From ff64d02589d4587943a571251d3cc8e08537cc4c Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Mon, 24 Feb 2014 17:05:26 +0000 Subject: [PATCH 01/13] Spi can receive options. Removing sleep dependencies. --- example.js | 9 --------- lib/Animations.js | 51 ----------------------------------------------- lib/LPD8806.js | 19 +++++++++--------- package.json | 1 - server.js | 14 ------------- 5 files changed, 9 insertions(+), 85 deletions(-) delete mode 100644 example.js delete mode 100644 lib/Animations.js delete mode 100644 server.js diff --git a/example.js b/example.js deleted file mode 100644 index 5775dd6..0000000 --- a/example.js +++ /dev/null @@ -1,9 +0,0 @@ -var LPD8806 = require('./lib/LPD8806'), - Animations = require('./lib/Animations') - -LPD8806 = new LPD8806(32, '/dev/spidev0.0'); -Animations = new Animations(32); - -Animations.Colors(LPD8806, 0.01); -Animations.Rainbow(LPD8806); -LPD8806.allOFF(); \ No newline at end of file diff --git a/lib/Animations.js b/lib/Animations.js deleted file mode 100644 index a7ae987..0000000 --- a/lib/Animations.js +++ /dev/null @@ -1,51 +0,0 @@ -var Color = require("color"), - sleep = require('sleep'); - -var ledCount = 32; - _step = 0, - start = 0; - -var Animations = function(leds){ - ledCount = leds || ledCount; -} - -Animations.prototype.Colors = function(LPD8806, step){ - var colors = [ - {r:255,g:0,b:0}, - {r:0,g:255,b:0}, - {r:0,g:0,b:255} - ]; - - for(var i =0; i < 4; i++){ - var level = 0.01, - dir = step; - while(level >= 0.0){ - LPD8806.setMasterBrightness(level); - LPD8806.fill(new Color(colors[i])); - if(level >= 0.99){ - dir =- step; - } - level += dir; - sleep.usleep(10000); - } - } -} - -Animations.prototype.Rainbow = function(LPD8806){ - for(var i = 0; i < 384; i++){ - var amt = 1; - for(var p = 0; p < ledCount; p++){ - var color = (p + _step) % 384; - LPD8806.setPixel(start + p, LPD8806.wheel_color(color)); - } - LPD8806.update(); - sleep.usleep(20000); - _step += amt; - var overflow = _step - 384; - if(overflow >= 0){ - _step = overflow; - } - } -} - -module.exports = Animations; \ No newline at end of file diff --git a/lib/LPD8806.js b/lib/LPD8806.js index 93872c4..3640bae 100644 --- a/lib/LPD8806.js +++ b/lib/LPD8806.js @@ -13,16 +13,15 @@ var ledCount = 32, c_order = ChannelOrder.GRB, masterBrightness = 1.0, buffer = [], - gamma = new Buffer(256), - spi = new SPI.Spi(device, { - 'mode': SPI.MODE.MODE_0, - 'chipSelect': SPI.CS.none, - 'maxSpeed': 20000000 - }, function(s){ - s.open(); - }); + gamma = new Buffer(256); + + +var LPD8806 = function(leds, dev, options){ + options = options || {}; -var LPD8806 = function(leds, dev){ + this.spi = new SPI.Spi(device, options, function(s){ + s.open(); + }); ledCount = leds || ledCount; device = dev || device; @@ -77,7 +76,7 @@ LPD8806.prototype.update = function(){ var _buffer = buffer.slice(0, buffer.length); _buffer.push(new Buffer([0x00, 0x00, 0x00])); _buffer.push(new Buffer([0x00])); - spi.write(Buffer.concat(_buffer)); + this.spi.write(Buffer.concat(_buffer)); }; diff --git a/package.json b/package.json index 57dd41e..f1171f3 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,6 @@ "dependencies": { "spi": "*", "color": "*", - "sleep": "*", "socket.io": "*" }, "description": "LPD8806 Node library for the Raspberry Pi", diff --git a/server.js b/server.js deleted file mode 100644 index c84e25c..0000000 --- a/server.js +++ /dev/null @@ -1,14 +0,0 @@ -var io = require('socket.io').listen(80); -var LPD8806 = require('LPD8806'), - Color = require('color'); - -LPD8806 = new LPD8806(); - -io.sockets.on('connection', function (socket) { - socket.on('setColor', function (data) { - LPD8806.fill(new Color({r: data.red, g: data.green, b: data.blue})); - }); - socket.on('setBrightness', function (data) { - LPD8806.updateBrightness(parseFloat(data.brightness)); - }); -}); \ No newline at end of file From 416891c4dccb310de510c4c1ed0d5e19386dad80 Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Mon, 24 Feb 2014 17:14:34 +0000 Subject: [PATCH 02/13] Updating readme. Removing unecessary extra packages. --- README.md | 18 +++++++++++------- package.json | 3 +-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 837c2f0..29e565e 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,31 @@ LPD8806-node ============ -Install. +- Removed synchronous lib sleep +- Asynchronous examples +- Spi accepts options - npm install lpd8806 +Forked to be able to work with Intel galileo +Check /examples for usage examples. + + + npm install git://github.com/v0od0oChild/LPD8806-node.git var LPD8806 = require('LPD8806'); - LPD8806 = new LPD8806(32, '/dev/spidev0.0'); - LPD8806.fillRGB(0, 0, 255); + LPD8806 = new LPD8806(32, '/dev/spidev1.0'); Available Funtions: LPD8806.updateBrightness(0.5); //Value must Between 0.0 and 1.0 LPD8806.update(); //To write the new Buffer - LPD8806.fillRGB(0, 0, 255); //ROT, GREEN, BLUE + LPD8806.fillRGB(0, 0, 255); //RED, GREEN, BLUE LPD8806.fillHSV(0.0, 100.0, 100.0); //HSV Values LPD8806.allOFF(); LPD8806.setPixel(new Color({r: 0, g: 0: b: 255})); - LPD8806.setPixelRGB(0, 0, 255); //ROT, GREEN, BLUE + LPD8806.setPixelRGB(0, 0, 255); //RED, GREEN, BLUE LPD8806.setPixelHSV(0.0, 100.0, 100.0) //HSV Values LPD8806.setPixelOff(pixelNumber); - The MIT License (MIT) Copyright (c) 2014 Pascal M. diff --git a/package.json b/package.json index f1171f3..42313bc 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,7 @@ }, "dependencies": { "spi": "*", - "color": "*", - "socket.io": "*" + "color": "*" }, "description": "LPD8806 Node library for the Raspberry Pi", "main": "./lib/LPD8806", From e20f4e05e5352f80621aec2b535a10b479a23393 Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Mon, 24 Feb 2014 17:21:41 +0000 Subject: [PATCH 03/13] Added asynchronous rainbow example --- examples/rainbow.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 examples/rainbow.js diff --git a/examples/rainbow.js b/examples/rainbow.js new file mode 100644 index 0000000..9b24ef0 --- /dev/null +++ b/examples/rainbow.js @@ -0,0 +1,37 @@ +var LPD8806 = require('LPD8806'); + +var leds = new LPD8806(96, '/dev/spidev1.0'); + +/** process.nextTick to avoid blocking it all the time */ +function rainbow(brightness){ + + var ledCount = config.ledStripe.ledsNum; + var _step = 0; + var start = 0; + + brightness = brightness || 1.0; + leds.setMasterBrightness(brightness); + var i = 0; + + function performStep() { + var amt = 1; + for(var p = 0; p < ledCount; p++){ + var color = (p + _step) % 384; + leds.setPixel(start + p, leds.wheel_color(color)); + } + leds.update(); + _step += amt; + var overflow = _step - 384; + if(overflow >= 0){ + _step = overflow; + } + + if (++i >= 384) { + i = 0; + } + setTimeout(performStep, 80); + } + performStep(); +} + +rainbow(); \ No newline at end of file From 33fc9fb0698eb21ae714f8f96f9cd76c64d27038 Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Mon, 24 Feb 2014 17:35:23 +0000 Subject: [PATCH 04/13] Added flash and fade effects. Fixed rainbow return. --- examples/flash.js | 42 ++++++++++++++++++++++++++++++++++++++++++ examples/rainbow.js | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 examples/flash.js diff --git a/examples/flash.js b/examples/flash.js new file mode 100644 index 0000000..4f3b98e --- /dev/null +++ b/examples/flash.js @@ -0,0 +1,42 @@ +var LPD8806 = require('LPD8806'); + +// npm install async +var async = require("async"); + + +// Flash ledstrip by manipulation of the color brightness +function flash(r, g, b, speed){ + var i = 0; + var step = speed; + + function performStep(){ + var level = 0.01, + dir = step; + + async.whilst(function(){ + return (level >= 0.0); + },function (callback) { + setTimeout(function(){ + leds.setMasterBrightness(level); + leds.fillRGB(r,g,b); + if(level >= 0.99){ + dir =- step; + } + level += dir; + callback(); + },4); + }, function (err) { + return; + }); + } + performStep(); +} + + +// Fade color +flash(130,16,233, 0.01); + +// Flash color +setTimeout(function(){ + flash(130,16,233, 0.09); +}, 20000); \ No newline at end of file diff --git a/examples/rainbow.js b/examples/rainbow.js index 9b24ef0..9f17e9b 100644 --- a/examples/rainbow.js +++ b/examples/rainbow.js @@ -27,7 +27,7 @@ function rainbow(brightness){ } if (++i >= 384) { - i = 0; + return; } setTimeout(performStep, 80); } From 0da090c4ad596a7b02375a31f5431aada1806e14 Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Mon, 24 Feb 2014 17:36:15 +0000 Subject: [PATCH 05/13] Initializing LPD lib --- examples/flash.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/flash.js b/examples/flash.js index 4f3b98e..6244442 100644 --- a/examples/flash.js +++ b/examples/flash.js @@ -3,6 +3,7 @@ var LPD8806 = require('LPD8806'); // npm install async var async = require("async"); +var leds = new LPD8806(96, '/dev/spidev1.0'); // Flash ledstrip by manipulation of the color brightness function flash(r, g, b, speed){ From 2e7b5c1ff295faf5268cf8e0011b90ef1aed86cc Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Mon, 24 Feb 2014 17:38:58 +0000 Subject: [PATCH 06/13] Updated simple usage --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 29e565e..cfb58eb 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,18 @@ LPD8806-node - Spi accepts options Forked to be able to work with Intel galileo + Check /examples for usage examples. npm install git://github.com/v0od0oChild/LPD8806-node.git var LPD8806 = require('LPD8806'); - LPD8806 = new LPD8806(32, '/dev/spidev1.0'); + var ledstrip = new LPD8806(32, '/dev/spidev1.0'); + + ledstrip.fillRGB(200,200,200); + + Available Funtions: From 06c7c3ec640fa68aa10b61f5d4fd0fa98499f32c Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Tue, 25 Feb 2014 10:59:02 +0000 Subject: [PATCH 07/13] Updated aynchronous rainbow example --- examples/rainbow.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/rainbow.js b/examples/rainbow.js index 9f17e9b..0aa62dd 100644 --- a/examples/rainbow.js +++ b/examples/rainbow.js @@ -1,11 +1,10 @@ var LPD8806 = require('LPD8806'); - -var leds = new LPD8806(96, '/dev/spidev1.0'); +var ledCount = 96; +var leds = new LPD8806(ledCount, '/dev/spidev1.0'); /** process.nextTick to avoid blocking it all the time */ function rainbow(brightness){ - var ledCount = config.ledStripe.ledsNum; var _step = 0; var start = 0; @@ -34,4 +33,4 @@ function rainbow(brightness){ performStep(); } -rainbow(); \ No newline at end of file +rainbow(0.8); \ No newline at end of file From 882f8179b3e534894b673086a58080e9fc549298 Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Tue, 25 Feb 2014 11:02:19 +0000 Subject: [PATCH 08/13] Updated readme --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index cfb58eb..1a178b3 100644 --- a/README.md +++ b/README.md @@ -21,15 +21,15 @@ Check /examples for usage examples. Available Funtions: - LPD8806.updateBrightness(0.5); //Value must Between 0.0 and 1.0 - LPD8806.update(); //To write the new Buffer - LPD8806.fillRGB(0, 0, 255); //RED, GREEN, BLUE - LPD8806.fillHSV(0.0, 100.0, 100.0); //HSV Values - LPD8806.allOFF(); - LPD8806.setPixel(new Color({r: 0, g: 0: b: 255})); - LPD8806.setPixelRGB(0, 0, 255); //RED, GREEN, BLUE - LPD8806.setPixelHSV(0.0, 100.0, 100.0) //HSV Values - LPD8806.setPixelOff(pixelNumber); + ledstrip.updateBrightness(0.5); //Value must Between 0.0 and 1.0 + ledstrip.update(); //To write the new Buffer + ledstrip.fillRGB(0, 0, 255); //RED, GREEN, BLUE + ledstrip.fillHSV(0.0, 100.0, 100.0); //HSV Values + ledstrip.allOFF(); + ledstrip.setPixel(new Color({r: 0, g: 0: b: 255})); + ledstrip.setPixelRGB(0, 0, 255); //RED, GREEN, BLUE + ledstrip.setPixelHSV(0.0, 100.0, 100.0) //HSV Values + ledstrip.setPixelOff(pixelNumber); The MIT License (MIT) From 322b638e2446f58a3dfadfc6517caff25e9dc4ce Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Wed, 9 Apr 2014 17:12:33 +0100 Subject: [PATCH 09/13] Fixing led count number, spi device params --- lib/LPD8806.js | 7 +++---- package.json | 5 +---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/LPD8806.js b/lib/LPD8806.js index 3640bae..05c97db 100644 --- a/lib/LPD8806.js +++ b/lib/LPD8806.js @@ -18,14 +18,13 @@ var ledCount = 32, var LPD8806 = function(leds, dev, options){ options = options || {}; + ledCount = leds || ledCount; + device = dev || device; this.spi = new SPI.Spi(device, options, function(s){ s.open(); }); - ledCount = leds || ledCount; - device = dev || device; - for(var i = 0; i < ledCount; i++){ buffer[i] = new Buffer([0x80, 0x80, 0x80]); } @@ -157,4 +156,4 @@ LPD8806.prototype.wheel_color = function(wheelpos){ return new Color({r: r, g: g, b: b}); }; -module.exports = LPD8806; \ No newline at end of file +module.exports = LPD8806; diff --git a/package.json b/package.json index 42313bc..e305933 100644 --- a/package.json +++ b/package.json @@ -2,14 +2,11 @@ "name": "lpd8806", "version": "0.2.0", "private": false, - "scripts": { - "start": "node example.js" - }, "dependencies": { "spi": "*", "color": "*" }, - "description": "LPD8806 Node library for the Raspberry Pi", + "description": "LPD8806 NodeJS general library", "main": "./lib/LPD8806", "devDependencies": {}, "repository": { From 4d3d1ae9fd90e7642c6de9de27e88c1dca2db76a Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Fri, 20 Jun 2014 10:29:51 +0100 Subject: [PATCH 10/13] Added credits --- README.md | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 1a178b3..432380e 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,17 @@ LPD8806-node ============ -- Removed synchronous lib sleep -- Asynchronous examples -- Spi accepts options - -Forked to be able to work with Intel galileo - -Check /examples for usage examples. - - - npm install git://github.com/v0od0oChild/LPD8806-node.git +Asyncronous lib that implements the LPD8806 protocol. +``` var LPD8806 = require('LPD8806'); var ledstrip = new LPD8806(32, '/dev/spidev1.0'); ledstrip.fillRGB(200,200,200); + //Available Funtions: - - Available Funtions: - - ledstrip.updateBrightness(0.5); //Value must Between 0.0 and 1.0 + ledstrip.updateBrightness(0.5); //Value must be between 0.0 and 1.0 ledstrip.update(); //To write the new Buffer ledstrip.fillRGB(0, 0, 255); //RED, GREEN, BLUE ledstrip.fillHSV(0.0, 100.0, 100.0); //HSV Values @@ -30,6 +20,15 @@ Check /examples for usage examples. ledstrip.setPixelRGB(0, 0, 255); //RED, GREEN, BLUE ledstrip.setPixelHSV(0.0, 100.0, 100.0) //HSV Values ledstrip.setPixelOff(pixelNumber); +``` + +Check /examples for usage examples. +Feel free to contribute. + + +Special thanks to [pmdroid](https://github.com/pmdroid) + + The MIT License (MIT) From 9c570d623b50e973071d8519e0315bef1f7ba9df Mon Sep 17 00:00:00 2001 From: tiagoalves Date: Fri, 20 Jun 2014 11:10:10 +0100 Subject: [PATCH 11/13] Updated info so it can be published to npm. --- README.md | 13 +++++++++---- package.json | 8 ++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 432380e..b298f24 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,15 @@ -LPD8806-node -============ +# lpd8806-async -Asyncronous lib that implements the LPD8806 protocol. +Asyncronous Node.js library that implements the LPD8806 protocol. + +## Install + + npm install lpd8806-async + +## Run ``` - var LPD8806 = require('LPD8806'); + var LPD8806 = require('lpd8806-async'); var ledstrip = new LPD8806(32, '/dev/spidev1.0'); ledstrip.fillRGB(200,200,200); diff --git a/package.json b/package.json index e305933..b5e73f7 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { - "name": "lpd8806", - "version": "0.2.0", + "name": "lpd8806-async", + "version": "0.2.1", "private": false, "dependencies": { "spi": "*", "color": "*" }, - "description": "LPD8806 NodeJS general library", + "description": "Non-blocking LPD8806 NodeJS general library", "main": "./lib/LPD8806", "devDependencies": {}, "repository": { @@ -23,7 +23,7 @@ "Raspberry", "PI" ], - "author": "pmdroid", + "author": "pmdroid, v0od0oChild", "license": "MIT License", "bugs": { "url": "https://github.com/pmdroid/LPD8806-node/issues" From f577f880f91716efafd8b0168ca44f8c6d4c1053 Mon Sep 17 00:00:00 2001 From: tiagoalves Date: Fri, 20 Jun 2014 11:12:10 +0100 Subject: [PATCH 12/13] Typo correction. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b298f24..c5e83a4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # lpd8806-async -Asyncronous Node.js library that implements the LPD8806 protocol. +Asynchronous Node.js library that implements the LPD8806 protocol. ## Install From 19e0dd4b95506d8c0a394bded32d2f971282248c Mon Sep 17 00:00:00 2001 From: tiagoalves Date: Fri, 20 Jun 2014 11:55:46 +0100 Subject: [PATCH 13/13] Fixed repo and site URLs in package.json. --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b5e73f7..75c1028 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lpd8806-async", - "version": "0.2.1", + "version": "0.2.2", "private": false, "dependencies": { "spi": "*", @@ -11,7 +11,7 @@ "devDependencies": {}, "repository": { "type": "git", - "url": "https://github.com/pmdroid/LPD8806-node" + "url": "https://github.com/muzzley/LPD8806-node" }, "keywords": [ "SPI", @@ -26,6 +26,6 @@ "author": "pmdroid, v0od0oChild", "license": "MIT License", "bugs": { - "url": "https://github.com/pmdroid/LPD8806-node/issues" + "url": "https://github.com/muzzley/LPD8806-node/issues" } }