Skip to content

Instantly share code, notes, and snippets.

@tatyanavolkova
Created December 26, 2022 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatyanavolkova/3b75d501fa0d67a62e2d4e1b11633abf to your computer and use it in GitHub Desktop.
Save tatyanavolkova/3b75d501fa0d67a62e2d4e1b11633abf to your computer and use it in GitHub Desktop.
Simple project - time management cube from Android smartphone with Termux onboard, Detects the side of the cube by using accelerometer data and adds a Toggl time entry.
[
{
"id": "2bf0bfd7051402f4",
"type": "tab",
"label": "Поток 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "368118c48e7bd251",
"type": "inject",
"z": "2bf0bfd7051402f4",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 100,
"y": 200,
"wires": [
[
"e98c847a6a98c097",
"9abf1204d30e209d"
]
]
},
{
"id": "e98c847a6a98c097",
"type": "exec",
"z": "2bf0bfd7051402f4",
"command": "termux-sensor -s \"LSM6DSO Accelerometer\" -n 1",
"addpay": "",
"append": "",
"useSpawn": "false",
"timer": "",
"winHide": false,
"oldrc": false,
"name": "Получить данные с акселерометра",
"x": 450,
"y": 120,
"wires": [
[
"beb39efc9d924169"
],
[],
[]
]
},
{
"id": "138b241d7b8e0619",
"type": "function",
"z": "2bf0bfd7051402f4",
"name": "Получить сторону кубика",
"func": "var accelerometer = msg.payload[\"LSM6DSO Accelerometer\"];\nvar x = accelerometer.values[0];\nvar y = accelerometer.values[1];\nvar z = accelerometer.values[2];\n\nvar side=0;\n\nif (Math.abs(x) > Math.abs(y) && Math.abs(x) > Math.abs(z)) {\n if (x > 0) {side = 0}\n else side = 1;\n}\n\nif (Math.abs(y) > Math.abs(x) && Math.abs(y) > Math.abs(z)) {\n if (y > 0) { side = 2 }\n else side = 3;\n}\n\nif (Math.abs(z) > Math.abs(x) && Math.abs(z) > Math.abs(y)) {\n if (z > 0) { side = 4 }\n else side = 5;\n}\n\nmsg.payload = side;\n\nnode.status({ text: \"Сторона: \" + side })\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 420,
"y": 320,
"wires": [
[
"3521d2aa593579f2"
]
]
},
{
"id": "fa83a30a2016a4fc",
"type": "debug",
"z": "2bf0bfd7051402f4",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 840,
"y": 520,
"wires": []
},
{
"id": "beb39efc9d924169",
"type": "json",
"z": "2bf0bfd7051402f4",
"name": "Перевести строку в JSON",
"property": "payload",
"action": "",
"pretty": false,
"x": 380,
"y": 240,
"wires": [
[
"138b241d7b8e0619"
]
]
},
{
"id": "3521d2aa593579f2",
"type": "switch",
"z": "2bf0bfd7051402f4",
"name": "Сторона поменялась?",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "neq",
"v": "prev_side",
"vt": "global"
},
{
"t": "eq",
"v": "prev_side",
"vt": "global"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 410,
"y": 480,
"wires": [
[
"12a63a6c46a0c7bb"
],
[
"e98c847a6a98c097"
]
]
},
{
"id": "9abf1204d30e209d",
"type": "function",
"z": "2bf0bfd7051402f4",
"name": "Задать глобальную переменную",
"func": "global.set(\"prev_side\", -1);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 380,
"y": 40,
"wires": [
[]
]
},
{
"id": "12a63a6c46a0c7bb",
"type": "function",
"z": "2bf0bfd7051402f4",
"name": "Обновить глобальную переменную",
"func": "global.set(\"prev_side\", msg.payload);\nglobal.set(\"side\", msg.payload);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 790,
"y": 440,
"wires": [
[
"fa83a30a2016a4fc",
"b29b8ccfa1272004"
]
]
},
{
"id": "3685c604c72fe098",
"type": "toggl-start-timer",
"z": "2bf0bfd7051402f4",
"name": "Чтение",
"toggl": "2d440f1e8be55305",
"workspace": "1439615",
"project": "15764084",
"description": "",
"tags": [],
"overwriteTags": false,
"x": 1460,
"y": 120,
"wires": [
[
"c23f0ebdaaacd2fa"
]
]
},
{
"id": "327891a406af8ce8",
"type": "switch",
"z": "2bf0bfd7051402f4",
"name": "Какое занятие?",
"property": "side",
"propertyType": "global",
"rules": [
{
"t": "eq",
"v": "0",
"vt": "num"
},
{
"t": "eq",
"v": "1",
"vt": "num"
},
{
"t": "eq",
"v": "2",
"vt": "num"
},
{
"t": "eq",
"v": "3",
"vt": "num"
},
{
"t": "eq",
"v": "4",
"vt": "num"
},
{
"t": "eq",
"v": "5",
"vt": "num"
}
],
"checkall": "true",
"repair": false,
"outputs": 6,
"x": 1220,
"y": 260,
"wires": [
[
"3685c604c72fe098"
],
[
"40b8192722a36fdf"
],
[
"f97e479909c73bc9"
],
[
"dadef422411e840f"
],
[
"8f4533201225c570"
],
[
"c23f0ebdaaacd2fa"
]
]
},
{
"id": "40b8192722a36fdf",
"type": "toggl-start-timer",
"z": "2bf0bfd7051402f4",
"name": "Спорт",
"toggl": "2d440f1e8be55305",
"workspace": "1439615",
"project": "16493487",
"description": "",
"tags": [],
"overwriteTags": false,
"x": 1450,
"y": 200,
"wires": [
[
"c23f0ebdaaacd2fa"
]
]
},
{
"id": "21090c35a73c4ba4",
"type": "toggl-stop-timer",
"z": "2bf0bfd7051402f4",
"name": "Остановить таймер",
"toggl": "2d440f1e8be55305",
"workspace": "1439615",
"x": 1180,
"y": 60,
"wires": [
[
"327891a406af8ce8"
]
]
},
{
"id": "b29b8ccfa1272004",
"type": "toggl-get-timer",
"z": "2bf0bfd7051402f4",
"name": "Какой таймер запущен?",
"toggl": "2d440f1e8be55305",
"noTimerSendFalse": true,
"x": 810,
"y": 220,
"wires": [
[
"dca436c78d95ae1e"
]
]
},
{
"id": "dca436c78d95ae1e",
"type": "switch",
"z": "2bf0bfd7051402f4",
"name": "Имя таймера",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "neq",
"v": "false",
"vt": "jsonata"
},
{
"t": "eq",
"v": "false",
"vt": "jsonata"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 1020,
"y": 120,
"wires": [
[
"21090c35a73c4ba4"
],
[
"327891a406af8ce8"
]
]
},
{
"id": "f97e479909c73bc9",
"type": "toggl-start-timer",
"z": "2bf0bfd7051402f4",
"name": "Быт",
"toggl": "2d440f1e8be55305",
"workspace": "1439615",
"project": "15458140",
"description": "",
"tags": [],
"overwriteTags": false,
"x": 1450,
"y": 260,
"wires": [
[
"c23f0ebdaaacd2fa"
]
]
},
{
"id": "dadef422411e840f",
"type": "toggl-start-timer",
"z": "2bf0bfd7051402f4",
"name": "Самообразование",
"toggl": "2d440f1e8be55305",
"workspace": "1439615",
"project": "15729759",
"description": "",
"tags": [],
"overwriteTags": false,
"x": 1490,
"y": 300,
"wires": [
[
"c23f0ebdaaacd2fa"
]
]
},
{
"id": "8f4533201225c570",
"type": "toggl-start-timer",
"z": "2bf0bfd7051402f4",
"name": "Отдых",
"toggl": "2d440f1e8be55305",
"workspace": "1439615",
"project": "15433859",
"description": "",
"tags": [],
"overwriteTags": false,
"x": 1430,
"y": 340,
"wires": [
[
"c23f0ebdaaacd2fa"
]
]
},
{
"id": "389e01fb2ff746e3",
"type": "termux-vibrate",
"z": "2bf0bfd7051402f4",
"name": "",
"topic": "",
"duration": 1000,
"force": false,
"x": 1740,
"y": 180,
"wires": []
},
{
"id": "c23f0ebdaaacd2fa",
"type": "function",
"z": "2bf0bfd7051402f4",
"name": "function 1",
"func": "\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1740,
"y": 260,
"wires": [
[
"389e01fb2ff746e3",
"e98c847a6a98c097",
"ba3696549e793f95"
]
]
},
{
"id": "ba3696549e793f95",
"type": "debug",
"z": "2bf0bfd7051402f4",
"name": "debug 3",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1920,
"y": 340,
"wires": []
},
{
"id": "2d440f1e8be55305",
"type": "toggl-config",
"name": "Default"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment