Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added documentation"

  • Loading branch information...
commit f4a0e1baaabc694482f0bd446aeee41adbf865f9 1 parent a44787d
@jgautier jgautier authored
Showing with 18 additions and 5 deletions.
  1. +5 −4 lib/firmata.js
  2. +13 −1 readme.md
View
9 lib/firmata.js
@@ -149,12 +149,12 @@ var Board=function(port,callback){
break;
case I2C_REPLY:
var replyBuffer = [];
- var slaveAddress=board.currentBuffer[2]|(board.currentBuffer[3] << 7);
- var register=board.currentBuffer[4]|(board.currentBuffer[5] << 7);
+ var slaveAddress=(board.currentBuffer[2] & 0x7F)|((board.currentBuffer[3] & 0x7F) << 7);
+ var register=(board.currentBuffer[4] & 0x7F)|((board.currentBuffer[5] & 0x7F) << 7);
for(var i = 6,length = board.currentBuffer.length-1; i < length;i+=2){
replyBuffer.push(board.currentBuffer[i]|(board.currentBuffer[i+1] << 7));
}
- board.emit('I2C-reply',replyBuffer);
+ board.emit('I2C-reply-'+slaveAddress,replyBuffer);;
break;
case STRING_DATA:
console.log(new Buffer(board.currentBuffer.slice(1,-1)).toString('utf8'));
@@ -256,7 +256,8 @@ Board.prototype.sendI2CWriteRequest=function(slaveAddress,bytes){
data.push(END_SYSEX);
this.sp.write(data);
};
-Board.prototype.sendI2CReadRequest=function(slaveAddress,numBytes){
+Board.prototype.sendI2CReadRequest=function(slaveAddress,numBytes,callback){
this.sp.write([START_SYSEX,I2C_REQUEST,slaveAddress,this.I2C_MODES.READ<<3,numBytes & 0x7F,(numBytes >> 7) & 0x7F,END_SYSEX]);
+ this.once('I2C-reply-'+slaveAddress,callback);
};
module.exports={Board:Board};
View
14 readme.md
@@ -70,4 +70,16 @@ If you run *firmata* from the command line it will prompt you for the usb port.
*board.analogRead(pin,callback)*
- Read an input for an analog pin. Every time there is data on the pin the callback will be fired with a value argument.
+ Read an input for an analog pin. Every time there is data on the pin the callback will be fired with a value argument.
+
+ *board.servoWrite(pin,degree)*
+
+ Write a degree value to a servo pin.
+
+ *board.sendI2CWriteRequest(slaveAddress,[bytes])*
+
+ Write an array of bytes to a an I2C device.
+
+ *board.sendI2CReadRequest(slaveAddress,numBytes,function(data))*
+
+ Requests a number of bytes from a slave I2C device. When the bytes are received from the I2C device the callback is called with the byte array.
Please sign in to comment.
Something went wrong with that request. Please try again.