Permalink
Browse files

fixing read events and write methods

  • Loading branch information...
jgautier committed Jun 7, 2011
1 parent 8544541 commit 9b092135583d200db0a769ef672ee84b8fe8073a
Showing with 5 additions and 5 deletions.
  1. +5 −5 lib/firmata.js
View
@@ -60,7 +60,7 @@ var Board=function(port,callback){
board.pins[board.analogPins[port]].value = value;
}
board.emit('analog-read-'+port,value);
- board.emit('analog-read',{pin:port,data:value});
+ board.emit('analog-read',{pin:port,value:value});
}else if(cmd == DIGITAL_MESSAGE){
var port = (board.currentBuffer[0]&0x0F);
var lsb = board.currentBuffer[1];
@@ -70,7 +70,7 @@ var Board=function(port,callback){
var pinNumber = 8*port+i;
var pin = board.pins[pinNumber];
if(pin.mode == board.MODES.INPUT){
- pin.value = ((mask & 1) << pinNumber)>0;
+ pin.value = ((mask & 1) << pinNumber)>0?1:0;
board.emit('digital-read-'+pinNumber,pin.value);
board.emit('digital-read',{pin: pinNumber,value:pin.value});
}
@@ -193,7 +193,7 @@ Board.prototype.analogRead=function(pin,callback){
this.addListener('analog-read-'+pin,callback);
};
Board.prototype.analogWrite=function(pin,value){
- this.pins[pin]=value;
+ this.pins[pin].value=value;
this.sp.write([ANALOG_MESSAGE|pin,value & 0x7F,(value >> 7) & 0x7F]);
};
Board.prototype.pinMode=function(number,state){
@@ -203,9 +203,9 @@ Board.prototype.pinMode=function(number,state){
Board.prototype.digitalWrite=function(pin,value){
var port = Math.floor(pin/8);
var portValue=0;
- this.pins[pin]=value;
+ this.pins[pin].value=value;
for(var i=0;i<8;i++){
- if(this.pins[8*port+i])
+ if(this.pins[8*port+i].value)
portValue |= (1<<i);
}
this.sp.write([DIGITAL_MESSAGE|port,portValue & 0x7F,(portValue >> 7) & 0x7F]);

0 comments on commit 9b09213

Please sign in to comment.