mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
Update licenses and packages for all nodes
This commit is contained in:
@@ -1,19 +1,3 @@
|
||||
/**
|
||||
* Copyright 2013-2014 Agile Innovative Ltd.
|
||||
* Based on code written by Dave Conway-Jones, IBM Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
@@ -48,6 +32,10 @@ module.exports = function(RED) {
|
||||
return typeof (value) === "undefined" || value === null ? value = defaultValue : value;
|
||||
}
|
||||
|
||||
function validateArray(value, defaultValue){
|
||||
return typeof (value) === "undefined" || Array.isArray(value) ? value : defaultValue;
|
||||
}
|
||||
|
||||
function validatePayloadObject (obj) {
|
||||
var
|
||||
task = validate(obj.task),
|
||||
@@ -56,18 +44,21 @@ module.exports = function(RED) {
|
||||
duration = validateInt(obj.duration),
|
||||
steps = validateInt(obj.steps),
|
||||
repeat = validate(obj.repeat),
|
||||
color = validate(obj.color);
|
||||
color = validate(obj.color),
|
||||
channel = validateInt(obj.channel),
|
||||
index = validateInt(obj.index),
|
||||
row = validateArray(obj.row);
|
||||
|
||||
if (typeof(task) !== 'undefined' && availableTasks.indexOf(task) === -1) {
|
||||
return "Task is invalid";
|
||||
}
|
||||
|
||||
if (typeof(color) === 'undefined') {
|
||||
if (typeof(color) === 'undefined' && typeof(row) === 'undefined') {
|
||||
return "Color parameter is not set";
|
||||
}
|
||||
|
||||
return { 'task': task, 'delay': delay, 'repeats': repeats, 'duration': duration, 'steps': steps,
|
||||
'repeat': repeat, 'color': color };
|
||||
'repeat': repeat, 'color': color, 'channel': channel, 'index': index, 'row': row };
|
||||
}
|
||||
|
||||
function BlinkStick(n) {
|
||||
@@ -82,6 +73,9 @@ module.exports = function(RED) {
|
||||
this.duration = n.duration || 1000;
|
||||
this.steps = n.steps || 50;
|
||||
this.repeat = n.repeat;
|
||||
this.channel = 0;
|
||||
this.index = 0;
|
||||
this.row = [];
|
||||
this.closing = false;
|
||||
this.color = '';
|
||||
this.previousColor = '';
|
||||
@@ -164,13 +158,41 @@ module.exports = function(RED) {
|
||||
try {
|
||||
//Select animation to perform
|
||||
if (node.task == "pulse") {
|
||||
node.led.pulse(node.color, {'duration': node.duration, 'steps': node.steps }, blinkstickAnimationComplete);
|
||||
node.led.pulse(node.color, {'duration': node.duration, 'steps': node.steps, 'channel': node.channel, 'index': node.index }, blinkstickAnimationComplete);
|
||||
} else if (node.task == "morph") {
|
||||
node.led.morph(node.color, {'duration': node.duration, 'steps': node.steps }, blinkstickAnimationComplete);
|
||||
node.led.morph(node.color, {'duration': node.duration, 'steps': node.steps, 'channel': node.channel, 'index': node.index }, blinkstickAnimationComplete);
|
||||
} else if (node.task == "blink") {
|
||||
node.led.blink(node.color,{'repeats': node.repeats, 'delay': node.delay }, blinkstickAnimationComplete);
|
||||
node.led.blink(node.color,{'repeats': node.repeats, 'delay': node.delay, 'channel': node.channel, 'index': node.index }, blinkstickAnimationComplete);
|
||||
} else {
|
||||
node.led.setColor(node.color, blinkstickAnimationComplete);
|
||||
if(node.row.length > 0){
|
||||
var dat = [];
|
||||
for (var i = 0; i < node.row.length; i++) {
|
||||
if (typeof node.row[i] === "string") { // if string then assume must be colour names
|
||||
var params = node.led.interpretParameters(node.row[i]); // lookup colour code from name
|
||||
if (params) {
|
||||
dat.push(params.green);
|
||||
dat.push(params.red);
|
||||
dat.push(params.blue);
|
||||
}
|
||||
else { node.warn("invalid colour: "+node.row[i]); }
|
||||
}
|
||||
else { // otherwise lets use numbers 0-255
|
||||
dat.push(node.row[i+1]);
|
||||
dat.push(node.row[i]);
|
||||
dat.push(node.row[i+2]);
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
if ((dat.length % 3) === 0) { // by now length must be a multiple of 3
|
||||
node.led.setColors(node.channel, dat, blinkstickAnimationComplete);
|
||||
}
|
||||
else {
|
||||
node.warn("Colour array length not / 3");
|
||||
}
|
||||
}
|
||||
else {
|
||||
node.led.setColor(node.color, {'channel': node.channel, 'index': node.index}, blinkstickAnimationComplete);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.toString().indexOf("setColor") !== -1) {
|
||||
@@ -244,6 +266,9 @@ module.exports = function(RED) {
|
||||
node.steps = data.steps ? data.steps : node.steps;
|
||||
node.repeat = data.repeat ? data.repeat : node.repeat;
|
||||
node.color = data.color ? data.color : node.color;
|
||||
node.channel = typeof(data.channel) !== 'undefined' ? data.channel : node.channel;
|
||||
node.index = data.index ? data.index : node.index;
|
||||
node.row = data.row ? data.row : node.row;
|
||||
} else {
|
||||
node.error(data);
|
||||
return;
|
||||
|
Reference in New Issue
Block a user