mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Misc tidy ups of jsHint "issues" for some node-red-nodes
This commit is contained in:
parent
3644f16a89
commit
f4fdebfba5
@ -14,46 +14,48 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var RED = require(process.env.NODE_RED_HOME + "/red/red");
|
module.exports = function(RED) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
function SmoothNode(n) {
|
function SmoothNode(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
this.action = n.action;
|
this.action = n.action;
|
||||||
this.round = n.round || false;
|
this.round = n.round || false;
|
||||||
this.count = Number(n.count);
|
this.count = Number(n.count);
|
||||||
var node = this;
|
var node = this;
|
||||||
var a = [];
|
var a = [];
|
||||||
var tot = 0;
|
var tot = 0;
|
||||||
var pop = 0;
|
var pop = 0;
|
||||||
var old = null;
|
var old = null;
|
||||||
|
|
||||||
this.on('input', function (msg) {
|
this.on('input', function (msg) {
|
||||||
var n = Number(msg.payload);
|
var n = Number(msg.payload);
|
||||||
if (!isNaN(n)) {
|
if (!isNaN(n)) {
|
||||||
if ((node.action === "low") || (node.action === "high")) {
|
if ((node.action === "low") || (node.action === "high")) {
|
||||||
if (old == null) { old = n; }
|
if (old == null) { old = n; }
|
||||||
old = old + (n - old) / node.count;
|
old = old + (n - old) / node.count;
|
||||||
if (node.action === "low") { msg.payload = old; }
|
if (node.action === "low") { msg.payload = old; }
|
||||||
else { msg.payload = n - old; }
|
else { msg.payload = n - old; }
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
a.push(n);
|
||||||
|
if (a.length > node.count) { pop = a.shift(); }
|
||||||
|
if (node.action === "max") {
|
||||||
|
msg.payload = Math.max.apply(Math, a);
|
||||||
|
}
|
||||||
|
if (node.action === "min") {
|
||||||
|
msg.payload = Math.min.apply(Math, a);
|
||||||
|
}
|
||||||
|
if (node.action === "mean") {
|
||||||
|
tot = tot + n - pop;
|
||||||
|
msg.payload = tot / a.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (node.round) { msg.payload = Math.round(msg.payload); }
|
||||||
|
node.send(msg);
|
||||||
}
|
}
|
||||||
else {
|
else { node.log("Not a number: "+msg.payload); }
|
||||||
a.push(n);
|
});
|
||||||
if (a.length > node.count) { pop = a.shift(); }
|
}
|
||||||
if (node.action === "max") {
|
RED.nodes.registerType("smooth", SmoothNode);
|
||||||
msg.payload = Math.max.apply(Math, a);
|
|
||||||
}
|
|
||||||
if (node.action === "min") {
|
|
||||||
msg.payload = Math.min.apply(Math, a);
|
|
||||||
}
|
|
||||||
if (node.action === "mean") {
|
|
||||||
tot = tot + n - pop;
|
|
||||||
msg.payload = tot / a.length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (node.round) { msg.payload = Math.round(msg.payload); }
|
|
||||||
node.send(msg);
|
|
||||||
}
|
|
||||||
else { node.log("Not a number: "+msg.payload); }
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("smooth", SmoothNode);
|
|
||||||
|
@ -41,9 +41,6 @@ module.exports = function(RED) {
|
|||||||
// GPIO pins 11 (R), 13 (G), 15 (B).
|
// GPIO pins 11 (R), 13 (G), 15 (B).
|
||||||
|
|
||||||
function LedBorgNode(n) {
|
function LedBorgNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
|
||||||
var node = this;
|
|
||||||
|
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.pin = n.pin;
|
this.pin = n.pin;
|
||||||
this.set = n.set || false;
|
this.set = n.set || false;
|
||||||
@ -69,10 +66,10 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
else if (p3.test(msg.payload)) {
|
else if (p3.test(msg.payload)) {
|
||||||
var c = msg.payload.split(",");
|
var c = msg.payload.split(",");
|
||||||
var r = Math.floor(parseInt(c[0])*100/256).toString();
|
var r1 = Math.floor(parseInt(c[0])*100/256).toString();
|
||||||
var g = Math.floor(parseInt(c[1])*100/256).toString();
|
var g1 = Math.floor(parseInt(c[1])*100/256).toString();
|
||||||
var b = Math.floor(parseInt(c[2])*100/256).toString();
|
var b1 = Math.floor(parseInt(c[2])*100/256).toString();
|
||||||
rgb = r+","+g+","+b;
|
rgb = r1+","+g1+","+b1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// you can add fancy colours by name here if you want...
|
// you can add fancy colours by name here if you want...
|
||||||
|
@ -23,9 +23,9 @@ module.exports = function(RED) {
|
|||||||
var pre = "\\\\.\\";
|
var pre = "\\\\.\\";
|
||||||
|
|
||||||
if (!plat.match(/^win/)) {
|
if (!plat.match(/^win/)) {
|
||||||
|
pre = "";
|
||||||
throw "Info : only needed for Windows boxes without serialport npm module installed.";
|
throw "Info : only needed for Windows boxes without serialport npm module installed.";
|
||||||
//util.log("[26-rawserial.js] Info : only really needed for Windows boxes without serialport npm module installed.");
|
//util.log("[26-rawserial.js] Info : only really needed for Windows boxes without serialport npm module installed.");
|
||||||
pre = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function RawSerialInNode(n) {
|
function RawSerialInNode(n) {
|
||||||
|
@ -35,10 +35,10 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var l = JSON.stringify(msg.payload).length;
|
var le = JSON.stringify(msg.payload).length;
|
||||||
msg.payload = msgpack.encode(msg.payload);
|
msg.payload = msgpack.encode(msg.payload);
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
node.status({text:l +" o->b "+ msg.payload.length});
|
node.status({text:le +" o->b "+ msg.payload.length});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,8 @@ var exifNode = require("../../../utility/exif/94-exif.js");
|
|||||||
var helper = require('../../../../node-red/test/nodes/helper.js');
|
var helper = require('../../../../node-red/test/nodes/helper.js');
|
||||||
|
|
||||||
describe('exif node', function() {
|
describe('exif node', function() {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
helper.startServer(done);
|
helper.startServer(done);
|
||||||
});
|
});
|
||||||
@ -34,43 +35,43 @@ describe('exif node', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('extracts location data from Exif data of JPEG', function(done) {
|
it('extracts location data from Exif data of JPEG', function(done) {
|
||||||
|
|
||||||
var exif = require('exif');
|
var exif = require('exif');
|
||||||
var ExifImage = exif.ExifImage;
|
var ExifImage = exif.ExifImage;
|
||||||
|
|
||||||
// the jpg file is a single black dot but it was originally a photo taken at IBM Hursley
|
// the jpg file is a single black dot but it was originally a photo taken at IBM Hursley
|
||||||
var data = fs.readFileSync("./exif_test_image.jpg", null); // extracting genuine exif data to be fed back as the result of the stubbed ExifImage constructor
|
var data = fs.readFileSync("./exif_test_image.jpg", null); // extracting genuine exif data to be fed back as the result of the stubbed ExifImage constructor
|
||||||
|
|
||||||
var eD;
|
var eD;
|
||||||
|
|
||||||
new ExifImage({ image : data }, function (error, exifData) {
|
new ExifImage({ image : data }, function (error, exifData) {
|
||||||
if(error) {
|
if(error) {
|
||||||
done(error);
|
done(error);
|
||||||
} else {
|
} else {
|
||||||
eD = exifData;
|
eD = exifData;
|
||||||
}
|
}
|
||||||
|
|
||||||
var flow = [{id:"exifNode1", type:"exif", wires:[["helperNode1"]]},
|
var flow = [{id:"exifNode1", type:"exif", wires:[["helperNode1"]]},
|
||||||
{id:"helperNode1", type:"helper"}];
|
{id:"helperNode1", type:"helper"}];
|
||||||
|
|
||||||
helper.load(exifNode, flow, function() {
|
helper.load(exifNode, flow, function() {
|
||||||
var exifNode1 = helper.getNode("exifNode1");
|
var exifNode1 = helper.getNode("exifNode1");
|
||||||
var helperNode1 = helper.getNode("helperNode1");
|
var helperNode1 = helper.getNode("helperNode1");
|
||||||
|
|
||||||
helperNode1.on("input", function(msg) {
|
helperNode1.on("input", function(msg) {
|
||||||
msg.location.lat.should.equal(50.95624); // this data is stored in the jpg file
|
msg.location.lat.should.equal(50.95624); // this data is stored in the jpg file
|
||||||
msg.location.lon.should.equal(-1.36701);
|
msg.location.lon.should.equal(-1.36701);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
var stub = sinon.stub(ExifImage.prototype, 'loadImage', function(error, callback) {
|
var stub = sinon.stub(ExifImage.prototype, 'loadImage', function(error, callback) {
|
||||||
stub.restore();
|
stub.restore();
|
||||||
callback(null, eD);
|
callback(null, eD);
|
||||||
});
|
});
|
||||||
|
|
||||||
exifNode1.receive({payload:data});
|
exifNode1.receive({payload:data});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -15,7 +15,8 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
module.exports = function(grunt) {
|
module.exports = function(grunt) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
// Project configuration.
|
// Project configuration.
|
||||||
grunt.initConfig({
|
grunt.initConfig({
|
||||||
simplemocha: {
|
simplemocha: {
|
||||||
@ -51,7 +52,5 @@ module.exports = function(grunt) {
|
|||||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||||
grunt.loadNpmTasks('grunt-lint-inline');
|
grunt.loadNpmTasks('grunt-lint-inline');
|
||||||
|
|
||||||
grunt.registerTask('default',
|
grunt.registerTask('default', ['jshint:all', 'simplemocha:all']);
|
||||||
['jshint:all', 'simplemocha:all']);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user