Cleaned up the code a little and added some more comments to the info section

This commit is contained in:
Ben Hardill 2014-02-25 11:18:45 +00:00
parent 2723210922
commit 7efd866ff0
2 changed files with 47 additions and 44 deletions

View File

@ -78,6 +78,10 @@
<!-- The first <p> is used as the pop-up tool tip when hovering over a -->
<!-- node in the palette. -->
<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>
<!-- Finally, the node type is registered along with all of its properties -->
@ -109,6 +113,7 @@
},
oneditsave: function() {
var mac = $("#node-input-uuid").val();
mac = mac.toLowerCase();
//nasty hack as I can't get global replace to work
mac = mac.replace(/:/gi,'');
mac = mac.replace(/:/gi,'');

View File

@ -17,8 +17,6 @@
// Require main module
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var SensorTag = require('sensortag');
var stag;
var node;
// The main node definition - most things happen in here
function sensorTagNode(n) {
@ -37,14 +35,14 @@ function sensorTagNode(n) {
if (this.uuid === "") {
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");
SensorTag.discover(function(sensorTag){
stag = sensorTag;
node.stag = sensorTag;
sensorTag.connect(function(){
//console.log("connected");
sensorTag.discoverServicesAndCharacteristics(function(){
@ -94,51 +92,51 @@ function sensorTagNode(n) {
msg.payload = {'left': left, 'right': right};
node.send(msg);
});
enable();
enable(node);
});
});
},node.uuid);
} else {
//console.log("reconfig");
enable();
enable(node);
}
}
function enable() {
if (node.temperature) {
stag.notifyIrTemperature(function(){});
} else {
stag.unnotifyIrTemperature(function(){});
}
if (node.pressure) {
stag.notifyBarometricPressure(function(){});
} else {
stag.unnotifyBarometricPressure(function(){});
}
if (node.humidity) {
stag.notifyHumidity(function() {});
} else {
stag.unnotifyHumidity(function() {});
}
if (node.accelometer){
stag.notifyAccelerometer(function() {});
} else {
stag.unnotifyAccelerometer(function() {});
}
if (node.magnetometer) {
stag.notifyMagnetometer(function() {});
} else {
stag.unnotifyMagnetometer(function() {});
}
if (node.gyroscope) {
stag.notifyGyroscope(function() {});
} else {
stag.unnotifyGyroscope(function() {});
}
if (node.keys) {
stag.notifySimpleKey(function() {});
} else {
stag.unnotifySimpleKey(function() {});
}
function enable(node) {
if (node.temperature) {
node.stag.notifyIrTemperature(function(){});
} else {
node.stag.unnotifyIrTemperature(function(){});
}
if (node.pressure) {
node.stag.notifyBarometricPressure(function(){});
} else {
node.stag.unnotifyBarometricPressure(function(){});
}
if (node.humidity) {
node.stag.notifyHumidity(function() {});
} else {
node.stag.unnotifyHumidity(function() {});
}
if (node.accelometer){
node.stag.notifyAccelerometer(function() {});
} else {
node.stag.unnotifyAccelerometer(function() {});
}
if (node.magnetometer) {
node.stag.notifyMagnetometer(function() {});
} else {
node.stag.unnotifyMagnetometer(function() {});
}
if (node.gyroscope) {
node.stag.notifyGyroscope(function() {});
} else {
node.stag.unnotifyGyroscope(function() {});
}
if (node.keys) {
node.stag.notifySimpleKey(function() {});
} else {
node.stag.unnotifySimpleKey(function() {});
}
}
RED.nodes.registerType("sensorTag",sensorTagNode);