Apply consistent style to node-red-nodes

(not updating npm for this yet - just whitespace)
This commit is contained in:
dceejay
2015-05-11 19:25:39 +01:00
parent 84f61a0466
commit f497b57b7d
18 changed files with 278 additions and 273 deletions

View File

@@ -54,7 +54,7 @@ module.exports = function (RED) {
}
}
// Node constructor for bbb-analogue-in
// Node constructor for bbb-analogue-in
function AnalogueInputNode(n) {
RED.nodes.createNode(this, n);
var node = this;
@@ -110,7 +110,7 @@ module.exports = function (RED) {
}
}
// Node constructor for bbb-discrete-in
// Node constructor for bbb-discrete-in
function DiscreteInputNode(n) {
RED.nodes.createNode(this, n);
var node = this;
@@ -141,7 +141,7 @@ module.exports = function (RED) {
this.intervalId = null; // Remember the timer ID so we can delete it when we are closed
this.currentState = 0; // The pin input state "1" or "0"
this.lastActiveTime = NaN; // The date (in ms since epoch) when the pin last went high
// switch to process.hrtime()
// switch to process.hrtime()
this.totalActiveTime = 0; // The total time in ms that the pin has been high (since reset)
this.starting = true;
this.debouncing = false; // True after a change of state while waiting for the 7ms debounce time to elapse
@@ -285,7 +285,7 @@ module.exports = function (RED) {
}
}
// Node constructor for bbb-pulse-in
// Node constructor for bbb-pulse-in
function PulseInputNode(n) {
RED.nodes.createNode(this, n);
var node = this;
@@ -383,7 +383,7 @@ module.exports = function (RED) {
}
}
// Node constructor for bbb-discrete-out
// Node constructor for bbb-discrete-out
function DiscreteOutputNode(n) {
RED.nodes.createNode(this, n);
var node = this;
@@ -443,7 +443,7 @@ module.exports = function (RED) {
}
}
// Node constructor for bbb-pulse-out
// Node constructor for bbb-pulse-out
function PulseOutputNode(n) {
RED.nodes.createNode(this, n);
var node = this;
@@ -519,14 +519,14 @@ module.exports = function (RED) {
}
}
// 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-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
// 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);
@@ -539,7 +539,7 @@ module.exports = function (RED) {
}
};
// 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 () {
if (this.interruptAttached) {
bonescript.detachInterrupt(this._pin);
@@ -549,7 +549,7 @@ module.exports = function (RED) {
}
};
// On close, clear an active pulse timer
// On close, clear an active pulse timer
PulseOutputNode.prototype.close = function () {
if (this.pulseTimer !== null) {
clearTimeout(this.pulseTimer);

View File

@@ -17,12 +17,12 @@
module.exports = function(RED) {
"use strict";
var exec = require('child_process').exec;
var fs = require('fs');
var fs = require('fs');
var gpioCommand = '/usr/local/bin/gpiohb';
//if (!fs.existsSync("/sys/devices/soc0/machine")) { // unlikely if not on a Hummingboard
//throw "Info : Ignoring Hummingboard specific node.";
//throw "Info : Ignoring Hummingboard specific node.";
//}
if (!fs.existsSync(gpioCommand)) { // gpio command not installed
@@ -31,66 +31,66 @@ module.exports = function(RED) {
// Map physical P1 pins to Gordon's Wiring-Pi Pins (as they should be V1/V2 tolerant)
var pintable = {
// Physical : WiringPi
"11":"0",
"12":"1",
"13":"2",
"15":"3",
"16":"4",
"18":"5",
"22":"6",
"7":"7",
"3":"8",
"5":"9",
"24":"10",
"26":"11",
"19":"12",
"21":"13",
"23":"14",
"8":"15",
"10":"16",
"27":"30",
"28":"31",
"29":"21",
"31":"22",
"32":"26",
"33":"23",
"35":"24",
"36":"27",
"37":"25",
"38":"28",
"40":"29"
// Physical : WiringPi
"11":"0",
"12":"1",
"13":"2",
"15":"3",
"16":"4",
"18":"5",
"22":"6",
"7":"7",
"3":"8",
"5":"9",
"24":"10",
"26":"11",
"19":"12",
"21":"13",
"23":"14",
"8":"15",
"10":"16",
"27":"30",
"28":"31",
"29":"21",
"31":"22",
"32":"26",
"33":"23",
"35":"24",
"36":"27",
"37":"25",
"38":"28",
"40":"29"
}
var tablepin = {
// WiringPi : Physical
"0":"11",
"1":"12",
"2":"13",
"3":"15",
"4":"16",
"5":"18",
"6":"22",
"7":"7",
"8":"3",
"9":"5",
"10":"24",
"11":"26",
"12":"19",
"13":"21",
"14":"23",
"15":"8",
"16":"10",
"30":"27",
"31":"28",
"21":"29",
"22":"31",
"26":"32",
"23":"33",
"24":"35",
"27":"36",
"25":"37",
"28":"38",
"29":"40"
// WiringPi : Physical
"0":"11",
"1":"12",
"2":"13",
"3":"15",
"4":"16",
"5":"18",
"6":"22",
"7":"7",
"8":"3",
"9":"5",
"10":"24",
"11":"26",
"12":"19",
"13":"21",
"14":"23",
"15":"8",
"16":"10",
"30":"27",
"31":"28",
"21":"29",
"22":"31",
"26":"32",
"23":"33",
"24":"35",
"27":"36",
"25":"37",
"28":"38",
"29":"40"
}
function GPIOHBInNode(n) {

View File

@@ -19,7 +19,7 @@ module.exports = function(RED) {
var util = require("util");
//var exec = require('child_process').exec;
var spawn = require('child_process').spawn;
var fs = require('fs');
var fs = require('fs');
var gpioCommand = __dirname+'/nrgpio';

View File

@@ -18,7 +18,7 @@ module.exports = function(RED) {
"use strict";
var util = require("util");
var exec = require('child_process').exec;
var fs = require('fs');
var fs = require('fs');
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
throw "Info : Ignoring Raspberry Pi specific node.";
@@ -30,31 +30,31 @@ module.exports = function(RED) {
// Map names of pins to Gordon's gpio PiFace pin numbers
var pintable = {
// Physical : WiringPi
"Button S1":"200",
"Button S2":"201",
"Button S3":"202",
"Button S4":"203",
"Input 5":"204",
"Input 6":"205",
"Input 7":"206",
"Input 8":"207",
"Output0":"208",
"Output1":"209",
"Output2":"210",
"Output3":"211",
"Output4":"212",
"Output5":"213",
"Output6":"214",
"Output7":"215",
"LED 0 / Relay 0":"200",
"LED 1 / Relay 1":"201",
"LED 2":"202",
"LED 3":"203",
"LED 4":"204",
"LED 5":"205",
"LED 6":"206",
"LED 7":"207"
// Physical : WiringPi
"Button S1":"200",
"Button S2":"201",
"Button S3":"202",
"Button S4":"203",
"Input 5":"204",
"Input 6":"205",
"Input 7":"206",
"Input 8":"207",
"Output0":"208",
"Output1":"209",
"Output2":"210",
"Output3":"211",
"Output4":"212",
"Output5":"213",
"Output6":"214",
"Output7":"215",
"LED 0 / Relay 0":"200",
"LED 1 / Relay 1":"201",
"LED 2":"202",
"LED 3":"203",
"LED 4":"204",
"LED 5":"205",
"LED 6":"206",
"LED 7":"207"
}
function PiFACEInNode(n) {

View File

@@ -18,7 +18,7 @@ module.exports = function(RED) {
"use strict";
var util = require("util");
var spawn = require('child_process').spawn;
var fs = require('fs');
var fs = require('fs');
var gpioCommand = __dirname+'/nrgpio';

View File

@@ -18,7 +18,7 @@ module.exports = function(RED) {
"use strict";
var util = require("util");
var spawn = require('child_process').spawn;
var fs = require('fs');
var fs = require('fs');
var gpioCommand = __dirname+'/nrgpio';

View File

@@ -35,38 +35,38 @@ module.exports = function(RED) {
if (blink1) {
var r,g,b;
try {
if (p1.test(msg.payload)) {
// if it is a hex colour string
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); }
else { blink1.fadeToRGB(node.fade, parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255); }
}
else {
// you can add fancy colours by name here if you want...
// these are the @cheerlight ones.
var colors = {"red":"#FF0000","green":"#00FF00","blue":"#0000FF","cyan":"#00FFFF",
"white":"#FFFFFF","warmwhite":"#FDF5E6","oldlace":"#FDF5E6","purple":"#800080","magenta":"#FF00FF",
"yellow":"#FFFF00","amber":"#FFD200","orange":"#FFA500","black":"#000000","pink":"#FF69B4"}
if (msg.payload.toLowerCase() in colors) {
var c = colors[msg.payload.toLowerCase()];
r = parseInt(c.slice(1,3),16);
g = parseInt(c.slice(3,5),16);
b = parseInt(c.slice(5),16);
if (p1.test(msg.payload)) {
// if it is a hex colour string
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 {
node.warn("Blink1 : invalid msg : "+msg.payload);
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); }
else { blink1.fadeToRGB(node.fade, parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255); }
}
else {
// you can add fancy colours by name here if you want...
// these are the @cheerlight ones.
var colors = {"red":"#FF0000","green":"#00FF00","blue":"#0000FF","cyan":"#00FFFF",
"white":"#FFFFFF","warmwhite":"#FDF5E6","oldlace":"#FDF5E6","purple":"#800080","magenta":"#FF00FF",
"yellow":"#FFFF00","amber":"#FFD200","orange":"#FFA500","black":"#000000","pink":"#FF69B4"}
if (msg.payload.toLowerCase() in colors) {
var c = colors[msg.payload.toLowerCase()];
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 {
node.warn("Blink1 : invalid msg : "+msg.payload);
}
}
}
} catch (e) { node.error("Blink1 : error"); blink1 = null; }
}
else {

View File

@@ -148,8 +148,8 @@ module.exports = function(RED) {
for (var key in message.payload) {
if (message.payload.hasOwnProperty(key)) {
// Ensure our valid keys contain valid values
switch(key) {
case "runmode" :
switch (key) {
case "runmode" : {
if (DEBUG) {
hminnode.log("Hit the runmode case");
}
@@ -158,8 +158,9 @@ module.exports = function(RED) {
return;
}
break;
}
//case "holiday" :
//case "holiday" : {
//if (DEBUG) {
//hminnode.log("Hit the holiday case");
//}
@@ -183,8 +184,9 @@ module.exports = function(RED) {
//message.payload.away_mode = 0;
//}
//break;
// }
//case "hotwater" :
//case "hotwater" : {
//if (DEBUG) {
//hminnode.log("Hit the hotwater case");
//}
@@ -193,8 +195,9 @@ module.exports = function(RED) {
//return;
//}
//break;
// }
case "heating" :
case "heating" : {
// Ensure heating stays last! It's got a multi write scenario
if (DEBUG) {
hminnode.log("Hit the heating case");
@@ -226,9 +229,11 @@ module.exports = function(RED) {
return;
}
break;
}
default :
default : {
break;
}
}
// Valid set of key messages, construct DCB and write
var dcb = message.payload;

View File

@@ -55,7 +55,7 @@ function BleScan(n) {
msg.payload = "not found";
//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;
noble.stopScanning();
}

View File

@@ -40,8 +40,8 @@ function sensorTagNode(n) {
var node=this;
if ( typeof node.stag == "undefined") {
//console.log("starting");
SensorTag.discover(function(sensorTag){
//console.log("starting");
SensorTag.discover(function(sensorTag){
node.stag = sensorTag;
sensorTag.connect(function(){
//console.log("connected");
@@ -49,11 +49,11 @@ function sensorTagNode(n) {
sensorTag.enableIrTemperature(function(){});
sensorTag.on('irTemperatureChange',
function(objectTemperature, ambientTemperature){
var msg = {'topic': node.topic + '/temperature'};
msg.payload = {'object': objectTemperature.toFixed(1),
'ambient':ambientTemperature.toFixed(1)
};
node.send(msg);
var msg = {'topic': node.topic + '/temperature'};
msg.payload = {'object': objectTemperature.toFixed(1),
'ambient':ambientTemperature.toFixed(1)
};
node.send(msg);
});
sensorTag.enableBarometricPressure(function(){});
sensorTag.on('barometricPressureChange', function(pressure){
@@ -71,34 +71,34 @@ function sensorTagNode(n) {
});
sensorTag.enableAccelerometer(function(){});
sensorTag.on('accelerometerChange', function(x,y,z){
var msg = {'topic': node.topic + '/accelerometer'};
msg.payload = {'x': x, 'y': y, 'z': z};
node.send(msg);
var msg = {'topic': node.topic + '/accelerometer'};
msg.payload = {'x': x, 'y': y, 'z': z};
node.send(msg);
});
sensorTag.enableMagnetometer(function() {});
sensorTag.on('magnetometerChange', function(x,y,z){
var msg = {'topic': node.topic + '/magnetometer'};
msg.payload = {'x': x, 'y': y, 'z': z};
node.send(msg);
var msg = {'topic': node.topic + '/magnetometer'};
msg.payload = {'x': x, 'y': y, 'z': z};
node.send(msg);
});
sensorTag.enableGyroscope(function(){});
sensorTag.on('gyroscopeChange', function(x,y,z){
var msg = {'topic': node.topic + '/gyroscope'};
msg.payload = {'x': x, 'y': y, 'z': z};
node.send(msg);
var msg = {'topic': node.topic + '/gyroscope'};
msg.payload = {'x': x, 'y': y, 'z': z};
node.send(msg);
});
sensorTag.on('simpleKeyChange', function(left, right){
var msg = {'topic': node.topic + '/keys'};
msg.payload = {'left': left, 'right': right};
node.send(msg);
var msg = {'topic': node.topic + '/keys'};
msg.payload = {'left': left, 'right': right};
node.send(msg);
});
enable(node);
});
});
},node.uuid);
} else {
//console.log("reconfig");
enable(node);
//console.log("reconfig");
enable(node);
}
}
@@ -106,37 +106,37 @@ function enable(node) {
if (node.temperature) {
node.stag.notifyIrTemperature(function(){});
} else {
node.stag.unnotifyIrTemperature(function(){});
node.stag.unnotifyIrTemperature(function(){});
}
if (node.pressure) {
node.stag.notifyBarometricPressure(function(){});
node.stag.notifyBarometricPressure(function(){});
} else {
node.stag.unnotifyBarometricPressure(function(){});
node.stag.unnotifyBarometricPressure(function(){});
}
if (node.humidity) {
node.stag.notifyHumidity(function() {});
node.stag.notifyHumidity(function() {});
} else {
node.stag.unnotifyHumidity(function() {});
node.stag.unnotifyHumidity(function() {});
}
if (node.accelerometer){
node.stag.notifyAccelerometer(function() {});
node.stag.notifyAccelerometer(function() {});
} else {
node.stag.unnotifyAccelerometer(function() {});
node.stag.unnotifyAccelerometer(function() {});
}
if (node.magnetometer) {
node.stag.notifyMagnetometer(function() {});
node.stag.notifyMagnetometer(function() {});
} else {
node.stag.unnotifyMagnetometer(function() {});
node.stag.unnotifyMagnetometer(function() {});
}
if (node.gyroscope) {
node.stag.notifyGyroscope(function() {});
node.stag.notifyGyroscope(function() {});
} else {
node.stag.unnotifyGyroscope(function() {});
node.stag.unnotifyGyroscope(function() {});
}
if (node.keys) {
node.stag.notifySimpleKey(function() {});
node.stag.notifySimpleKey(function() {});
} else {
node.stag.unnotifySimpleKey(function() {});
node.stag.unnotifySimpleKey(function() {});
}
}
RED.nodes.registerType("sensorTag",sensorTagNode);