-
Notifications
You must be signed in to change notification settings - Fork 0
/
getCompassReading.json
1 lines (1 loc) · 7.17 KB
/
getCompassReading.json
1
[{"id":"338b2bd0.cc74d4","type":"subflow","name":"Get Compass Reading HMC5883L","info":"","category":"","in":[{"x":40,"y":160,"wires":[{"id":"7926fcc6.86d904"}]}],"out":[{"x":2040,"y":220,"wires":[{"id":"e0cf7f15.1f308","port":0}]}],"env":[],"color":"#E9967A","inputLabels":["trigger request"],"outputLabels":["Rich packet (X,Y,Z, etc)"],"icon":"font-awesome/fa-cubes"},{"id":"fe33bb1f.01cc48","type":"comment","z":"338b2bd0.cc74d4","name":"Now: slight timing delay","info":"Was: hope the multi-part msgs arrive in order i guess","x":410,"y":120,"wires":[]},{"id":"e85bde50.17a42","type":"inject","z":"338b2bd0.cc74d4","name":"X - HMC5883L ","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":440,"y":80,"wires":[["ca904d86.356fb"]]},{"id":"ca904d86.356fb","type":"function","z":"338b2bd0.cc74d4","name":"read X command","func":"return [{command:\"03\"},{command:\"04\"}];","outputs":2,"noerr":0,"x":660,"y":160,"wires":[["a9cca95e.563358"],["a9cca95e.563358"]],"outputLabels":["get ID1","get ID2"]},{"id":"a9cca95e.563358","type":"i2c in","z":"338b2bd0.cc74d4","name":"HMC5883L command","address":"30","command":"","count":"1","x":910,"y":160,"wires":[["f5628349.0a9d8"]]},{"id":"f5628349.0a9d8","type":"join","z":"338b2bd0.cc74d4","name":"join msgs","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":1110,"y":160,"wires":[["6ad2487b.952db8"]]},{"id":"6ad2487b.952db8","type":"function","z":"338b2bd0.cc74d4","name":"calc X","func":"//16-bit 2's complement nonsense\nvar X = (msg.payload[0]<<8)+(msg.payload[1]);\nif ((X & 0x8000) > 0) {\n X = X - 0x10000;\n}\n\nmsg.label = \"Xmag\";\nmsg.payload = (X/1090).toFixed(3); //msg.X in gauss?\nnode.status({text:\"X: \"+msg.payload});\n\nreturn msg;","outputs":1,"noerr":2,"x":1250,"y":160,"wires":[["c33df8e7.3cc208","77379d3b.88c864"]]},{"id":"95be3482.6a41c8","type":"inject","z":"338b2bd0.cc74d4","name":"Z - HMC5883L ","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":440,"y":220,"wires":[["6907d235.96f82c"]]},{"id":"6907d235.96f82c","type":"function","z":"338b2bd0.cc74d4","name":"read Z command","func":"return [{command:\"05\"},{command:\"05\"}];","outputs":2,"noerr":0,"x":660,"y":220,"wires":[["3434255b.cbcbda"],["3434255b.cbcbda"]],"outputLabels":["get ID1","get ID2"]},{"id":"3434255b.cbcbda","type":"i2c in","z":"338b2bd0.cc74d4","name":"HMC5883L command","address":"30","command":"","count":"1","x":910,"y":220,"wires":[["a0921bd1.5f6de8"]]},{"id":"c33df8e7.3cc208","type":"debug","z":"338b2bd0.cc74d4","name":"msg","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1410,"y":160,"wires":[]},{"id":"a0921bd1.5f6de8","type":"join","z":"338b2bd0.cc74d4","name":"join msgs","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":1110,"y":220,"wires":[["20728521.df8d7a"]]},{"id":"20728521.df8d7a","type":"function","z":"338b2bd0.cc74d4","name":"calc Z","func":"//16-bit 2's complement nonsense\nvar X = (msg.payload[0]<<8)+(msg.payload[1]);\nif ((X & 0x8000) > 0) {\n X = X - 0x10000;\n}\n\nmsg.label = \"Zmag\";\nmsg.payload = (X/1090).toFixed(3); //msg.X in gauss?\nnode.status({text:\"Z: \"+msg.payload});\n\nreturn msg;","outputs":1,"noerr":2,"x":1250,"y":220,"wires":[["c33df8e7.3cc208","77379d3b.88c864"]]},{"id":"49293a3a.b6d6c4","type":"inject","z":"338b2bd0.cc74d4","name":"Y - HMC5883L ","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":440,"y":320,"wires":[["ae8bcce3.51743"]]},{"id":"ae8bcce3.51743","type":"function","z":"338b2bd0.cc74d4","name":"read Y command","func":"return [{command:\"07\"},{command:\"08\"}];","outputs":2,"noerr":0,"x":660,"y":280,"wires":[["15dad9f3.ea2526"],["15dad9f3.ea2526"]],"outputLabels":["get ID1","get ID2"]},{"id":"15dad9f3.ea2526","type":"i2c in","z":"338b2bd0.cc74d4","name":"HMC5883L command","address":"30","command":"","count":"1","x":910,"y":280,"wires":[["2fb1883e.d04e78"]]},{"id":"2fb1883e.d04e78","type":"join","z":"338b2bd0.cc74d4","name":"join msgs","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":1110,"y":280,"wires":[["ea113c60.15eec"]]},{"id":"ea113c60.15eec","type":"function","z":"338b2bd0.cc74d4","name":"calc Y","func":"//16-bit 2's complement nonsense\nvar X = (msg.payload[0]<<8)+(msg.payload[1]);\nif ((X & 0x8000) > 0) {\n X = X - 0x10000;\n}\n\nmsg.label = \"Ymag\";\nmsg.payload = (X/1090).toFixed(3); //msg.X in gauss?\nnode.status({text:\"Y: \"+msg.payload});\n\nreturn msg;","outputs":1,"noerr":2,"x":1250,"y":280,"wires":[["c33df8e7.3cc208","77379d3b.88c864"]]},{"id":"77379d3b.88c864","type":"join","z":"338b2bd0.cc74d4","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"label","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1430,"y":220,"wires":[["b26250d0.4d9db"]]},{"id":"b26250d0.4d9db","type":"change","z":"338b2bd0.cc74d4","name":"set/delete props","rules":[{"t":"delete","p":"command","pt":"msg"},{"t":"delete","p":"size","pt":"msg"},{"t":"set","p":"label","pt":"msg","to":"xyz mag","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"label","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1610,"y":220,"wires":[["e0cf7f15.1f308"]]},{"id":"93694253.6c96c","type":"comment","z":"338b2bd0.cc74d4","name":"XYZ magnetic field output","info":"","x":1750,"y":180,"wires":[]},{"id":"a4d6b2ac.5b295","type":"delay","z":"338b2bd0.cc74d4","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":450,"y":180,"wires":[["6907d235.96f82c"]]},{"id":"464e0f3.fb9b1f","type":"delay","z":"338b2bd0.cc74d4","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":450,"y":280,"wires":[["ae8bcce3.51743"]]},{"id":"e0cf7f15.1f308","type":"function","z":"338b2bd0.cc74d4","name":"calculate abs magnitude","func":"msg.payload.ABSMAG = (Math.sqrt(msg.payload.Xmag*msg.payload.Xmag+msg.payload.Ymag*msg.payload.Ymag+msg.payload.Zmag*msg.payload.Zmag).toFixed(3));\nmsg.payload.UNITS = \"Gauss\";\nmsg.payload.tinyunits = \"G\";\nreturn msg;","outputs":1,"noerr":2,"x":1840,"y":220,"wires":[[]]},{"id":"7926fcc6.86d904","type":"function","z":"338b2bd0.cc74d4","name":"input trigger","func":"\nreturn msg;","outputs":1,"noerr":2,"x":200,"y":160,"wires":[["ca904d86.356fb","a4d6b2ac.5b295","464e0f3.fb9b1f"]]}]