mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
Update node-red-nodes hardware nodes to use strict and pass jshint scan
This commit is contained in:
parent
62956b0bb8
commit
9e0585a721
@ -14,7 +14,8 @@
|
|||||||
* limitations under the License.
|
* 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 util = require("util");
|
||||||
var exec = require('child_process').exec;
|
var exec = require('child_process').exec;
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
@ -91,11 +92,11 @@ function PiFACEInNode(n) {
|
|||||||
var node = this;
|
var node = this;
|
||||||
if (node.pin) {
|
if (node.pin) {
|
||||||
exec("gpio -p mode "+node.pin+" "+node.intype, function(err,stdout,stderr) {
|
exec("gpio -p mode "+node.pin+" "+node.intype, function(err,stdout,stderr) {
|
||||||
if (err) node.error(err);
|
if (err) { node.error(err); }
|
||||||
else {
|
else {
|
||||||
node._interval = setInterval( function() {
|
node._interval = setInterval( function() {
|
||||||
exec("gpio -p read "+node.pin, function(err,stdout,stderr) {
|
exec("gpio -p read "+node.pin, function(err,stdout,stderr) {
|
||||||
if (err) node.error(err);
|
if (err) { node.error(err); }
|
||||||
else {
|
else {
|
||||||
if (node.buttonState !== Number(stdout)) {
|
if (node.buttonState !== Number(stdout)) {
|
||||||
var previousState = node.buttonState;
|
var previousState = node.buttonState;
|
||||||
@ -125,15 +126,15 @@ function PiFACEOutNode(n) {
|
|||||||
var node = this;
|
var node = this;
|
||||||
if (node.pin) {
|
if (node.pin) {
|
||||||
node.on("input", function(msg) {
|
node.on("input", function(msg) {
|
||||||
if (msg.payload === "true") msg.payload = true;
|
if (msg.payload === "true") { msg.payload = true; }
|
||||||
if (msg.payload === "false") msg.payload = false;
|
if (msg.payload === "false") { msg.payload = false; }
|
||||||
var out = Number(msg.payload);
|
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) {
|
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 {
|
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 in",PiFACEInNode);
|
||||||
RED.nodes.registerType("rpi-piface out",PiFACEOutNode);
|
RED.nodes.registerType("rpi-piface out",PiFACEOutNode);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
* limitations under the License.
|
* 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 util = require("util");
|
||||||
var exec = require('child_process').exec;
|
var exec = require('child_process').exec;
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
@ -69,11 +70,11 @@ function PibrellaIn(n) {
|
|||||||
|
|
||||||
if (node.pin) {
|
if (node.pin) {
|
||||||
exec("gpio mode "+node.pin+" in", function(err,stdout,stderr) {
|
exec("gpio mode "+node.pin+" in", function(err,stdout,stderr) {
|
||||||
if (err) node.error(err);
|
if (err) { node.error(err); }
|
||||||
else {
|
else {
|
||||||
node._interval = setInterval( function() {
|
node._interval = setInterval( function() {
|
||||||
exec("gpio read "+node.pin, function(err,stdout,stderr) {
|
exec("gpio read "+node.pin, function(err,stdout,stderr) {
|
||||||
if (err) node.error(err);
|
if (err) { node.error(err); }
|
||||||
else {
|
else {
|
||||||
if (node.buttonState !== Number(stdout)) {
|
if (node.buttonState !== Number(stdout)) {
|
||||||
var previousState = node.buttonState;
|
var previousState = node.buttonState;
|
||||||
@ -124,18 +125,18 @@ function PibrellaOut(n) {
|
|||||||
else if (node.pin) {
|
else if (node.pin) {
|
||||||
process.nextTick(function() {
|
process.nextTick(function() {
|
||||||
exec("gpio mode "+node.pin+" out", function(err,stdout,stderr) {
|
exec("gpio mode "+node.pin+" out", function(err,stdout,stderr) {
|
||||||
if (err) node.error(err);
|
if (err) { node.error(err); }
|
||||||
else {
|
else {
|
||||||
node.on("input", function(msg) {
|
node.on("input", function(msg) {
|
||||||
if (msg.payload === "true") msg.payload = true;
|
if (msg.payload === "true") { msg.payload = true; }
|
||||||
if (msg.payload === "false") msg.payload = false;
|
if (msg.payload === "false") { msg.payload = false; }
|
||||||
var out = Number(msg.payload);
|
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) {
|
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 in",PibrellaIn);
|
||||||
RED.nodes.registerType("rpi-pibrella out",PibrellaOut);
|
RED.nodes.registerType("rpi-pibrella out",PibrellaOut);
|
||||||
|
}
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
* limitations under the License.
|
* 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 util = require('util');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ function LedBorgNode(n) {
|
|||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
if (p1.test(msg.payload)) {
|
if (p1.test(msg.payload)) {
|
||||||
fs.writeFile('/dev/ledborg', msg.payload, function (err) {
|
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)) {
|
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 g = Math.floor(parseInt(msg.payload.slice(3,5),16)/88).toString();
|
||||||
var b = Math.floor(parseInt(msg.payload.slice(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) {
|
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 {
|
else {
|
||||||
@ -51,7 +52,7 @@ function LedBorgNode(n) {
|
|||||||
if (msg.payload.toLowerCase() in colors) {
|
if (msg.payload.toLowerCase() in colors) {
|
||||||
var c = colors[msg.payload.toLowerCase()];
|
var c = colors[msg.payload.toLowerCase()];
|
||||||
fs.writeFile('/dev/ledborg', c, function (err) {
|
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 {
|
else {
|
||||||
@ -61,3 +62,4 @@ function LedBorgNode(n) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("ledborg",LedBorgNode);
|
RED.nodes.registerType("ledborg",LedBorgNode);
|
||||||
|
}
|
||||||
|
@ -14,12 +14,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
module.exports = function(RED) {
|
||||||
|
"use strict";
|
||||||
var blinkstick = require("blinkstick");
|
var blinkstick = require("blinkstick");
|
||||||
|
|
||||||
Object.size = function(obj) {
|
Object.size = function(obj) {
|
||||||
var size = 0, key;
|
var size = 0;
|
||||||
for (key in obj) { if (obj.hasOwnProperty(key)) size++; }
|
for (var key in obj) { if (obj.hasOwnProperty(key)) { size++; } }
|
||||||
return size;
|
return size;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -60,3 +61,4 @@ function BlinkStick(n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RED.nodes.registerType("blinkstick",BlinkStick);
|
RED.nodes.registerType("blinkstick",BlinkStick);
|
||||||
|
}
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
* limitations under the License.
|
* 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");
|
var Blink1 = require("node-blink1");
|
||||||
// create a single global blink1 object
|
// create a single global blink1 object
|
||||||
// all blink1 nodes affect the same (single) led
|
// all blink1 nodes affect the same (single) led
|
||||||
@ -31,19 +32,20 @@ function Blink1Node(n) {
|
|||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
blink1 = blink1 || new Blink1.Blink1();
|
blink1 = blink1 || new Blink1.Blink1();
|
||||||
if (blink1) {
|
if (blink1) {
|
||||||
|
var r,g,b;
|
||||||
try {
|
try {
|
||||||
if (p1.test(msg.payload)) {
|
if (p1.test(msg.payload)) {
|
||||||
// if it is a hex colour string
|
// if it is a hex colour string
|
||||||
var r = parseInt(msg.payload.slice(1,3),16);
|
r = parseInt(msg.payload.slice(1,3),16);
|
||||||
var g = parseInt(msg.payload.slice(3,5),16);
|
g = parseInt(msg.payload.slice(3,5),16);
|
||||||
var b = parseInt(msg.payload.slice(5),16);
|
b = parseInt(msg.payload.slice(5),16);
|
||||||
if (node.fade == 0) { blink1.setRGB( r, g, b ); }
|
if (node.fade === 0) { blink1.setRGB( r, g, b ); }
|
||||||
else { blink1.fadeToRGB(node.fade, r, g, b ); }
|
else { blink1.fadeToRGB(node.fade, r, g, b ); }
|
||||||
}
|
}
|
||||||
else if (p2.test(msg.payload)) {
|
else if (p2.test(msg.payload)) {
|
||||||
// if it is a r,g,b triple
|
// if it is a r,g,b triple
|
||||||
var rgb = msg.payload.split(',');
|
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 { blink1.fadeToRGB(node.fade, parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255); }
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -53,10 +55,10 @@ function Blink1Node(n) {
|
|||||||
"purple":"#800080","magenta":"#FF00FF","yellow":"#FFFF00","amber":"#FFD200","orange":"#FFA500","black":"#000000"}
|
"purple":"#800080","magenta":"#FF00FF","yellow":"#FFFF00","amber":"#FFD200","orange":"#FFA500","black":"#000000"}
|
||||||
if (msg.payload.toLowerCase() in colors) {
|
if (msg.payload.toLowerCase() in colors) {
|
||||||
var c = colors[msg.payload.toLowerCase()];
|
var c = colors[msg.payload.toLowerCase()];
|
||||||
var r = parseInt(c.slice(1,3),16);
|
r = parseInt(c.slice(1,3),16);
|
||||||
var g = parseInt(c.slice(3,5),16);
|
g = parseInt(c.slice(3,5),16);
|
||||||
var b = parseInt(c.slice(5),16);
|
b = parseInt(c.slice(5),16);
|
||||||
if (node.fade == 0) { blink1.setRGB( r, g, b ); }
|
if (node.fade === 0) { blink1.setRGB( r, g, b ); }
|
||||||
else { blink1.fadeToRGB(node.fade, r, g, b ); }
|
else { blink1.fadeToRGB(node.fade, r, g, b ); }
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -81,3 +83,4 @@ function Blink1Node(n) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("blink1",Blink1Node);
|
RED.nodes.registerType("blink1",Blink1Node);
|
||||||
|
}
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
* limitations under the License.
|
* 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 HID = require('node-hid');
|
||||||
var device;
|
var device;
|
||||||
var node;
|
var node;
|
||||||
@ -67,3 +68,4 @@ function DigiRGBNode(n) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("digiRGB",DigiRGBNode);
|
RED.nodes.registerType("digiRGB",DigiRGBNode);
|
||||||
|
}
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
* limitations under the License.
|
* 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');
|
var WeMo = new require('wemo');
|
||||||
|
|
||||||
function WeMoOut(n) {
|
function WeMoOut(n) {
|
||||||
@ -26,9 +27,9 @@ function WeMoOut(n) {
|
|||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
var state = 0;
|
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) {
|
node.wemoSwitch.setBinaryState(state, function(err, result) {
|
||||||
if (err) node.warn(err);
|
if (err) { node.warn(err); }
|
||||||
//else { node.log(result); }
|
//else { node.log(result); }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -45,7 +46,7 @@ function WeMoIn(n) {
|
|||||||
|
|
||||||
var tick = setInterval(function() {
|
var tick = setInterval(function() {
|
||||||
wemoSwitch.getBinaryState(function(err, result) {
|
wemoSwitch.getBinaryState(function(err, result) {
|
||||||
if (err) node.warn(err);
|
if (err) { node.warn(err); }
|
||||||
if (parseInt(result) != wemoSwitch.state) {
|
if (parseInt(result) != wemoSwitch.state) {
|
||||||
wemoSwitch.state = parseInt(result);
|
wemoSwitch.state = parseInt(result);
|
||||||
node.send({payload:wemoSwitch.state,topic:"wemo/"+node.ipaddr});
|
node.send({payload:wemoSwitch.state,topic:"wemo/"+node.ipaddr});
|
||||||
@ -58,3 +59,4 @@ function WeMoIn(n) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("wemo in",WeMoOut);
|
RED.nodes.registerType("wemo in",WeMoOut);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user