fixes for noe-pixel to check more thoroughly for new libs

while supporting old ones also.
This commit is contained in:
Dave Conway-Jones 2017-09-01 15:22:35 +01:00
parent 39fd3b85cd
commit e376802ff4
No known key found for this signature in database
GPG Key ID: 81B04231572A9A2D
7 changed files with 40 additions and 20 deletions

View File

@ -16,10 +16,25 @@ LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
LED_DMA = 5 # DMA channel to use for generating signal (try 5)
LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
LED_CHANNEL = 0 # PWM channel
LED_GAMMA = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5,
6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11,
11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18,
19, 19, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, 27, 27, 28,
29, 29, 30, 31, 31, 32, 33, 34, 34, 35, 36, 37, 37, 38, 39, 40,
40, 41, 42, 43, 44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 76, 77, 78, 79, 80, 81, 83, 84, 85, 86, 88, 89,
90, 91, 93, 94, 95, 96, 98, 99,100,102,103,104,106,107,109,110,
111,113,114,116,117,119,120,121,123,124,126,128,129,131,132,134,
135,137,138,140,142,143,145,146,148,150,151,153,155,157,158,160,
162,163,165,167,169,170,172,174,176,178,179,181,183,185,187,189,
191,193,194,196,198,200,202,204,206,208,210,212,214,216,218,220,
222,224,227,229,231,233,235,237,239,241,244,246,248,250,252,255]
if sys.version_info >= (3,0):
print("Sorry - currently only configured to work with python 2.x")
sys.exit(1)
LED_COUNT = int(sys.argv[1])
WAIT_MS = int(sys.argv[2])
@ -107,8 +122,12 @@ def rainbowCycle(strip, wait_ms=20, iterations=2):
# Main loop:
if __name__ == '__main__':
# Create NeoPixel object with appropriate configuration.
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS)
# Intialize the library (must be called once before other functions).
#strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS)
if __version__ == "legacy":
strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
else:
strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL, LED_GAMMA)# Intialize the library (must be called once before other functions).
strip.begin()
## Color wipe animations.

View File

@ -2,9 +2,9 @@
module.exports = function(RED) {
"use strict";
var spawn = require('child_process').spawn;
var execSync = require('child_process').execSync;
var fs = require('fs');
var colors = require('./colours.js');
var piCommand = __dirname+'/neopix';
try {
@ -15,9 +15,9 @@ module.exports = function(RED) {
throw "Info : "+RED._("rpi-gpio.errors.ignorenode");
}
if (!fs.existsSync('/usr/local/lib/python2.7/dist-packages/neopixel/')) {
RED.log.warn("Can't find neopixel.py python library");
throw "Warning : Can't find neopixel.py python library";
if (execSync('python -c "import neopixel"').toString() !== "") {
RED.log.warn("Can't find neopixel python library");
throw "Warning : Can't find neopixel python library";
}
if ( !(1 & parseInt ((fs.statSync(piCommand).mode & parseInt ("777", 8)).toString (8)[0]) )) {

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-pi-neopixel",
"version" : "0.0.15",
"version" : "0.0.16",
"description" : "A Node-RED node to output to a neopixel (ws2812) string of LEDS from a Raspberry Pi.",
"dependencies" : {
},

View File

@ -1,13 +1,13 @@
#!/usr/bin/env node
var fs = require('fs');
if (!fs.existsSync('/usr/local/lib/python2.7/dist-packages/neopixel/')) {
console.warn("WARNING : Can't find neopixel.py python library");
if (!fs.existsSync('/usr/local/lib/python2.7/dist-packages/unicornhat.py')) {
console.warn("WARNING : Can't find required python library");
console.warn("WARNING : Please install using the following command");
console.warn("WARNING : Note: this uses root...");
console.warn("WARNING : curl -sS get.pimoroni.com/unicornhat | bash\n");
//process.exit(1);
}
else {
console.log("Neopixel Python library found OK.\n")
console.log("Python library found OK.\n")
}

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-pi-unicorn-hat",
"version" : "0.0.15",
"version" : "0.0.16",
"description" : "A Node-RED node to output to a Raspberry Pi Unicorn HAT from Pimorini.",
"dependencies" : {
"pngjs": "2.2.*"

View File

@ -1,13 +1,13 @@
#!/usr/bin/env node
var fs = require('fs');
if (!fs.existsSync('/usr/local/lib/python2.7/dist-packages/neopixel')) {
console.warn("WARNING : Can't find unicorn.py python library");
if (!fs.existsSync('/usr/local/lib/python2.7/dist-packages/unicornhat.py')) {
console.warn("WARNING : Can't find required python library");
console.warn("WARNING : Please install using the following command");
console.warn("WARNING : Note: this uses root...");
console.warn("WARNING : curl -sS get.pimoroni.com/unicornhat | bash\n");
//process.exit(1);
}
else {
console.log("Unicorn Hat Python library found OK.\n")
console.log("Python library found OK.\n")
}

View File

@ -4,6 +4,7 @@ module.exports = function(RED) {
var fs = require('fs');
var PNG = require('pngjs').PNG;
var spawn = require('child_process').spawn;
var execSync = require('child_process').execSync;
var hatCommand = __dirname+'/unihat';
@ -12,9 +13,9 @@ module.exports = function(RED) {
throw "Info : "+RED._("rpi-gpio.errors.ignorenode");
}
if (!fs.existsSync('/usr/local/lib/python2.7/dist-packages/neopixel')) {
RED.log.warn("Can't find Unicorn HAT python libraries");
throw "Warning : Can't find Unicorn HAT python libraries";
if (execSync('python -c "import neopixel"').toString() !== "") {
RED.log.warn("Can't find neopixel python library");
throw "Warning : Can't find neopixel python library";
}
if ( !(1 & parseInt ((fs.statSync(hatCommand).mode & parseInt ("777", 8)).toString (8)[0]) )) {