From 9e286f7ba5748850baa01bedf3325c5c672d4e38 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Sat, 24 Jan 2015 18:00:25 -0500 Subject: [PATCH] setColorRGB API as per #8 --- README.md | 1 + examples/bean_example.js | 4 ++-- lib/Bean.js | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7c4dc84..98f36b7 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/examples/bean_example.js b/examples/bean_example.js index a277a20..d72fdd3 100644 --- a/examples/bean_example.js +++ b/examples/bean_example.js @@ -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"); }); @@ -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); diff --git a/lib/Bean.js b/lib/Bean.js index e5c61ae..2a2f742 100644 --- a/lib/Bean.js +++ b/lib/Bean.js @@ -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); };