no need to test for existence of opts.interrupt
parent
4e4a43a099
commit
120ba35cd3
|
@ -12,26 +12,25 @@ class MCP23008 extends Device {
|
|||
opts.portID = 'A'
|
||||
this.ports.A = new Port(opts)
|
||||
this.chip_config = opts.chip_config
|
||||
if (opts.interrupt) {
|
||||
this.ports.A.interrupt = opts.interruptA ? opts.interruptA : opts.interrupt
|
||||
}
|
||||
|
||||
} // end constructor
|
||||
|
||||
init() {
|
||||
// console.log('chip configuration', chip_config.cmd, chipSetByte())
|
||||
// console.log(super.write.toString())
|
||||
return super.write(chip_config.cmd, chipSetByte(this.chip_config)) // configure chip
|
||||
.then(() => {
|
||||
let jobs = [super.write(chip_config.cmd, chipSetByte(this.chip_config))] // configure chip
|
||||
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
|
||||
|
||||
interrupt(port = 'A') { return this.ports[port].interrupt }
|
||||
|
||||
// pin configurations should already be set before calling
|
||||
writePinsCfg() {
|
||||
let jobs = [];
|
||||
|
@ -47,7 +46,7 @@ class MCP23008 extends Device {
|
|||
}
|
||||
// console.log(`port ${port} - setting ${setting} - reg ${reg} - byte ${byte}`)
|
||||
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
|
||||
opts.portID = 'B'
|
||||
this.ports.B = new Port(opts)
|
||||
if (opts.interrupt) {
|
||||
this.ports.B.interrupt = opts.interruptB ? opts.interruptB : opts.interrupt
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pin(id, port) {
|
||||
|
|
Loading…
Reference in New Issue