chip-io
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -6,2 +6,3 @@ var util = require('util'); | ||
var I2C = require('./i2c'); | ||
var AXP209 = require('./axp209'); | ||
@@ -62,2 +63,3 @@ var PCF8574A = require('./pcf8574a'); | ||
this._pcf8574a = new PCF8574A(2, 0x38); | ||
this._i2cReads = []; | ||
@@ -161,2 +163,105 @@ // emit "connect" event on the next tick | ||
ChipIO.prototype.i2cConfig = function(delay) { | ||
debug('i2cConfig', delay); | ||
}; | ||
ChipIO.prototype.i2cWrite = function(address, register, data) { | ||
if (arguments.length === 2) { | ||
data = register; | ||
register = null; | ||
} | ||
debug('i2cWrite', address, register, data); | ||
var i2c = new I2C(1, address); | ||
if (typeof(data) === 'number') { | ||
data = [data]; | ||
} | ||
data = new Buffer(data); | ||
i2c.open(function(err) { | ||
if (err) { | ||
return; | ||
} | ||
if (register) { | ||
i2c.writeRegister(register, data, function() { | ||
i2c.close(); | ||
}); | ||
} else { | ||
i2c.write(data, function() { | ||
i2c.close(); | ||
}); | ||
} | ||
}); | ||
}; | ||
ChipIO.prototype.i2cWriteReg = function(address, register, data) { | ||
debug('i2cWriteReg', address, register, data); | ||
this.i2cWrite(address, register, data); | ||
}; | ||
ChipIO.prototype.i2cRead = function(address, register, size, handler) { | ||
debug('i2cRead', address, register, size, handler); | ||
this._i2cReads.push(arguments); | ||
}; | ||
ChipIO.prototype.i2cReadOnce = function(address, register, size, handler) { | ||
if (arguments.length === 3) { | ||
handler = size; | ||
size = register; | ||
register = null; | ||
} | ||
debug('i2cReadOnce', address, register, size, handler); | ||
var i2c = new I2C(1, address); | ||
i2c.open(function(err) { | ||
if (err) { | ||
return; | ||
} | ||
if (register) { | ||
i2c.readRegister(register, size, function(err, data) { | ||
if (err) { | ||
return; | ||
} | ||
i2c.close(function() { | ||
var event = 'I2C-reply-' + address + '-' + register; | ||
this.once(event, handler); | ||
this.emit(event, data); | ||
}.bind(this)); | ||
}.bind(this)); | ||
} else { | ||
i2c.read(size, function(err, data) { | ||
if (err) { | ||
return; | ||
} | ||
i2c.close(function() { | ||
var event = 'I2C-reply-' + address; | ||
this.once(event, handler); | ||
this.emit(event, data); | ||
}.bind(this)); | ||
}.bind(this)); | ||
} | ||
}.bind(this)); | ||
}; | ||
ChipIO.prototype.pwmWrite = function(pin, value) { | ||
throw new Error('pwmWrite is not supported'); | ||
}; | ||
ChipIO.prototype.analogWrite = ChipIO.prototype.pwmWrite; | ||
ChipIO.prototype._tick = function() { | ||
@@ -199,4 +304,8 @@ if (this._pins[this._batPin].report) { | ||
} | ||
for (var j = 0; j < this._i2cReads.length; j++) { | ||
this.i2cReadOnce.apply(this, this._i2cReads[j]); | ||
} | ||
}; | ||
module.exports = ChipIO; |
{ | ||
"name": "chip-io", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Johnny-Five IO Plugin for the Next Thing Co. C.H.I.P.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,2 +11,5 @@ # chip-io | ||
* Node.js installed | ||
1. Install ```curl```: ```apt-get install curl``` | ||
2. Follow Debian section of [NodeSource installations instructions](https://github.com/nodesource/distributions#debinstall) | ||
* Build essential installed: ```apt-get install build-essential``` | ||
@@ -36,3 +39,3 @@ ## Getting Started | ||
See [examples](examples folder) as well as [Johnny-Five examples](http://johnny-five.io/examples/). | ||
See [examples](examples) folder as well as [Johnny-Five examples](http://johnny-five.io/examples/). | ||
@@ -58,3 +61,4 @@ ## API | ||
| INTTEMP | 10 | Input | Reads internal temperature from the AXP290 | | ||
| I2C | | I2C | Uses I2C port 1 (TWI1-SCK and TWI1-SDA) | | ||
![C.H.I.P. pinouts](http://docs.getchip.com/images/chip_pinouts.jpg) |
174592
473
62