read write tests

master
David Kebler 2017-01-16 16:26:28 -08:00
parent 860b38b621
commit 13097c8d22
2 changed files with 51 additions and 28 deletions

View File

@ -21,7 +21,8 @@ class MCP23008 extends Device {
} // end constructor
init() {
console.log('chip configuration', chip_config.cmd, chipSetByte())
// console.log('chip configuration', chip_config.cmd, chipSetByte())
// console.log(super.write.toString())
return super.write(chip_config.cmd, chipSetByte()) // configure chip
.then(() => { return this.writePinsCfg() })
@ -35,16 +36,16 @@ class MCP23008 extends Device {
for (let port in this.ports) {
for (let setting in registers.pin_config) {
let reg = registers.pin_config[setting]
if (port === 'B') { reg = reg + 16 }
if (port === 'B') { reg = reg + 0x10 }
let byte = 0;
let pins = this.ports[port].allPins
for (let i = 0; i < 8; i++) {
let pin = pins[i]
byte += pin.address.toFmt('DEC') * pin.cfg[setting]
}
// console.log(`port ${port} - setting ${setting} - reg ${reg} - byte ${byte}`)
// console.log(`port ${port} - setting ${setting} - reg ${reg} - byte ${byte}`)
jobs.push(
() => super.write(reg, byte) //.then((resp) => console.log(`done writing config ${resp}`))
() => super.write(reg, byte) //.then(() => console.log(`done writing config`))
)
}
}
@ -52,7 +53,7 @@ class MCP23008 extends Device {
} // end writePinsCfg
// reads all pins in all ports
read(cmd, fmt) {
readPins(cmd, fmt) {
let jobs = []
cmd = cmd ? cmd : 'gpio'
let reg = registers.pin_cmd[cmd]
@ -64,10 +65,6 @@ class MCP23008 extends Device {
}
write() {
}
pinRead(id, opts) {
let mcpdev = this;
return new Promise(function (resolve, reject) {

View File

@ -80,10 +80,10 @@
});
const ADDR = 0x20,
let ADDR = 0x20,
W = 0x09,
R = 0x0A,
PINSON = 129,
PINSON = 0xa5,
PINSOFF = 0x00
let testout = new MCP.MCP23008(bus1, ADDR, {
@ -91,21 +91,47 @@
name: 'outputs 1-8'
})
// let tasks = [
// testout.init(),
// testout.write(W, PINSON)
//
// ]
function tstout() {
return testout.init()
.then(() => {
console.log('testing device write and read')
return testout.write(W, PINSON)
.then(() => {
return testout.read(R)
.then((resp) => {
console.log('Pins Set On', _u.byteFormat(resp, { in: 'DEC', out: 'PLC' }))
return _u.pDelay(1000)
.then(() => {
console.log('Reset Pins')
return testout.write(W, PINSOFF)
})
})
})
})
.catch(err => console.log('errors:', err))
}
testout.init()
.then(() => {
return testout.write(W, PINSON)
.then(() => {
return testout.read(R)
.then((resp) => {
console.log('Pins Set On', resp)
return testout.write(W, PINSOFF)
})
})
})
.catch(err => console.log('errors:', err))
const
ADDR17 = 0x27,
port = { A: 0x09, B: 0x19 }
let testin = new MCP.MCP23017(bus1, ADDR17, {
pin_cfg_default: 'toggle_switch',
name: 'read inputs 1-16'
})
function tstin(p) {
return testin.init()
.then(() => {
console.log('port', port[p])
return testin.read(port[p])
.then((resp) => {
console.log('Port ', p, ' Pins', _u.byteFormat(resp, { in: 'DEC', out: 'PLC' }))
})
})
.catch(err => console.log('errors:', err))
}
// tstout().then(() => tstin())
bus1.qAdd(tstin('A'))
bus1.qAdd(tstin('B'))