Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/flash.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var LPD8806 = require('LPD8806');
var LPD8806 = require('../lib/LPD8806');

// npm install async
var async = require("async");

var leds = new LPD8806(96, '/dev/spidev1.0');
var leds = new LPD8806(96, 0, 0);

// Flash ledstrip by manipulation of the color brightness
function flash(r, g, b, speed){
Expand Down Expand Up @@ -40,4 +40,4 @@ flash(130,16,233, 0.01);
// Flash color
setTimeout(function(){
flash(130,16,233, 0.09);
}, 20000);
}, 20000);
6 changes: 3 additions & 3 deletions examples/rainbow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var LPD8806 = require('LPD8806');
var LPD8806 = require('../lib/LPD8806');
var ledCount = 96;
var leds = new LPD8806(ledCount, '/dev/spidev1.0');
var leds = new LPD8806(ledCount, 0, 0);

/** process.nextTick to avoid blocking it all the time */
function rainbow(brightness){
Expand Down Expand Up @@ -33,4 +33,4 @@ function rainbow(brightness){
performStep();
}

rainbow(0.8);
rainbow(0.8);
26 changes: 17 additions & 9 deletions lib/LPD8806.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* MIT license */

var SPI = require('spi'),
var SPI = require('spi-device'),
Color = require("color");

var ledCount = 32,
device = '/dev/spidev0.0',
spiBus = 0,
spiDevice = 0,
spiMaxSpeed = 1000000,
ChannelOrder = {
"RGB" : [0,1,2], // Probably not used, here for clarity
"GRB" : [1,0,2], // Strands from Adafruit and some others (default)
Expand All @@ -16,14 +18,13 @@ var ledCount = 32,
gamma = new Buffer(256);


var LPD8806 = function(leds, dev, options){
options = options || {};
var LPD8806 = function(leds, bus, device, options){
options = options || {'maxSpeed' : spiMaxSpeed};
ledCount = leds || ledCount;
device = dev || device;
spiBus = bus || spiBus;
spiDevice = device || spiDevice;

this.spi = new SPI.Spi(device, options, function(s){
s.open();
});
this.spi = SPI.openSync(spiBus, spiDevice, options);

for(var i = 0; i < ledCount; i++){
buffer[i] = new Buffer([0x80, 0x80, 0x80]);
Expand Down Expand Up @@ -75,7 +76,14 @@ LPD8806.prototype.update = function(){
var _buffer = buffer.slice(0, buffer.length);
_buffer.push(new Buffer([0x00, 0x00, 0x00]));
_buffer.push(new Buffer([0x00]));
this.spi.write(Buffer.concat(_buffer));
var adjustedBuffer = Buffer.concat(_buffer);

let message = [{
sendBuffer: adjustedBuffer,
byteLength: adjustedBuffer.length,
speedHz: spiMaxSpeed
}];
this.spi.transferSync(message);
};


Expand Down
79 changes: 79 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.2.2",
"private": false,
"dependencies": {
"spi": "*",
"color": "*"
"color": "*",
"spi-device": "^2.0.8"
},
"description": "Non-blocking LPD8806 NodeJS general library",
"main": "./lib/LPD8806",
Expand Down