mirror of
				https://github.com/node-red/node-red-nodes.git
				synced 2025-03-01 10:37:43 +00:00 
			
		
		
		
	Fix flow examples of Sense HAT simulator nodes (#991)
* Add indents to flow examples of Sense HAT simulator * Fix flow examples of Sense HAT simulator nodes
This commit is contained in:
		| @@ -1 +1,56 @@ | ||||
| [{"id":"8b346a30.651a88","type":"rpi-sensehat out","z":"7756eff1.08d0a","name":"","x":530,"y":220,"wires":[]},{"id":"c2e7a15d.237bd","type":"function","z":"7756eff1.08d0a","name":"Simple graphical clock","func":"\n// array to hold \"random\" pixels\nvar ranNums = [];\n\n// create a non-overlapping array of random numbers 0-8\nfunction rerand() {\n    var nums = [0,1,2,3,4,5,6,7,8];\n    var i = nums.length;\n    var j;\n    ranNums = [];\n    while (i--) {\n        j = Math.floor(Math.random() * (i+1));\n        ranNums.push(nums[j]);\n        nums.splice(j,1);\n    }\n}\n\n// Get the hours and minutes and split into tens and units\nvar d = new Date();\nvar s = d.getSeconds();\nvar su = s%4;\nif (su === 0) {\n    var h = d.getHours();\n    var m = d.getMinutes();\n    var hu = h%10;\n    h = parseInt(h/10);\n    var mu = m%10;\n    m = parseInt(m/10);\n    \n    // Do the tens of hours (red)\n    rerand();\n    node.send({payload:\"1-3,1-3,0,0,0\"});\n    for (var i=0; i<h; i++) {\n        node.send({payload:(1+ranNums[i]%3)+\",\"+(1+parseInt(ranNums[i]/3))+\",255,0,0\"});\n    }\n    \n    // Do the units of hours (green)\n    rerand();\n    node.send({payload:\"4-6,1-3,0,0,0\"});\n    for (var i=0; i<hu; i++) {\n        node.send({payload:(4+ranNums[i]%3)+\",\"+(1+parseInt(ranNums[i]/3))+\",0,255,0\"});\n    }\n    \n    // Do the tens of minutes (yellow)\n    rerand();\n    node.send({payload:\"1-3,4-6,0,0,0\"});\n    for (var i=0; i<m; i++) {\n        node.send({payload:(1+ranNums[i]%3)+\",\"+(4+parseInt(ranNums[i]/3))+\",255,255,0\"});\n    }\n    \n    // Do the unit of minutes (blue)\n    rerand();\n    node.send({payload:\"4-6,4-6,0,0,0\"});\n    for (var i=0; i<mu; i++) {\n        node.send({payload:(4+ranNums[i]%3)+\",\"+(4+parseInt(ranNums[i]/3))+\",0,0,255\"});\n    }\n    \n}\nnode.send({payload:\"0,0,\"+(su===0?\"purple\":\"off\")+\",7,0,\"+(su===1?\"purple\":\"off\")+\",7,7,\"+(su===2?\"purple\":\"off\")+\",0,7,\"+(su===3?\"purple\":\"off\")})\n\n\n// nothing left to do\nreturn null;","outputs":1,"noerr":0,"x":320,"y":220,"wires":[["8b346a30.651a88"]]},{"id":"fc3808df.6cbcf8","type":"comment","z":"7756eff1.08d0a","name":"Simple graphical clock for Sense Hat","info":"Generates a graphical clock, showing hours and minutes. \n\nHours are shown by the red and green pixels, minutes\nare the yellow and blue pixels.\n\nUses the local time of the Pi - you may need to set your local\ntimezone using\n\n    sudo dpkg-reconfigure tzdata\n","x":210,"y":180,"wires":[]},{"id":"f33ea1a7.27216","type":"inject","z":"7756eff1.08d0a","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":true,"x":120,"y":220,"wires":[["c2e7a15d.237bd"]]}] | ||||
| [ | ||||
|     { | ||||
|         "id": "8b346a30.651a88", | ||||
|         "type": "rpi-sensehatsim out", | ||||
|         "z": "7756eff1.08d0a", | ||||
|         "name": "", | ||||
|         "x": 530, | ||||
|         "y": 220, | ||||
|         "wires": [] | ||||
|     }, | ||||
|     { | ||||
|         "id": "c2e7a15d.237bd", | ||||
|         "type": "function", | ||||
|         "z": "7756eff1.08d0a", | ||||
|         "name": "Simple graphical clock", | ||||
|         "func": "\n// array to hold \"random\" pixels\nvar ranNums = [];\n\n// create a non-overlapping array of random numbers 0-8\nfunction rerand() {\n    var nums = [0,1,2,3,4,5,6,7,8];\n    var i = nums.length;\n    var j;\n    ranNums = [];\n    while (i--) {\n        j = Math.floor(Math.random() * (i+1));\n        ranNums.push(nums[j]);\n        nums.splice(j,1);\n    }\n}\n\n// Get the hours and minutes and split into tens and units\nvar d = new Date();\nvar s = d.getSeconds();\nvar su = s%4;\nif (su === 0) {\n    var h = d.getHours();\n    var m = d.getMinutes();\n    var hu = h%10;\n    h = parseInt(h/10);\n    var mu = m%10;\n    m = parseInt(m/10);\n    \n    // Do the tens of hours (red)\n    rerand();\n    node.send({payload:\"1-3,1-3,0,0,0\"});\n    for (var i=0; i<h; i++) {\n        node.send({payload:(1+ranNums[i]%3)+\",\"+(1+parseInt(ranNums[i]/3))+\",255,0,0\"});\n    }\n    \n    // Do the units of hours (green)\n    rerand();\n    node.send({payload:\"4-6,1-3,0,0,0\"});\n    for (var i=0; i<hu; i++) {\n        node.send({payload:(4+ranNums[i]%3)+\",\"+(1+parseInt(ranNums[i]/3))+\",0,255,0\"});\n    }\n    \n    // Do the tens of minutes (yellow)\n    rerand();\n    node.send({payload:\"1-3,4-6,0,0,0\"});\n    for (var i=0; i<m; i++) {\n        node.send({payload:(1+ranNums[i]%3)+\",\"+(4+parseInt(ranNums[i]/3))+\",255,255,0\"});\n    }\n    \n    // Do the unit of minutes (blue)\n    rerand();\n    node.send({payload:\"4-6,4-6,0,0,0\"});\n    for (var i=0; i<mu; i++) {\n        node.send({payload:(4+ranNums[i]%3)+\",\"+(4+parseInt(ranNums[i]/3))+\",0,0,255\"});\n    }\n    \n}\nnode.send({payload:\"0,0,\"+(su===0?\"purple\":\"off\")+\",7,0,\"+(su===1?\"purple\":\"off\")+\",7,7,\"+(su===2?\"purple\":\"off\")+\",0,7,\"+(su===3?\"purple\":\"off\")})\n\n\n// nothing left to do\nreturn null;", | ||||
|         "outputs": 1, | ||||
|         "noerr": 0, | ||||
|         "x": 320, | ||||
|         "y": 220, | ||||
|         "wires": [ | ||||
|             [ | ||||
|                 "8b346a30.651a88" | ||||
|             ] | ||||
|         ] | ||||
|     }, | ||||
|     { | ||||
|         "id": "fc3808df.6cbcf8", | ||||
|         "type": "comment", | ||||
|         "z": "7756eff1.08d0a", | ||||
|         "name": "Simple graphical clock for Sense Hat", | ||||
|         "info": "Generates a graphical clock, showing hours and minutes. \n\nHours are shown by the red and green pixels, minutes\nare the yellow and blue pixels.\n\nUses the local time of the Pi - you may need to set your local\ntimezone using\n\n    sudo dpkg-reconfigure tzdata\n", | ||||
|         "x": 210, | ||||
|         "y": 180, | ||||
|         "wires": [] | ||||
|     }, | ||||
|     { | ||||
|         "id": "f33ea1a7.27216", | ||||
|         "type": "inject", | ||||
|         "z": "7756eff1.08d0a", | ||||
|         "name": "", | ||||
|         "topic": "", | ||||
|         "payload": "", | ||||
|         "payloadType": "date", | ||||
|         "repeat": "1", | ||||
|         "crontab": "", | ||||
|         "once": true, | ||||
|         "x": 120, | ||||
|         "y": 220, | ||||
|         "wires": [ | ||||
|             [ | ||||
|                 "c2e7a15d.237bd" | ||||
|             ] | ||||
|         ] | ||||
|     } | ||||
| ] | ||||
|   | ||||
| @@ -1 +1,53 @@ | ||||
| [{"id":"104a54e7.6656cb","type":"rpi-sensehat out","z":"7756eff1.08d0a","name":"","x":470,"y":300,"wires":[]},{"id":"a3786fbb.b3ff9","type":"rpi-sensehat in","z":"7756eff1.08d0a","name":"","motion":true,"env":false,"stick":false,"x":120,"y":300,"wires":[["931798d.9640d68"]]},{"id":"931798d.9640d68","type":"function","z":"7756eff1.08d0a","name":"Compass","func":"// Based on the Compass example provided by\n// the Sense HAT python library\n// https://github.com/RPi-Distro/python-sense-hat/tree/master/examples\n\nvar led_loop = [4, 5, 6, 7, 15, 23, 31, 39, 47, 55, 63, 62, 61, 60, 59, 58, 57, 56, 48, 40, 32, 24, 16, 8, 0, 1, 2, 3];\nvar led_degree_ratio = led_loop.length / 360.0;\nvar dir = (360 - msg.payload.compass)%360;\n\nfunction getXY(dir) {\n    var led_index = Math.floor(led_degree_ratio * (dir%360));\n    var offset = led_loop[led_index];\n    return [offset % 8,Math.floor(offset / 8)];\n}\n\nvar previous = context.get('previous');\nmsg.payload = '';\n\nvar position = getXY(dir);\nif (!previous || position[0] != previous[0][0] || position[1] != previous[0][1]) {\n    if (previous) {\n        msg.payload = previous[0][0]+\",\"+previous[0][1]+\",off,\"+\n                      previous[1][0]+\",\"+previous[1][1]+\",off,\";\n    } else {\n        msg.payload = \"*,*,off,\";\n    }\n    previous = [\n        position,\n        getXY(dir+180)\n    ];\n    msg.payload += previous[0][0]+\",\"+previous[0][1]+\",red,\"+\n                  previous[1][0]+\",\"+previous[1][1]+\",white\"\n    \n    context.set('previous',previous);\n    return msg;\n}\nreturn null;\n\n","outputs":1,"noerr":0,"x":280,"y":300,"wires":[["104a54e7.6656cb"]]},{"id":"434680a8.c2e54","type":"comment","z":"7756eff1.08d0a","name":"Simple compass for Sense Hat","info":"Generates a compass, showing north (red) and south (white).\n\nBased on the python example provided with the Sense Hat: https://github.com/RPi-Distro/python-sense-hat/tree/master/examples\n\nThe accuracy of the compass will depend on callibrating the Sense Hat\ninternal compass. Search the Sense Hat forums for a guide on how to\ndo this.\n","x":190,"y":260,"wires":[]}] | ||||
| [ | ||||
|     { | ||||
|         "id": "104a54e7.6656cb", | ||||
|         "type": "rpi-sensehatsim out", | ||||
|         "z": "7756eff1.08d0a", | ||||
|         "name": "", | ||||
|         "x": 470, | ||||
|         "y": 300, | ||||
|         "wires": [] | ||||
|     }, | ||||
|     { | ||||
|         "id": "a3786fbb.b3ff9", | ||||
|         "type": "rpi-sensehatsim in", | ||||
|         "z": "7756eff1.08d0a", | ||||
|         "name": "", | ||||
|         "motion": true, | ||||
|         "env": false, | ||||
|         "stick": false, | ||||
|         "x": 120, | ||||
|         "y": 300, | ||||
|         "wires": [ | ||||
|             [ | ||||
|                 "931798d.9640d68" | ||||
|             ] | ||||
|         ] | ||||
|     }, | ||||
|     { | ||||
|         "id": "931798d.9640d68", | ||||
|         "type": "function", | ||||
|         "z": "7756eff1.08d0a", | ||||
|         "name": "Compass", | ||||
|         "func": "// Based on the Compass example provided by\n// the Sense HAT python library\n// https://github.com/RPi-Distro/python-sense-hat/tree/master/examples\n\nvar led_loop = [4, 5, 6, 7, 15, 23, 31, 39, 47, 55, 63, 62, 61, 60, 59, 58, 57, 56, 48, 40, 32, 24, 16, 8, 0, 1, 2, 3];\nvar led_degree_ratio = led_loop.length / 360.0;\nvar dir = (360 - msg.payload.compass)%360;\n\nfunction getXY(dir) {\n    var led_index = Math.floor(led_degree_ratio * (dir%360));\n    var offset = led_loop[led_index];\n    return [offset % 8,Math.floor(offset / 8)];\n}\n\nvar previous = context.get('previous');\nmsg.payload = '';\n\nvar position = getXY(dir);\nif (!previous || position[0] != previous[0][0] || position[1] != previous[0][1]) {\n    if (previous) {\n        msg.payload = previous[0][0]+\",\"+previous[0][1]+\",off,\"+\n                      previous[1][0]+\",\"+previous[1][1]+\",off,\";\n    } else {\n        msg.payload = \"*,*,off,\";\n    }\n    previous = [\n        position,\n        getXY(dir+180)\n    ];\n    msg.payload += previous[0][0]+\",\"+previous[0][1]+\",red,\"+\n                  previous[1][0]+\",\"+previous[1][1]+\",white\"\n    \n    context.set('previous',previous);\n    return msg;\n}\nreturn null;\n\n", | ||||
|         "outputs": 1, | ||||
|         "noerr": 0, | ||||
|         "x": 280, | ||||
|         "y": 300, | ||||
|         "wires": [ | ||||
|             [ | ||||
|                 "104a54e7.6656cb" | ||||
|             ] | ||||
|         ] | ||||
|     }, | ||||
|     { | ||||
|         "id": "434680a8.c2e54", | ||||
|         "type": "comment", | ||||
|         "z": "7756eff1.08d0a", | ||||
|         "name": "Simple compass for Sense Hat", | ||||
|         "info": "Generates a compass, showing north (red) and south (white).\n\nBased on the python example provided with the Sense Hat: https://github.com/RPi-Distro/python-sense-hat/tree/master/examples\n\nThe accuracy of the compass will depend on callibrating the Sense Hat\ninternal compass. Search the Sense Hat forums for a guide on how to\ndo this.\n", | ||||
|         "x": 190, | ||||
|         "y": 260, | ||||
|         "wires": [] | ||||
|     } | ||||
| ] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user