Skip to content

Commit

Permalink
setColorRGB API
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepmistry committed Jan 24, 2015
1 parent 12effdd commit 9e286f7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ When that returns you're finally ready to use the ble-bean api:
bean.requestTemp(callback);
bean.requestAccell(callback);
bean.setColor(color, callback); //where color is a buffer of r,g,b hex values
bean.setColorRGB(r, g, b, callback); //when r, g, b are numbers 0 - 255
bean.write(data, callback); //where data is a buffer
```
Huge gotcha here though, the callback to all api commands DO NOT GIVE YOU BACK YOUR DATA, they simply confirms that the request has left your computer.
Expand Down
4 changes: 2 additions & 2 deletions examples/bean_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Bean.discover(function(bean){
var readData = function() {

//set random led colors between 0-255. I find red overpowering so red between 0-64
bean.setColor(new Buffer([getRandomInt(0,64),getRandomInt(0,255),getRandomInt(0,255)]),
bean.setColorRGB(getRandomInt(0,64),getRandomInt(0,255),getRandomInt(0,255),
function(){
console.log("led color sent");
});
Expand Down Expand Up @@ -73,7 +73,7 @@ var exitHandler = function exitHandler() {
triedToExit = true;
console.log('Turning off led...');
clearInterval(intervalId);
connectedBean.setColor(new Buffer([0x0,0x0,0x0]), function(){});
connectedBean.setColorRGB(0x0,0x0,0x0, function(){});
//no way to know if succesful but often behind other commands going out, so just wait 2 seconds
console.log('Disconnecting from Device...');
setTimeout(connectedBean.disconnect.bind(connectedBean, function(){}), 2000);
Expand Down
4 changes: 4 additions & 0 deletions lib/Bean.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ Bean.prototype.setColor = function(color,done){
this.send(commands.MSG_ID_CC_LED_WRITE_ALL, color, done);
};

Bean.prototype.setColorRGB = function(r,g,b,done){
this.setColor(new Buffer([r, g, b]), done)
};

Bean.prototype.requestAccell = function(done){
this.send(commands.MSG_ID_CC_ACCEL_READ, new Buffer([]), done);
};
Expand Down

0 comments on commit 9e286f7

Please sign in to comment.