diff --git a/hardware/neopixel/neopix.py b/hardware/neopixel/neopix.py index 7f92fefb..ed1b51fb 100755 --- a/hardware/neopixel/neopix.py +++ b/hardware/neopixel/neopix.py @@ -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) diff --git a/hardware/neopixel/neopixel.html b/hardware/neopixel/neopixel.html old mode 100644 new mode 100755 index 43492c85..794599df --- a/hardware/neopixel/neopixel.html +++ b/hardware/neopixel/neopixel.html @@ -31,6 +31,16 @@ +
A range of pixels from x to y can be set by msg.payload
with a CSV string x,y,r,g,b
+
By default, gamma correction is enabled but it can disabled which can be useful for working with low brightness levels
+msg.brightness
can be used to dynamically set brightness level
The pixels data line should be connected to Pi physical pin 12 - GPIO 18. Note: this may conflict with audio playback.
@@ -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(); diff --git a/hardware/neopixel/neopixel.js b/hardware/neopixel/neopixel.js old mode 100644 new mode 100755 index 85980bb2..7ed79365 --- a/hardware/neopixel/neopixel.js +++ b/hardware/neopixel/neopixel.js @@ -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); diff --git a/hardware/neopixel/package.json b/hardware/neopixel/package.json old mode 100644 new mode 100755 index 2f8e5e20..ae9a8475 --- a/hardware/neopixel/package.json +++ b/hardware/neopixel/package.json @@ -1,22 +1,25 @@ { - "name" : "node-red-node-pi-neopixel", - "version" : "0.0.16", - "description" : "A Node-RED node to output to a neopixel (ws2812) string of LEDS from a Raspberry Pi.", - "dependencies" : { - }, - "repository" : { - "type":"git", - "url":"https://github.com/node-red/node-red-nodes/tree/master/hardware/neopixel" + "name": "node-red-node-pi-neopixel", + "version": "0.0.17", + "description": "A Node-RED node to output to a neopixel (ws2812) string of LEDS from a Raspberry Pi.", + "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" ], - "node-red" : { - "nodes" : { + "keywords": [ + "node-red", + "ws2812", + "neopixel" + ], + "node-red": { + "nodes": { "rpi-neopixels": "neopixel.js" } }, - "scripts" : { - "postinstall" : "scripts/checklib.js" + "scripts": { + "postinstall": "scripts/checklib.js" }, "author": { "name": "Dave Conway-Jones",