Comparing version 0.0.15 to 0.1.0
@@ -23,3 +23,3 @@ const util = require('util') | ||
console.log(data) | ||
if(data == 'BBIO1'){ | ||
if(data.indexOf('BBIO1') !== -1){ | ||
this.ready() | ||
@@ -32,6 +32,7 @@ } | ||
Object.assign(BusPirate.prototype, i2c) | ||
BusPirate.prototype.reset = function(){ | ||
console.log('resetting') | ||
this.port.write([0x0F]) | ||
this.port.open(()=>{ this.emit('open')}) | ||
} | ||
@@ -51,4 +52,3 @@ | ||
Object.assign(BusPirate.prototype, i2c) | ||
module.exports = BusPirate |
@@ -12,3 +12,13 @@ var BusPirate = require('../BusPirate') | ||
busPirate.on('ready', () => { | ||
console.log(busPirate) | ||
busPirate.i2cInit() | ||
busPirate.i2cConfig({ | ||
power: true | ||
}); | ||
busPirate.i2cWrite(0x7e, [0x1e, 0x40]) | ||
}) | ||
process.on('SIGINT', function(){ | ||
busPirate.reset() | ||
process.exit() | ||
}) |
var BusPirate = require('../BusPirate') | ||
var busPirate = new BusPirate({ | ||
port: '/dev/tty.usbserial-AI03KY7Z' | ||
port: '/dev/tty.usbmodem00000001' | ||
}) | ||
@@ -6,0 +6,0 @@ |
@@ -1,8 +0,54 @@ | ||
let i2c = { | ||
i2cInit: function(){ | ||
console.log('starting I2C') | ||
this.port.write([0x02]) | ||
i2c = {}; | ||
i2c.i2cInit = function(){ | ||
console.log(this) | ||
console.log('starting I2C') | ||
this.port.write([0x00, 0x02]) | ||
} | ||
i2c.i2cConfig = function(opts){ | ||
if(!opts){ | ||
return | ||
} | ||
let tempByte = 0x40 | ||
if(opts.power){ | ||
tempByte |= 1 << 3 | ||
console.log('Power turning ON') | ||
} | ||
if(opts.pullups){ | ||
tempByte |= 1 << 2 | ||
console.log('Pullup resistors ENABLED') | ||
} | ||
if(opts.aux){ | ||
tempByte |= 1 << 1 | ||
} | ||
if(opts.cs){ | ||
tempByte |= 1 | ||
} | ||
this.port.write([tempByte]) | ||
} | ||
/* | ||
First send the write then read command (0x08) | ||
The next two bytes (High8/Low8) set the number of bytes to write (0 to 4096) | ||
The next two bytes (h/l) set the number of bytes to read (0 to 4096) | ||
If the number of bytes to read or write are out of bounds, the Bus Pirate will return 0x00 now | ||
Next, send the bytes to write. Bytes are buffered in the Bus Pirate, there is no acknowledgment that a byte is received. | ||
The Bus Pirate sends an I2C start bit, then all write bytes are sent at once. If an I2C write is not ACKed by a slave device, then the operation will abort and the Bus Pirate will return 0x00 now | ||
Read starts immediately after the write completes. Bytes are read from I2C into a buffer at max I2C speed (no waiting for UART). All read bytes are ACKed, except the last byte which is NACKed, this process is handled internally between the Bus Pirate and the I2C device | ||
At the end of the read process, the Bus Pirate sends an I2C stop | ||
The Bus Pirate now returns 0x01 to the PC, indicating success | ||
Finally, the buffered read bytes are returned to the PC | ||
*/ | ||
i2c.i2cWrite = function(register, bytes){ | ||
let lowByteLength = 0x00 | bytes.length | ||
let highByteLength = 0x00 | (bytes.length >> 4) | ||
let commandBytes = [0x08, highByteLength, lowByteLength, 0x00, 0x00, register] | ||
commandBytes.concat(bytes) | ||
this.port.write(commandBytes) | ||
} | ||
module.exports = i2c |
{ | ||
"name": "bus-pirate", | ||
"version": "0.0.15", | ||
"version": "0.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "BusPirate.js", |
@@ -9,2 +9,17 @@ # bus-pirate | ||
Currently working | ||
.start() | ||
.reset() | ||
'ready' event | ||
i2cInit() | ||
i2cConfig({ | ||
power: true, | ||
pullups: true, | ||
aux: true, | ||
cs: true | ||
}) | ||
i2cWrite(address, bytesArray) | ||
Thanks to node-serialport for making this all possible <3 |
4441
115
24