From 120ba35cd38fa3f251f5d4cb0c65f45e7270ce78 Mon Sep 17 00:00:00 2001 From: David Kebler Date: Sat, 21 Jan 2017 12:22:18 -0800 Subject: [PATCH] no need to test for existence of opts.interrupt --- lib/mcp23008-17.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/mcp23008-17.js b/lib/mcp23008-17.js index bc0254b..d00e653 100644 --- a/lib/mcp23008-17.js +++ b/lib/mcp23008-17.js @@ -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 - } + 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(() => { - for (let port in this.ports) { - if (this.ports[port].interrupt) { this.ports[port].interrupt.init() } - } - return this.writePinsCfg() - }) - + let jobs = [super.write(chip_config.cmd, chipSetByte(this.chip_config))] // configure chip + for (let port in this.ports) { + if (this.ports[port].interrupt) { jobs.push(this.ports[port].interrupt.init()) } + } + 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 - } + this.ports.B.interrupt = opts.interruptB ? opts.interruptB : opts.interrupt + } pin(id, port) {