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

View File

@ -80,10 +80,10 @@
}); });
const ADDR = 0x20, let ADDR = 0x20,
W = 0x09, W = 0x09,
R = 0x0A, R = 0x0A,
PINSON = 129, PINSON = 0xa5,
PINSOFF = 0x00 PINSOFF = 0x00
let testout = new MCP.MCP23008(bus1, ADDR, { let testout = new MCP.MCP23008(bus1, ADDR, {
@ -91,21 +91,47 @@
name: 'outputs 1-8' name: 'outputs 1-8'
}) })
// let tasks = [ function tstout() {
// testout.init(), return testout.init()
// testout.write(W, PINSON)
//
// ]
testout.init()
.then(() => { .then(() => {
console.log('testing device write and read')
return testout.write(W, PINSON) return testout.write(W, PINSON)
.then(() => { .then(() => {
return testout.read(R) return testout.read(R)
.then((resp) => { .then((resp) => {
console.log('Pins Set On', 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) return testout.write(W, PINSOFF)
}) })
}) })
}) })
})
.catch(err => console.log('errors:', err)) .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'))