no need to test for existence of opts.interrupt

master
David Kebler 2017-01-21 12:22:18 -08:00
parent 4e4a43a099
commit 120ba35cd3
1 changed files with 13 additions and 15 deletions

View File

@ -12,26 +12,25 @@ class MCP23008 extends Device {
opts.portID = 'A' opts.portID = 'A'
this.ports.A = new Port(opts) this.ports.A = new Port(opts)
this.chip_config = opts.chip_config this.chip_config = opts.chip_config
if (opts.interrupt) {
this.ports.A.interrupt = opts.interruptA ? opts.interruptA : opts.interrupt this.ports.A.interrupt = opts.interruptA ? opts.interruptA : opts.interrupt
}
} // 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()) // console.log(super.write.toString())
return super.write(chip_config.cmd, chipSetByte(this.chip_config)) // configure chip let jobs = [super.write(chip_config.cmd, chipSetByte(this.chip_config))] // configure chip
.then(() => {
for (let port in this.ports) { for (let port in this.ports) {
if (this.ports[port].interrupt) { this.ports[port].interrupt.init() } if (this.ports[port].interrupt) { jobs.push(this.ports[port].interrupt.init()) }
} }
return this.writePinsCfg() jobs.push(this.writePinsCfg())
}) return _u.pSeries(jobs)
} }
pin(id) { return this.ports.A.pin(id) } // get a reference to a particular pin's object pin(id) { return this.ports.A.pin(id) } // get a reference to a particular pin's object
interrupt(port = 'A') { return this.ports[port].interrupt }
// pin configurations should already be set before calling // pin configurations should already be set before calling
writePinsCfg() { writePinsCfg() {
let jobs = []; let jobs = [];
@ -47,7 +46,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(() => console.log(`done writing config`)) super.write(reg, byte) //.then(() => console.log(`done writing config`))
) )
} }
} }
@ -133,9 +132,8 @@ class MCP23017 extends MCP23008 {
// add a second port // add a second port
opts.portID = 'B' opts.portID = 'B'
this.ports.B = new Port(opts) this.ports.B = new Port(opts)
if (opts.interrupt) {
this.ports.B.interrupt = opts.interruptB ? opts.interruptB : opts.interrupt this.ports.B.interrupt = opts.interruptB ? opts.interruptB : opts.interrupt
}
} }
pin(id, port) { pin(id, port) {