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.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
// Require main module
|
module.exports = function(RED) {
|
||||||
var RED = require(process.env.NODE_RED_HOME + "/red/red");
|
"use strict";
|
||||||
var bonescript = require("bonescript");
|
var bonescript = require("bonescript");
|
||||||
|
|
||||||
// Node constructor for bbb-analogue-in
|
// Node constructor for bbb-analogue-in
|
||||||
function AnalogueInputNode(n) {
|
function AnalogueInputNode(n) {
|
||||||
// Create a RED node
|
// Create a RED node
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
|
|
||||||
@ -72,19 +72,21 @@ function AnalogueInputNode(n) {
|
|||||||
} else {
|
} else {
|
||||||
node.error("Unconfigured input pin");
|
node.error("Unconfigured input pin");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node constructor for bbb-discrete-in
|
// Node constructor for bbb-discrete-in
|
||||||
function DiscreteInputNode(n) {
|
function DiscreteInputNode(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
|
|
||||||
// Store local copies of the node configuration (as defined in the .html)
|
// Store local copies of the node configuration (as defined in the .html)
|
||||||
this.topic = n.topic; // the topic is not currently used
|
this.topic = n.topic; // the topic is not currently used
|
||||||
this.pin = n.pin; // The Beaglebone Black pin identifying string
|
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;
|
this.activeState = 0;
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
this.activeState = 1;
|
this.activeState = 1;
|
||||||
|
}
|
||||||
this.updateInterval = n.updateInterval * 1000; // How often to send totalActiveTime messages
|
this.updateInterval = n.updateInterval * 1000; // How often to send totalActiveTime messages
|
||||||
this.debounce = n.debounce; // Enable switch contact debouncing algorithm
|
this.debounce = n.debounce; // Enable switch contact debouncing algorithm
|
||||||
if (n.outputOn === "rising") {
|
if (n.outputOn === "rising") {
|
||||||
@ -184,7 +186,7 @@ function DiscreteInputNode(n) {
|
|||||||
// payload, if possible. Otherwise clear the totalActiveTime (so we start counting
|
// payload, if possible. Otherwise clear the totalActiveTime (so we start counting
|
||||||
// from zero again)
|
// from zero again)
|
||||||
var inputCallback = function (ipMsg) {
|
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;
|
node.totalActiveTime = 0;
|
||||||
} else {
|
} else {
|
||||||
node.totalActiveTime = Number(ipMsg.payload);
|
node.totalActiveTime = Number(ipMsg.payload);
|
||||||
@ -240,10 +242,10 @@ function DiscreteInputNode(n) {
|
|||||||
} else {
|
} else {
|
||||||
node.error("Unconfigured input pin");
|
node.error("Unconfigured input pin");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node constructor for bbb-pulse-in
|
// Node constructor for bbb-pulse-in
|
||||||
function PulseInputNode(n) {
|
function PulseInputNode(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
|
|
||||||
// Store local copies of the node configuration (as defined in the .html)
|
// 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
|
// insensitive) and the payload is a valid number, set the count to that
|
||||||
// number, otherwise set it to zero
|
// number, otherwise set it to zero
|
||||||
var inputCallback = function (msg) {
|
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;
|
node.pulseCount = 0;
|
||||||
} else {
|
} else {
|
||||||
node.pulseCount = Number(msg.payload);
|
node.pulseCount = Number(msg.payload);
|
||||||
@ -332,10 +334,10 @@ function PulseInputNode(n) {
|
|||||||
} else {
|
} else {
|
||||||
node.error("Unconfigured input pin");
|
node.error("Unconfigured input pin");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node constructor for bbb-discrete-out
|
// Node constructor for bbb-discrete-out
|
||||||
function DiscreteOutputNode(n) {
|
function DiscreteOutputNode(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
|
|
||||||
// Store local copies of the node configuration (as defined in the .html)
|
// Store local copies of the node configuration (as defined in the .html)
|
||||||
@ -388,10 +390,10 @@ function DiscreteOutputNode(n) {
|
|||||||
} else {
|
} else {
|
||||||
node.error("Unconfigured output pin");
|
node.error("Unconfigured output pin");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node constructor for bbb-pulse-out
|
// Node constructor for bbb-pulse-out
|
||||||
function PulseOutputNode(n) {
|
function PulseOutputNode(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
|
|
||||||
// Store local copies of the node configuration (as defined in the .html)
|
// Store local copies of the node configuration (as defined in the .html)
|
||||||
@ -462,17 +464,17 @@ function PulseOutputNode(n) {
|
|||||||
} else {
|
} else {
|
||||||
node.error("Unconfigured output pin");
|
node.error("Unconfigured output pin");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the nodes by name. This must be called before overriding any of the Node functions.
|
// 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-analogue-in", AnalogueInputNode);
|
||||||
RED.nodes.registerType("bbb-discrete-in", DiscreteInputNode);
|
RED.nodes.registerType("bbb-discrete-in", DiscreteInputNode);
|
||||||
RED.nodes.registerType("bbb-pulse-in", PulseInputNode);
|
RED.nodes.registerType("bbb-pulse-in", PulseInputNode);
|
||||||
RED.nodes.registerType("bbb-discrete-out", DiscreteOutputNode);
|
RED.nodes.registerType("bbb-discrete-out", DiscreteOutputNode);
|
||||||
RED.nodes.registerType("bbb-pulse-out", PulseOutputNode);
|
RED.nodes.registerType("bbb-pulse-out", PulseOutputNode);
|
||||||
|
|
||||||
// On close, detach the interrupt (if we attached one) and clear any active timers
|
// On close, detach the interrupt (if we attached one) and clear any active timers
|
||||||
DiscreteInputNode.prototype.close = function () {
|
DiscreteInputNode.prototype.close = function () {
|
||||||
if (this.interruptAttached) {
|
if (this.interruptAttached) {
|
||||||
bonescript.detachInterrupt(this.pin);
|
bonescript.detachInterrupt(this.pin);
|
||||||
}
|
}
|
||||||
@ -482,21 +484,22 @@ DiscreteInputNode.prototype.close = function () {
|
|||||||
if (this.debounceTimer !== null) {
|
if (this.debounceTimer !== null) {
|
||||||
clearTimeout(this.debounceTimer);
|
clearTimeout(this.debounceTimer);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// On close, detach the interrupt (if we attached one) and clear the interval (if we set one)
|
// On close, detach the interrupt (if we attached one) and clear the interval (if we set one)
|
||||||
PulseInputNode.prototype.close = function () {
|
PulseInputNode.prototype.close = function () {
|
||||||
if (this.interruptAttached) {
|
if (this.interruptAttached) {
|
||||||
bonescript.detachInterrupt(this.pin);
|
bonescript.detachInterrupt(this.pin);
|
||||||
}
|
}
|
||||||
if (this.intervalId !== null) {
|
if (this.intervalId !== null) {
|
||||||
clearInterval(this.intervalId);
|
clearInterval(this.intervalId);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// On close, clear an active pulse timer
|
// On close, clear an active pulse timer
|
||||||
PulseOutputNode.prototype.close = function () {
|
PulseOutputNode.prototype.close = function () {
|
||||||
if (this.pulseTimer !== null) {
|
if (this.pulseTimer !== null) {
|
||||||
clearTimeout(this.pulseTimer);
|
clearTimeout(this.pulseTimer);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
@ -40,8 +40,9 @@ function BleScan(n) {
|
|||||||
this.on("input", function(msg){
|
this.on("input", function(msg){
|
||||||
noble.startScanning();
|
noble.startScanning();
|
||||||
});
|
});
|
||||||
|
|
||||||
noble.on('scanStart', function(msg) {
|
noble.on('scanStart', function(msg) {
|
||||||
var msg = {};
|
msg = {};
|
||||||
msg.topic = node.topic;
|
msg.topic = node.topic;
|
||||||
msg.payload = "Scanning initiated..." //debugging
|
msg.payload = "Scanning initiated..." //debugging
|
||||||
//console.log('scanning initiated...');
|
//console.log('scanning initiated...');
|
||||||
@ -49,7 +50,6 @@ function BleScan(n) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
noble.on('discover', function(peripheral) {
|
noble.on('discover', function(peripheral) {
|
||||||
|
|
||||||
var msg = {};
|
var msg = {};
|
||||||
msg.topic = node.topic;
|
msg.topic = node.topic;
|
||||||
msg.payload = "not found";
|
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)
|
//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) {
|
if(peripheral.advertisement.localName==node.ble_name && peripheral.advertisement.serviceUuids[0]==node.ble_uuid) {
|
||||||
msg.payload=peripheral.advertisement.localName;
|
msg.payload=peripheral.advertisement.localName;
|
||||||
noble.stopScanning(); }
|
noble.stopScanning();
|
||||||
|
}
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.on("close", function() {
|
this.on("close", function() {
|
||||||
try { noble.stopScanning(); }
|
try { noble.stopScanning(); }
|
||||||
|
@ -16,12 +16,12 @@
|
|||||||
|
|
||||||
module.exports = function(RED) {
|
module.exports = function(RED) {
|
||||||
"use strict";
|
"use strict";
|
||||||
var WeMo = new require('wemo');
|
var Wemo = require('wemo');
|
||||||
|
|
||||||
function WeMoOut(n) {
|
function WemoOut(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.ipaddr = n.ipaddr;
|
this.ipaddr = n.ipaddr;
|
||||||
this.wemoSwitch = new WeMo(n.ipaddr);
|
this.wemoSwitch = new Wemo(n.ipaddr);
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
this.on("input", function(msg) {
|
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);
|
RED.nodes.createNode(this,n);
|
||||||
this.ipaddr = n.ipaddr;
|
this.ipaddr = n.ipaddr;
|
||||||
this.wemoSwitch = new WeMo(n.ipaddr);
|
this.wemoSwitch = new WeMo(n.ipaddr);
|
||||||
@ -58,5 +58,5 @@ module.exports = function(RED) {
|
|||||||
clearInterval(tick);
|
clearInterval(tick);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("wemo in",WeMoOut);
|
RED.nodes.registerType("wemo in",WemoIn);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user