mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
jsHint passing versions of BBB, scanBLE and wemo nodes.
Also fixe and in vs out issue on wemo... no way it could have been working previously..
This commit is contained in:
parent
c14364d752
commit
999874f2b5
@ -14,12 +14,12 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
// Require main module
|
||||
var RED = require(process.env.NODE_RED_HOME + "/red/red");
|
||||
var bonescript = require("bonescript");
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var bonescript = require("bonescript");
|
||||
|
||||
// Node constructor for bbb-analogue-in
|
||||
function AnalogueInputNode(n) {
|
||||
// Node constructor for bbb-analogue-in
|
||||
function AnalogueInputNode(n) {
|
||||
// Create a RED node
|
||||
RED.nodes.createNode(this, n);
|
||||
|
||||
@ -72,19 +72,21 @@ function AnalogueInputNode(n) {
|
||||
} else {
|
||||
node.error("Unconfigured input pin");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Node constructor for bbb-discrete-in
|
||||
function DiscreteInputNode(n) {
|
||||
// Node constructor for bbb-discrete-in
|
||||
function DiscreteInputNode(n) {
|
||||
RED.nodes.createNode(this, n);
|
||||
|
||||
// Store local copies of the node configuration (as defined in the .html)
|
||||
this.topic = n.topic; // the topic is not currently used
|
||||
this.pin = n.pin; // The Beaglebone Black pin identifying string
|
||||
if (n.activeLow) // Set the 'active' state 0 or 1 as appropriate
|
||||
if (n.activeLow) { // Set the 'active' state 0 or 1 as appropriate
|
||||
this.activeState = 0;
|
||||
else
|
||||
}
|
||||
else {
|
||||
this.activeState = 1;
|
||||
}
|
||||
this.updateInterval = n.updateInterval * 1000; // How often to send totalActiveTime messages
|
||||
this.debounce = n.debounce; // Enable switch contact debouncing algorithm
|
||||
if (n.outputOn === "rising") {
|
||||
@ -184,7 +186,7 @@ function DiscreteInputNode(n) {
|
||||
// payload, if possible. Otherwise clear the totalActiveTime (so we start counting
|
||||
// from zero again)
|
||||
var inputCallback = function (ipMsg) {
|
||||
if (String(ipMsg.topic).search(/load/i) < 0 || isFinite(ipMsg.payload) == false) {
|
||||
if (String(ipMsg.topic).search(/load/i) < 0 || isFinite(ipMsg.payload) === false) {
|
||||
node.totalActiveTime = 0;
|
||||
} else {
|
||||
node.totalActiveTime = Number(ipMsg.payload);
|
||||
@ -240,10 +242,10 @@ function DiscreteInputNode(n) {
|
||||
} else {
|
||||
node.error("Unconfigured input pin");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Node constructor for bbb-pulse-in
|
||||
function PulseInputNode(n) {
|
||||
// Node constructor for bbb-pulse-in
|
||||
function PulseInputNode(n) {
|
||||
RED.nodes.createNode(this, n);
|
||||
|
||||
// Store local copies of the node configuration (as defined in the .html)
|
||||
@ -277,7 +279,7 @@ function PulseInputNode(n) {
|
||||
// insensitive) and the payload is a valid number, set the count to that
|
||||
// number, otherwise set it to zero
|
||||
var inputCallback = function (msg) {
|
||||
if (String(msg.topic).search(/load/i) < 0 || isFinite(msg.payload) == false) {
|
||||
if (String(msg.topic).search(/load/i) < 0 || isFinite(msg.payload) === false) {
|
||||
node.pulseCount = 0;
|
||||
} else {
|
||||
node.pulseCount = Number(msg.payload);
|
||||
@ -332,10 +334,10 @@ function PulseInputNode(n) {
|
||||
} else {
|
||||
node.error("Unconfigured input pin");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Node constructor for bbb-discrete-out
|
||||
function DiscreteOutputNode(n) {
|
||||
// Node constructor for bbb-discrete-out
|
||||
function DiscreteOutputNode(n) {
|
||||
RED.nodes.createNode(this, n);
|
||||
|
||||
// Store local copies of the node configuration (as defined in the .html)
|
||||
@ -388,10 +390,10 @@ function DiscreteOutputNode(n) {
|
||||
} else {
|
||||
node.error("Unconfigured output pin");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Node constructor for bbb-pulse-out
|
||||
function PulseOutputNode(n) {
|
||||
// Node constructor for bbb-pulse-out
|
||||
function PulseOutputNode(n) {
|
||||
RED.nodes.createNode(this, n);
|
||||
|
||||
// Store local copies of the node configuration (as defined in the .html)
|
||||
@ -462,17 +464,17 @@ function PulseOutputNode(n) {
|
||||
} else {
|
||||
node.error("Unconfigured output pin");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Register the nodes by name. This must be called before overriding any of the Node functions.
|
||||
RED.nodes.registerType("bbb-analogue-in", AnalogueInputNode);
|
||||
RED.nodes.registerType("bbb-discrete-in", DiscreteInputNode);
|
||||
RED.nodes.registerType("bbb-pulse-in", PulseInputNode);
|
||||
RED.nodes.registerType("bbb-discrete-out", DiscreteOutputNode);
|
||||
RED.nodes.registerType("bbb-pulse-out", PulseOutputNode);
|
||||
// Register the nodes by name. This must be called before overriding any of the Node functions.
|
||||
RED.nodes.registerType("bbb-analogue-in", AnalogueInputNode);
|
||||
RED.nodes.registerType("bbb-discrete-in", DiscreteInputNode);
|
||||
RED.nodes.registerType("bbb-pulse-in", PulseInputNode);
|
||||
RED.nodes.registerType("bbb-discrete-out", DiscreteOutputNode);
|
||||
RED.nodes.registerType("bbb-pulse-out", PulseOutputNode);
|
||||
|
||||
// On close, detach the interrupt (if we attached one) and clear any active timers
|
||||
DiscreteInputNode.prototype.close = function () {
|
||||
// On close, detach the interrupt (if we attached one) and clear any active timers
|
||||
DiscreteInputNode.prototype.close = function () {
|
||||
if (this.interruptAttached) {
|
||||
bonescript.detachInterrupt(this.pin);
|
||||
}
|
||||
@ -482,21 +484,22 @@ DiscreteInputNode.prototype.close = function () {
|
||||
if (this.debounceTimer !== null) {
|
||||
clearTimeout(this.debounceTimer);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// On close, detach the interrupt (if we attached one) and clear the interval (if we set one)
|
||||
PulseInputNode.prototype.close = function () {
|
||||
// On close, detach the interrupt (if we attached one) and clear the interval (if we set one)
|
||||
PulseInputNode.prototype.close = function () {
|
||||
if (this.interruptAttached) {
|
||||
bonescript.detachInterrupt(this.pin);
|
||||
}
|
||||
if (this.intervalId !== null) {
|
||||
clearInterval(this.intervalId);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// On close, clear an active pulse timer
|
||||
PulseOutputNode.prototype.close = function () {
|
||||
// On close, clear an active pulse timer
|
||||
PulseOutputNode.prototype.close = function () {
|
||||
if (this.pulseTimer !== null) {
|
||||
clearTimeout(this.pulseTimer);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -40,8 +40,9 @@ function BleScan(n) {
|
||||
this.on("input", function(msg){
|
||||
noble.startScanning();
|
||||
});
|
||||
|
||||
noble.on('scanStart', function(msg) {
|
||||
var msg = {};
|
||||
msg = {};
|
||||
msg.topic = node.topic;
|
||||
msg.payload = "Scanning initiated..." //debugging
|
||||
//console.log('scanning initiated...');
|
||||
@ -49,7 +50,6 @@ function BleScan(n) {
|
||||
});
|
||||
|
||||
noble.on('discover', function(peripheral) {
|
||||
|
||||
var msg = {};
|
||||
msg.topic = node.topic;
|
||||
msg.payload = "not found";
|
||||
@ -57,9 +57,10 @@ function BleScan(n) {
|
||||
//check for the device name and the UUID (first one from the UUID list)
|
||||
if(peripheral.advertisement.localName==node.ble_name && peripheral.advertisement.serviceUuids[0]==node.ble_uuid) {
|
||||
msg.payload=peripheral.advertisement.localName;
|
||||
noble.stopScanning(); }
|
||||
noble.stopScanning();
|
||||
}
|
||||
node.send(msg);
|
||||
});
|
||||
});
|
||||
|
||||
this.on("close", function() {
|
||||
try { noble.stopScanning(); }
|
||||
|
@ -16,12 +16,12 @@
|
||||
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var WeMo = new require('wemo');
|
||||
var Wemo = require('wemo');
|
||||
|
||||
function WeMoOut(n) {
|
||||
function WemoOut(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.ipaddr = n.ipaddr;
|
||||
this.wemoSwitch = new WeMo(n.ipaddr);
|
||||
this.wemoSwitch = new Wemo(n.ipaddr);
|
||||
var node = this;
|
||||
|
||||
this.on("input", function(msg) {
|
||||
@ -35,9 +35,9 @@ module.exports = function(RED) {
|
||||
}
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("wemo out",WeMoOut);
|
||||
RED.nodes.registerType("wemo out",WemoOut);
|
||||
|
||||
function WeMoIn(n) {
|
||||
function WemoIn(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.ipaddr = n.ipaddr;
|
||||
this.wemoSwitch = new WeMo(n.ipaddr);
|
||||
@ -58,5 +58,5 @@ module.exports = function(RED) {
|
||||
clearInterval(tick);
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("wemo in",WeMoOut);
|
||||
RED.nodes.registerType("wemo in",WemoIn);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user