Skip to content

Commit

Permalink
Pin specify and colour order. Fixes #47 Closes #28
Browse files Browse the repository at this point in the history
  • Loading branch information
ajfisher committed Dec 2, 2015
1 parent 27e4ca8 commit bd0cf35
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions firmware/src/libs/ws2812/ws2812.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void process_command(byte argc, byte *argv){
// TODO make this work with the strand length...

// get the bottom 5 bits off for the pin value
uint8_t pin = (uint8_t)argv[1] & 0x31;
uint8_t pin = (uint8_t)argv[1] & 0x1F;
// get the top two bits for the colour order type.
uint8_t colour_type = (uint8_t)argv[1]>>5;
switch (colour_type) {
Expand All @@ -110,7 +110,7 @@ void process_command(byte argc, byte *argv){
}

strip_0.updateLength(8);
//strip_0.setOutput(pin);
strip_0.setOutput(pin);

break;
}
Expand Down
18 changes: 13 additions & 5 deletions lib/pixel.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ PIXEL_SET_STRIP = 0x04,
PIXEL_CONFIG_FIRMATA = 0x05,
PIXEL_CONFIG_BACKPACK = 0x06;


var PIN_DEFAULT = 6; // use this if not supplied

var I2C_DEFAULT = 0x42;
Expand All @@ -54,7 +55,7 @@ var Controllers = {
var strip_length = opts.length || 6; // just an arbitrary val
var data_pin = opts.data || DEFAULT_PIN;
var firmata = opts.firmata || opts.board.io;
var colour_order = opts.colour_order || 0x0; // default GRB
var colour_order = opts.colour_order || COLOUR_TYPE.GRB; // default GRB
var id = opts.strip_id || 0; // which strip are you talking to.

if (firmata == undefined) {
Expand Down Expand Up @@ -93,13 +94,11 @@ var Controllers = {
// now send the config message with length and data point.
var data = [];

colour_order = 2;
data[0] = START_SYSEX;
data[1] = PIXEL_COMMAND;
//data[2] = PIXEL_CONFIG_FIRMATA;
data[2] = PIXEL_CONFIG;
data[3] = (colour_order << 5) | data_pin;
console.log("Data pin: %s", data_pin);
data[4] = strip_length & FIRMATA_7BIT_MASK;
data[5] = (strip_length >> 7) & FIRMATA_7BIT_MASK;
data[6] = END_SYSEX;
Expand Down Expand Up @@ -419,7 +418,7 @@ Pixel.prototype.colour = Pixel.prototype.color = function(color, opts) {
if (options.sendmsg != undefined) { sendmsg = options.sendmsg; }

var pixelcolor = null;

if (color) {
// get the color based on a string
if(typeof(color) === "object") {
Expand Down Expand Up @@ -453,4 +452,13 @@ Pixel.prototype.colour = Pixel.prototype.color = function(color, opts) {
}
};

module.exports = { Strip: Strip};
var COLOUR_TYPE = {
GRB: 0x00,
RGB: 0x01,
BRG: 0x02,
};

module.exports = {
Strip: Strip,
COLOUR_TYPE: COLOUR_TYPE,
};

0 comments on commit bd0cf35

Please sign in to comment.