From 40a26100a28b262cccf1fa99b1bb731a3080e02a Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Tue, 23 Dec 2014 21:46:27 -0500 Subject: [PATCH] split set color param to r, g, b --- README.md | 2 +- examples/bean_example.js | 4 ++-- examples/ble.js | 2 +- examples/firmata.js | 2 +- examples/scratch.js | 2 +- examples/serial.js | 2 +- lib/Bean.js | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6f606ca..6ca0eaf 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,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.setColor(r, g, b, callback); // r, g, b are 0-255/0x00 - 0xff 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..f38fa5d 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.setColor(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.setColor(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/examples/ble.js b/examples/ble.js index 56e11ee..8654988 100644 --- a/examples/ble.js +++ b/examples/ble.js @@ -71,7 +71,7 @@ var exitHandler = function exitHandler() { triedToExit = true; console.log('Turning off led...'); clearInterval(intervalId); - connectedBean.setColor(new Buffer([0x0,0x0,0x0]), function(){}); + connectedBean.setColor(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/examples/firmata.js b/examples/firmata.js index dd3c3d9..cba4517 100644 --- a/examples/firmata.js +++ b/examples/firmata.js @@ -62,7 +62,7 @@ var exitHandler = function exitHandler() { triedToExit = true; console.log('Turning off led...'); clearInterval(intervalId); - connectedBean.setColor(new Buffer([0x0,0x0,0x0]), function(){}); + connectedBean.setColor(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/examples/scratch.js b/examples/scratch.js index 22a1498..6e02281 100644 --- a/examples/scratch.js +++ b/examples/scratch.js @@ -67,7 +67,7 @@ var exitHandler = function exitHandler() { triedToExit = true; console.log('Turning off led...'); clearInterval(intervalId); - connectedBean.setColor(new Buffer([0x0,0x0,0x0]), function(){}); + connectedBean.setColor(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/examples/serial.js b/examples/serial.js index 2aaf3a7..0e23942 100644 --- a/examples/serial.js +++ b/examples/serial.js @@ -41,7 +41,7 @@ var exitHandler = function exitHandler() { triedToExit = true; console.log('Turning off led...'); clearInterval(intervalId); - connectedBean.setColor(new Buffer([0x0,0x0,0x0]), function(){}); + connectedBean.setColor(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 d19735d..5a78a53 100644 --- a/lib/Bean.js +++ b/lib/Bean.js @@ -146,8 +146,8 @@ Bean.prototype.write = function(data, done){ this.send(commands.MSG_ID_SERIAL_DATA, data, done); } -Bean.prototype.setColor = function(color,done){ - this.send(commands.MSG_ID_CC_LED_WRITE_ALL, color, done); +Bean.prototype.setColor = function(r,g,b,done){ + this.send(commands.MSG_ID_CC_LED_WRITE_ALL, new Buffer([r, g, b]), done); }; Bean.prototype.requestAccell = function(done){