mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Add Gamma flag and Brightness control to node-red-node-pi-neopixel (#431)
This commit is contained in:
parent
025f97206f
commit
0f55fc160e
@ -36,9 +36,12 @@ LED_GAMMA = [
|
||||
222,224,227,229,231,233,235,237,239,241,244,246,248,250,252,255]
|
||||
|
||||
|
||||
LED_COUNT = int(sys.argv[1])
|
||||
WAIT_MS = int(sys.argv[2])
|
||||
LED_COUNT = max(0,int(sys.argv[1]))
|
||||
WAIT_MS = max(0,int(sys.argv[2]))
|
||||
MODE = sys.argv[3]
|
||||
LED_BRIGHTNESS = min(255,int(max(0,float(sys.argv[4])) * 255 / 100))
|
||||
if (sys.argv[5].lower() != "true"):
|
||||
LED_GAMMA = range(256)
|
||||
|
||||
def getRGBfromI(RGBint):
|
||||
blue = RGBint & 255
|
||||
@ -59,6 +62,12 @@ def setPixels(strip, s, e, color, wait_ms=30):
|
||||
strip.show()
|
||||
time.sleep(wait_ms/1000.0)
|
||||
|
||||
def setBrightness(strip, brightness, wait_ms=30):
|
||||
"""Set overall brighness"""
|
||||
strip.setBrightness(brightness)
|
||||
strip.show()
|
||||
time.sleep(wait_ms/1000.0)
|
||||
|
||||
def colorWipe(strip, color, wait_ms=30):
|
||||
"""Wipe color across display a pixel at a time."""
|
||||
for i in range(strip.numPixels()):
|
||||
@ -145,6 +154,9 @@ if __name__ == '__main__':
|
||||
try:
|
||||
data = raw_input()
|
||||
bits = data.split(',')
|
||||
if len(bits) == 2:
|
||||
if bits[0] == "brightness":
|
||||
setBrightness(strip, min(255,max(0,int(bits[1]))), WAIT_MS)
|
||||
if len(bits) == 3:
|
||||
if MODE == "shiftu":
|
||||
shiftUp(strip, Color(int(bits[0]), int(bits[1]), int(bits[2])), WAIT_MS)
|
||||
|
24
hardware/neopixel/neopixel.html
Normal file → Executable file
24
hardware/neopixel/neopixel.html
Normal file → Executable file
@ -31,6 +31,16 @@
|
||||
<option value="grb">GRB</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-brightness"><i class="fa fa-sun-o"></i> Brightness</label>
|
||||
<input type="text" id="node-input-brightness" placeholder="number" style="width:60px;"> (0-100)
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-gamma"> </label>
|
||||
<label for="node-input-gamma" style="width:70%">
|
||||
<input type="checkbox" id="node-input-gamma" style="display:inline-block; width:22px; vertical-align:baseline;"> Apply gamma correction
|
||||
</label>
|
||||
</div>
|
||||
<br/>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||
@ -53,6 +63,8 @@
|
||||
<!-- <p>The whole strip is set by <code>msg.payload</code> with a CSV string <i>r,g,b</i> -->
|
||||
<p>A range of pixels from <i>x</i> to <i>y</i> can be set by <code>msg.payload</code>
|
||||
with a CSV string <i>x,y,r,g,b</i>
|
||||
<p>By default, gamma correction is enabled but it can disabled which can be useful for working with low brightness levels</p>
|
||||
<p><code>msg.brightness</code> can be used to dynamically set brightness level</p>
|
||||
<p>The pixels data line should be connected to Pi physical pin 12 - GPIO 18. <i>Note:</i>
|
||||
this may conflict with audio playback.</p>
|
||||
<p align="right"><a href="http://flows.nodered.org/node/node-red-node-pi-neopixel#usage">More info </a></p>
|
||||
@ -69,7 +81,9 @@
|
||||
fgnd: { value:"" },
|
||||
wipe: { value:"40", required:true, validate:RED.validators.number() },
|
||||
mode: { value:"pcent" },
|
||||
rgb: { value:"rgb" }
|
||||
rgb: { value:"rgb" },
|
||||
brightness: { value:"100", required:true, validate:RED.validators.number() },
|
||||
gamma: { value: true }
|
||||
},
|
||||
inputs:1,
|
||||
outputs:0,
|
||||
@ -82,6 +96,14 @@
|
||||
return this.name?"node_label_italic":"";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
if (this.gamma === undefined) {
|
||||
this.gamma = true;
|
||||
$("#node-input-gamma").prop('checked', true);
|
||||
}
|
||||
if (this.brightness === undefined) {
|
||||
this.brighness = "100";
|
||||
$("#node-input-brightness").val("100");
|
||||
}
|
||||
var setstate = function () {
|
||||
if ($('#node-input-mode').val().indexOf("shift") !== -1) {
|
||||
$("#bgcol").hide();
|
||||
|
12
hardware/neopixel/neopixel.js
Normal file → Executable file
12
hardware/neopixel/neopixel.js
Normal file → Executable file
@ -35,8 +35,13 @@ module.exports = function(RED) {
|
||||
this.fgnd = n.fgnd || "128,128,128";
|
||||
this.mode = n.mode || "pcent";
|
||||
this.rgb = n.rgb || "rgb";
|
||||
this.gamma = n.gamma;
|
||||
if (this.gamma === undefined) { this.gamma = true; }
|
||||
this.brightness = Number(n.brightness || 100);
|
||||
this.wipe = Number(n.wipe || 40);
|
||||
if (this.wipe < 0) { this.wipe = 0; }
|
||||
if (this.brightness < 0) { this.brightness = 0; }
|
||||
if (this.brightness > 100) { this.brightness = 100; }
|
||||
var node = this;
|
||||
var needle = "255,255,255";
|
||||
//var p1 = /^\#[A-Fa-f0-9]{6}$/
|
||||
@ -45,6 +50,9 @@ module.exports = function(RED) {
|
||||
var p4 = /^[0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+$/
|
||||
|
||||
function inputlistener(msg) {
|
||||
if (msg.hasOwnProperty("brightness")) {
|
||||
node.child.stdin.write("brightness,"+msg.brightness.toString()+"\n");
|
||||
}
|
||||
if (msg.hasOwnProperty("payload")) {
|
||||
var pay = msg.payload.toString().toUpperCase();
|
||||
var parts = pay.split(",");
|
||||
@ -101,8 +109,8 @@ module.exports = function(RED) {
|
||||
else { node.warn("Invalid payload : "+pay); }
|
||||
}
|
||||
}
|
||||
|
||||
node.child = spawn(piCommand, [node.pixels, node.wipe, node.mode]);
|
||||
node.warn("GAMMA: "+node.gamma);
|
||||
node.child = spawn(piCommand, [node.pixels, node.wipe, node.mode, node.brightness, node.gamma]);
|
||||
node.status({fill:"green",shape:"dot",text:"ok"});
|
||||
|
||||
node.on("input", inputlistener);
|
||||
|
11
hardware/neopixel/package.json
Normal file → Executable file
11
hardware/neopixel/package.json
Normal file → Executable file
@ -1,15 +1,18 @@
|
||||
{
|
||||
"name": "node-red-node-pi-neopixel",
|
||||
"version" : "0.0.16",
|
||||
"version": "0.0.17",
|
||||
"description": "A Node-RED node to output to a neopixel (ws2812) string of LEDS from a Raspberry Pi.",
|
||||
"dependencies" : {
|
||||
},
|
||||
"dependencies": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/node-red/node-red-nodes/tree/master/hardware/neopixel"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [ "node-red", "ws2812", "neopixel" ],
|
||||
"keywords": [
|
||||
"node-red",
|
||||
"ws2812",
|
||||
"neopixel"
|
||||
],
|
||||
"node-red": {
|
||||
"nodes": {
|
||||
"rpi-neopixels": "neopixel.js"
|
||||
|
Loading…
Reference in New Issue
Block a user