1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Update node-red-nodes hardware nodes to use strict and pass jshint scan

This commit is contained in:
Dave C-J 2014-06-28 23:35:21 +01:00
parent 62956b0bb8
commit 9e0585a721
7 changed files with 496 additions and 481 deletions

View File

@ -14,7 +14,8 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
module.exports = function(RED) {
"use strict";
var util = require("util");
var exec = require('child_process').exec;
var fs = require('fs');
@ -91,11 +92,11 @@ function PiFACEInNode(n) {
var node = this;
if (node.pin) {
exec("gpio -p mode "+node.pin+" "+node.intype, function(err,stdout,stderr) {
if (err) node.error(err);
if (err) { node.error(err); }
else {
node._interval = setInterval( function() {
exec("gpio -p read "+node.pin, function(err,stdout,stderr) {
if (err) node.error(err);
if (err) { node.error(err); }
else {
if (node.buttonState !== Number(stdout)) {
var previousState = node.buttonState;
@ -125,15 +126,15 @@ function PiFACEOutNode(n) {
var node = this;
if (node.pin) {
node.on("input", function(msg) {
if (msg.payload === "true") msg.payload = true;
if (msg.payload === "false") msg.payload = false;
if (msg.payload === "true") { msg.payload = true; }
if (msg.payload === "false") { msg.payload = false; }
var out = Number(msg.payload);
if ((out == 0)|(out == 1)) {
if ((out === 0)|(out === 1)) {
exec("gpio -p write "+node.pin+" "+out, function(err,stdout,stderr) {
if (err) node.error(err);
if (err) { node.error(err); }
});
}
else node.warn("Invalid input - not 0 or 1");
else { node.warn("Invalid input - not 0 or 1"); }
});
}
else {
@ -149,3 +150,4 @@ exec("gpio load spi",function(err,stdout,stderr) {
RED.nodes.registerType("rpi-piface in",PiFACEInNode);
RED.nodes.registerType("rpi-piface out",PiFACEOutNode);
});
}

View File

@ -14,7 +14,8 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
module.exports = function(RED) {
"use strict";
var util = require("util");
var exec = require('child_process').exec;
var fs = require('fs');
@ -69,11 +70,11 @@ function PibrellaIn(n) {
if (node.pin) {
exec("gpio mode "+node.pin+" in", function(err,stdout,stderr) {
if (err) node.error(err);
if (err) { node.error(err); }
else {
node._interval = setInterval( function() {
exec("gpio read "+node.pin, function(err,stdout,stderr) {
if (err) node.error(err);
if (err) { node.error(err); }
else {
if (node.buttonState !== Number(stdout)) {
var previousState = node.buttonState;
@ -124,18 +125,18 @@ function PibrellaOut(n) {
else if (node.pin) {
process.nextTick(function() {
exec("gpio mode "+node.pin+" out", function(err,stdout,stderr) {
if (err) node.error(err);
if (err) { node.error(err); }
else {
node.on("input", function(msg) {
if (msg.payload === "true") msg.payload = true;
if (msg.payload === "false") msg.payload = false;
if (msg.payload === "true") { msg.payload = true; }
if (msg.payload === "false") { msg.payload = false; }
var out = Number(msg.payload);
if ((out == 0)|(out == 1)) {
if ((out === 0)|(out === 1)) {
exec("gpio write "+node.pin+" "+out, function(err,stdout,stderr) {
if (err) node.error(err);
if (err) { node.error(err); }
});
}
else node.warn("Invalid input - not 0 or 1");
else { node.warn("Invalid input - not 0 or 1"); }
});
}
});
@ -170,3 +171,4 @@ function PibrellaOut(n) {
RED.nodes.registerType("rpi-pibrella in",PibrellaIn);
RED.nodes.registerType("rpi-pibrella out",PibrellaOut);
}

View File

@ -14,7 +14,8 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
module.exports = function(RED) {
"use strict";
var util = require('util');
var fs = require('fs');
@ -32,7 +33,7 @@ function LedBorgNode(n) {
this.on("input", function(msg) {
if (p1.test(msg.payload)) {
fs.writeFile('/dev/ledborg', msg.payload, function (err) {
if (err) node.warn(msg.payload+" : No LedBorg found");
if (err) { node.warn(msg.payload+" : No LedBorg found"); }
});
}
else if (p2.test(msg.payload)) {
@ -40,7 +41,7 @@ function LedBorgNode(n) {
var g = Math.floor(parseInt(msg.payload.slice(3,5),16)/88).toString();
var b = Math.floor(parseInt(msg.payload.slice(5),16)/88).toString();
fs.writeFile('/dev/ledborg', r+g+b, function (err) {
if (err) node.warn(r+g+b+" : No LedBorg found");
if (err) { node.warn(r+g+b+" : No LedBorg found"); }
});
}
else {
@ -51,7 +52,7 @@ function LedBorgNode(n) {
if (msg.payload.toLowerCase() in colors) {
var c = colors[msg.payload.toLowerCase()];
fs.writeFile('/dev/ledborg', c, function (err) {
if (err) node.warn(msg.payload+" : No LedBorg found");
if (err) { node.warn(msg.payload+" : No LedBorg found"); }
});
}
else {
@ -61,3 +62,4 @@ function LedBorgNode(n) {
});
}
RED.nodes.registerType("ledborg",LedBorgNode);
}

View File

@ -14,12 +14,13 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
module.exports = function(RED) {
"use strict";
var blinkstick = require("blinkstick");
Object.size = function(obj) {
var size = 0, key;
for (key in obj) { if (obj.hasOwnProperty(key)) size++; }
var size = 0;
for (var key in obj) { if (obj.hasOwnProperty(key)) { size++; } }
return size;
};
@ -60,3 +61,4 @@ function BlinkStick(n) {
}
RED.nodes.registerType("blinkstick",BlinkStick);
}

View File

@ -14,7 +14,8 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
module.exports = function(RED) {
"use strict";
var Blink1 = require("node-blink1");
// create a single global blink1 object
// all blink1 nodes affect the same (single) led
@ -31,19 +32,20 @@ function Blink1Node(n) {
this.on("input", function(msg) {
blink1 = blink1 || new Blink1.Blink1();
if (blink1) {
var r,g,b;
try {
if (p1.test(msg.payload)) {
// if it is a hex colour string
var r = parseInt(msg.payload.slice(1,3),16);
var g = parseInt(msg.payload.slice(3,5),16);
var b = parseInt(msg.payload.slice(5),16);
if (node.fade == 0) { blink1.setRGB( r, g, b ); }
r = parseInt(msg.payload.slice(1,3),16);
g = parseInt(msg.payload.slice(3,5),16);
b = parseInt(msg.payload.slice(5),16);
if (node.fade === 0) { blink1.setRGB( r, g, b ); }
else { blink1.fadeToRGB(node.fade, r, g, b ); }
}
else if (p2.test(msg.payload)) {
// if it is a r,g,b triple
var rgb = msg.payload.split(',');
if (node.fade == 0) { blink1.setRGB(parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255); }
if (node.fade === 0) { blink1.setRGB(parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255); }
else { blink1.fadeToRGB(node.fade, parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255); }
}
else {
@ -53,10 +55,10 @@ function Blink1Node(n) {
"purple":"#800080","magenta":"#FF00FF","yellow":"#FFFF00","amber":"#FFD200","orange":"#FFA500","black":"#000000"}
if (msg.payload.toLowerCase() in colors) {
var c = colors[msg.payload.toLowerCase()];
var r = parseInt(c.slice(1,3),16);
var g = parseInt(c.slice(3,5),16);
var b = parseInt(c.slice(5),16);
if (node.fade == 0) { blink1.setRGB( r, g, b ); }
r = parseInt(c.slice(1,3),16);
g = parseInt(c.slice(3,5),16);
b = parseInt(c.slice(5),16);
if (node.fade === 0) { blink1.setRGB( r, g, b ); }
else { blink1.fadeToRGB(node.fade, r, g, b ); }
}
else {
@ -81,3 +83,4 @@ function Blink1Node(n) {
}
}
RED.nodes.registerType("blink1",Blink1Node);
}

View File

@ -14,7 +14,8 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
module.exports = function(RED) {
"use strict";
var HID = require('node-hid');
var device;
var node;
@ -67,3 +68,4 @@ function DigiRGBNode(n) {
});
}
RED.nodes.registerType("digiRGB",DigiRGBNode);
}

View File

@ -14,7 +14,8 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
module.exports = function(RED) {
"use strict";
var WeMo = new require('wemo');
function WeMoOut(n) {
@ -26,9 +27,9 @@ function WeMoOut(n) {
this.on("input", function(msg) {
if (msg != null) {
var state = 0;
if ( msg.payload == 1 || msg.payload == true || msg.payload == "on" ) { var state = 1; }
if ( msg.payload == 1 || msg.payload === true || msg.payload == "on" ) { state = 1; }
node.wemoSwitch.setBinaryState(state, function(err, result) {
if (err) node.warn(err);
if (err) { node.warn(err); }
//else { node.log(result); }
});
}
@ -45,7 +46,7 @@ function WeMoIn(n) {
var tick = setInterval(function() {
wemoSwitch.getBinaryState(function(err, result) {
if (err) node.warn(err);
if (err) { node.warn(err); }
if (parseInt(result) != wemoSwitch.state) {
wemoSwitch.state = parseInt(result);
node.send({payload:wemoSwitch.state,topic:"wemo/"+node.ipaddr});
@ -58,3 +59,4 @@ function WeMoIn(n) {
});
}
RED.nodes.registerType("wemo in",WeMoOut);
}