mirror of
				https://github.com/node-red/node-red-nodes.git
				synced 2025-03-01 10:37:43 +00:00 
			
		
		
		
	Cleaned up the code a little and added some more comments to the info section
This commit is contained in:
		| @@ -78,6 +78,10 @@ | |||||||
|    <!-- The first <p> is used as the pop-up tool tip when hovering over a    --> |    <!-- The first <p> is used as the pop-up tool tip when hovering over a    --> | ||||||
|    <!-- node in the palette.                                                 --> |    <!-- node in the palette.                                                 --> | ||||||
|    <p>Input node for the Ti SensorTag</p> |    <p>Input node for the Ti SensorTag</p> | ||||||
|  |    <p>The UUID field is the mac address of the sensor tag, this is optional | ||||||
|  |       can be used to bind to a specific SensorTag if you have more than one | ||||||
|  |       active in range at the same time. (note you can only have one SensorTag per  | ||||||
|  |       node-red instance at the moment)</p> | ||||||
| </script> | </script> | ||||||
|  |  | ||||||
| <!-- Finally, the node type is registered along with all of its properties   --> | <!-- Finally, the node type is registered along with all of its properties   --> | ||||||
| @@ -109,6 +113,7 @@ | |||||||
|         }, |         }, | ||||||
|         oneditsave: function() { |         oneditsave: function() { | ||||||
|            var mac = $("#node-input-uuid").val(); |            var mac = $("#node-input-uuid").val(); | ||||||
|  |            mac = mac.toLowerCase(); | ||||||
|            //nasty hack as I can't get global replace to work |            //nasty hack as I can't get global replace to work | ||||||
|            mac = mac.replace(/:/gi,''); |            mac = mac.replace(/:/gi,''); | ||||||
|            mac = mac.replace(/:/gi,''); |            mac = mac.replace(/:/gi,''); | ||||||
|   | |||||||
| @@ -17,8 +17,6 @@ | |||||||
| // Require main module | // Require main module | ||||||
| var RED = require(process.env.NODE_RED_HOME+"/red/red"); | var RED = require(process.env.NODE_RED_HOME+"/red/red"); | ||||||
| var SensorTag = require('sensortag'); | var SensorTag = require('sensortag'); | ||||||
| var stag; |  | ||||||
| var node; |  | ||||||
|  |  | ||||||
| // The main node definition - most things happen in here | // The main node definition - most things happen in here | ||||||
| function sensorTagNode(n) { | function sensorTagNode(n) { | ||||||
| @@ -37,14 +35,14 @@ function sensorTagNode(n) { | |||||||
|     if (this.uuid === "") { |     if (this.uuid === "") { | ||||||
|         this.uuid = undefined; |         this.uuid = undefined; | ||||||
|     } |     } | ||||||
|     console.log(this.uuid); |     //console.log(this.uuid); | ||||||
|  |  | ||||||
|     node=this; |     var node=this; | ||||||
|  |  | ||||||
|     if ( typeof stag == "undefined") { |     if ( typeof node.stag == "undefined") { | ||||||
|     //console.log("starting"); |     //console.log("starting"); | ||||||
|     SensorTag.discover(function(sensorTag){ |     SensorTag.discover(function(sensorTag){ | ||||||
|         stag = sensorTag; |         node.stag = sensorTag; | ||||||
|         sensorTag.connect(function(){ |         sensorTag.connect(function(){ | ||||||
|             //console.log("connected"); |             //console.log("connected"); | ||||||
|             sensorTag.discoverServicesAndCharacteristics(function(){ |             sensorTag.discoverServicesAndCharacteristics(function(){ | ||||||
| @@ -94,51 +92,51 @@ function sensorTagNode(n) { | |||||||
|                    msg.payload = {'left': left, 'right': right}; |                    msg.payload = {'left': left, 'right': right}; | ||||||
|                    node.send(msg); |                    node.send(msg); | ||||||
|                 }); |                 }); | ||||||
|                 enable(); |                 enable(node); | ||||||
|             }); |             }); | ||||||
|         }); |         }); | ||||||
|     },node.uuid); |     },node.uuid); | ||||||
|     } else { |     } else { | ||||||
|       //console.log("reconfig"); |       //console.log("reconfig"); | ||||||
|       enable(); |       enable(node); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| function enable() { | function enable(node) { | ||||||
|                 if (node.temperature) { |     if (node.temperature) { | ||||||
|                   stag.notifyIrTemperature(function(){}); |         node.stag.notifyIrTemperature(function(){}); | ||||||
|                 } else { |     } else { | ||||||
|                   stag.unnotifyIrTemperature(function(){}); |        node.stag.unnotifyIrTemperature(function(){}); | ||||||
|                 } |     } | ||||||
|                 if (node.pressure) { |     if (node.pressure) { | ||||||
|                   stag.notifyBarometricPressure(function(){}); |        node.stag.notifyBarometricPressure(function(){}); | ||||||
|                 } else { |     } else { | ||||||
|                   stag.unnotifyBarometricPressure(function(){}); |        node.stag.unnotifyBarometricPressure(function(){}); | ||||||
|                 } |     } | ||||||
|                 if (node.humidity) { |     if (node.humidity) { | ||||||
|                   stag.notifyHumidity(function() {}); |        node.stag.notifyHumidity(function() {}); | ||||||
|                 } else { |     } else { | ||||||
|                   stag.unnotifyHumidity(function() {}); |        node.stag.unnotifyHumidity(function() {}); | ||||||
|                 } |     } | ||||||
|                 if (node.accelometer){ |     if (node.accelometer){ | ||||||
|                   stag.notifyAccelerometer(function() {}); |        node.stag.notifyAccelerometer(function() {}); | ||||||
|                 } else { |     } else { | ||||||
|                   stag.unnotifyAccelerometer(function() {}); |        node.stag.unnotifyAccelerometer(function() {}); | ||||||
|                 } |     } | ||||||
|                 if (node.magnetometer) { |     if (node.magnetometer) { | ||||||
|                   stag.notifyMagnetometer(function() {}); |        node.stag.notifyMagnetometer(function() {}); | ||||||
|                 } else { |     } else { | ||||||
|                   stag.unnotifyMagnetometer(function() {}); |        node.stag.unnotifyMagnetometer(function() {}); | ||||||
|                 } |     } | ||||||
|                 if (node.gyroscope) { |     if (node.gyroscope) { | ||||||
|                   stag.notifyGyroscope(function() {}); |        node.stag.notifyGyroscope(function() {}); | ||||||
|                 } else { |     } else { | ||||||
|                   stag.unnotifyGyroscope(function() {}); |        node.stag.unnotifyGyroscope(function() {}); | ||||||
|                 } |     } | ||||||
|                 if (node.keys) { |     if (node.keys) { | ||||||
|                   stag.notifySimpleKey(function() {}); |        node.stag.notifySimpleKey(function() {}); | ||||||
|                 } else { |     } else { | ||||||
|                   stag.unnotifySimpleKey(function() {}); |        node.stag.unnotifySimpleKey(function() {}); | ||||||
|                 } |     } | ||||||
| } | } | ||||||
| RED.nodes.registerType("sensorTag",sensorTagNode); | RED.nodes.registerType("sensorTag",sensorTagNode); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user