Update blinkstick neopixel modes

This commit is contained in:
Dave Conway-Jones 2016-08-06 18:42:10 +01:00
parent 677864482e
commit 75787fa3c2
4 changed files with 24 additions and 4 deletions

View File

@ -22,6 +22,15 @@
<input type="text" id="node-input-serial" placeholder="defaults to first found" style="width:60%">
<a id="node-lookup-serial" class="btn"><i id="node-lookup-serial-icon" class="fa fa-search"></i></a>
</div>
<div class="form-row">
<label for="node-input-mode">Mode</label>
<select id="node-input-mode" style="width:125px !important">
<option value="normal">Normal</option>
<option value="inverted">Inverted</option>
<option value="neopixel">NeoPixel</option>
</select>
</div>
<div class="form-row">
<label for="node-input-task"><i class="fa fa-empire"></i> Task</label>
<select id="node-input-task" style="width:125px !important">
@ -41,7 +50,6 @@
<label for="node-input-repeats"><i class="fa fa-history"></i> Repeats</label>
<input type="text" id="node-input-repeats" placeholder="Times" style="text-align:end; width:50px !important">
</div>
<div id="duration-details" class="form-row">
<label for="node-input-duration"><i class="fa fa-clock-o"></i> Duration</label>
<input type="text" id="node-input-duration" placeholder="Duration" style="text-align:end; width:50px !important">
@ -120,6 +128,7 @@
defaults: { // defines the default editable properties of the node
name: {value:""}, // along with default values.
serial: {value:""},
mode: {value:"normal", validate:function(v) {return ((v === undefined)||v=="normal"||v=="inverted"||v=="neopixel"); }},
task: {value:"set_color", validate:function(v) {return ((v === undefined)||v=="set_color"||v=="blink"||v=="morph"||v=="pulse"); }},
delay: {value:"500", validate:function(v) {return ((v === undefined)||(/^\d+$/).test(v)); }},
repeats: {value:"1", validate:function(v) {return ((v === undefined)||(/^\d+$/).test(v)); }},
@ -138,6 +147,10 @@
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
if (!$("#node-input-mode").val()) {
$("#node-input-mode").val("normal");
}
if (!$("#node-input-task").val()) {
$("#node-input-task").val("set_color");
}

View File

@ -19,6 +19,7 @@ module.exports = function(RED) {
"use strict";
var blinkstick = require("blinkstick");
var availableModes = ["normal", "inverted", "neopixel"];
var availableTasks = ["set_color", "blink", "pulse", "morph"];
Object.size = function(obj) {
@ -74,6 +75,7 @@ module.exports = function(RED) {
this.name = n.name;
this.serial = n.serial;
this.mode = n.mode || "normal";
this.task = n.task || "set_color";
this.delay = n.delay || 500;
this.repeats = n.repeats || 1;
@ -101,6 +103,9 @@ module.exports = function(RED) {
node.error("BlinkStick with serial number " + node.serial + " not found");
} else {
node.status({fill:"green",shape:"dot",text:"connected"});
if(node.mode == "normal"){node.led.setMode(0);}
else if(node.mode == "inverted"){node.led.setMode(1);}
else if(node.mode == "neopixel"){node.led.setMode(2);}
if (callback) { callback(); }
}
});
@ -112,6 +117,9 @@ module.exports = function(RED) {
node.error("No BlinkStick found");
} else {
node.status({fill:"green",shape:"dot",text:"connected"});
if(node.mode == "normal"){node.led.setMode(0);}
else if(node.mode == "inverted"){node.led.setMode(1);}
else if(node.mode == "neopixel"){node.led.setMode(2);}
if (callback) { callback(); }
}
}
@ -196,7 +204,6 @@ module.exports = function(RED) {
// if it's an array then hopefully it's r,g,b,r,g,b or name,name,name
if (Array.isArray(msg.payload)) {
if (Object.size(node.led) !== 0) {
node.led.setMode(2); // put it into ws2812B LED mode
var dat = [];
for (var i = 0; i < msg.payload.length; i++) {
if (typeof msg.payload[i] === "string") { // if string then assume must be colour names

View File

@ -16,7 +16,7 @@ For more information see <i><a href="http://www.blinkstick.com/help/tutorials" t
You also currently need to create a file `/etc/udev/rules.d/80-blinkstick.rules` containing
SUBSYSTEMS=="usb", ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="41e5", TAG+="uaccess"
SUBSYSTEM=="usb", ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="41e5", TAG+="uaccess"
and either reload the udev rules or reboot.

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-blinkstick",
"version" : "0.1.12",
"version" : "0.1.13",
"description" : "A Node-RED node to control a Blinkstick",
"dependencies" : {
"blinkstick" : "1.1.3"