Skip to content

Commit

Permalink
Led.RGB: Add BlinkM support
Browse files Browse the repository at this point in the history
Fixes #742
  • Loading branch information
scottgonzalez committed May 26, 2015
1 parent 70deced commit 1e9c148
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/led/rgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,42 @@ var Controllers = {
this.io.i2cWrite(this.address, [this.COMMANDS.LED0_ON_L + 4 * pin, on, on >> 8, off, off >> 8]);
}, this);

Object.assign(state, colors);
}
}
},
BLINKM: {
COMMANDS: {
value: {
GO_TO_RGB_COLOR_NOW: 0x6e,
STOP_SCRIPT: 0x6f
}
},
initialize: {
value: function(opts) {
this.address = opts.address || 0x09;

if (!this.board.Drivers[this.address]) {
this.io.i2cConfig();
this.board.Drivers[this.address] = {
initialized: false
};

// Stop the current script
this.board.io.i2cWrite(this.address, [this.COMMANDS.STOP_SCRIPT]);

this.board.Drivers[this.address].initialized = true;
}
}
},
write: {
writable: true,
value: function(colors) {
var state = priv.get(this);

this.board.io.i2cWrite(this.address,
[this.COMMANDS.GO_TO_RGB_COLOR_NOW, colors.red, colors.green, colors.blue]);

Object.assign(state, colors);
}
}
Expand Down
53 changes: 53 additions & 0 deletions test/led.js
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,59 @@ exports["Led.RGB - PCA9685 (I2C)"] = {
}
};

exports["Led.RGB - BlinkM (I2C)"] = {
setUp: function(done) {
this.board = newBoard();

this.ledRgb = new Led.RGB({
controller: "BlinkM",
board: this.board
});

this.i2cWrite = sinon.spy(this.board.io, "i2cWrite");

done();
},

shape: function(test) {
test.expect(rgbProtoProperties.length + rgbInstanceProperties.length);

rgbProtoProperties.forEach(function(method) {
test.equal(typeof this.ledRgb[method.name], "function");
}, this);

rgbInstanceProperties.forEach(function(property) {
test.notEqual(typeof this.ledRgb[property.name], "undefined");
}, this);

test.done();
},

write: function(test) {
test.expect(6);

// Fully off
this.ledRgb.write({ red: 0x00, green: 0x00, blue: 0x00 });
test.equal(this.i2cWrite.callCount, 1);
test.ok(this.i2cWrite.calledWith(0x09, [0x6e, 0x00, 0x00, 0x00]));
this.i2cWrite.reset();

// Fully on
this.ledRgb.write({ red: 0xff, green: 0xff, blue: 0xff });
test.equal(this.i2cWrite.callCount, 1);
test.ok(this.i2cWrite.calledWith(0x09, [0x6e, 0xff, 0xff, 0xff]));
this.i2cWrite.reset();

// Custom color
this.ledRgb.write({ red: 0xbb, green: 0xcc, blue: 0xaa });
test.equal(this.i2cWrite.callCount, 1);
test.ok(this.i2cWrite.calledWith(0x09, [0x6e, 0xbb, 0xcc, 0xaa]));
this.i2cWrite.reset();

test.done();
}
};

exports["Led - Default Pin w/ Firmata"] = {
shape: function(test) {
test.expect(8);
Expand Down

0 comments on commit 1e9c148

Please sign in to comment.