From 860b38b621caff01498203628010f4ce12a515df Mon Sep 17 00:00:00 2001 From: David Kebler Date: Mon, 16 Jan 2017 00:04:24 -0800 Subject: [PATCH] fix super calls to write and promise chains --- lib/mcp23008-17.js | 9 ++++---- test/mcp.test.js | 56 +++++++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/lib/mcp23008-17.js b/lib/mcp23008-17.js index 2ed4a2f..fed80e7 100644 --- a/lib/mcp23008-17.js +++ b/lib/mcp23008-17.js @@ -13,7 +13,6 @@ class MCP23008 extends Device { this.ports = {} opts.portID = 'A' this.ports.A = new Port(opts) - console.log(this.ports.A) // if not specified there RPi is not managing the interrupt // pin number on RPi that is connected to and services the interrupt. 4/17/27/22 = 7/11/13/15 if (opts.interPin) { @@ -22,9 +21,9 @@ class MCP23008 extends Device { } // end constructor init() { - console.log('chip ', chip_config.cmd, chipSetByte()) - return this.write(chip_config.cmd, chipSetByte()) // configure chip - .then(this.writePinsCfg()) + console.log('chip configuration', chip_config.cmd, chipSetByte()) + return super.write(chip_config.cmd, chipSetByte()) // configure chip + .then(() => { return this.writePinsCfg() }) } @@ -45,7 +44,7 @@ class MCP23008 extends Device { } // console.log(`port ${port} - setting ${setting} - reg ${reg} - byte ${byte}`) jobs.push( - () => this.write(reg, byte) // .then((resp)=>console.log(`done writing config ${resp}`)) + () => super.write(reg, byte) //.then((resp) => console.log(`done writing config ${resp}`)) ) } } diff --git a/test/mcp.test.js b/test/mcp.test.js index 4e013ce..5f50776 100644 --- a/test/mcp.test.js +++ b/test/mcp.test.js @@ -76,32 +76,36 @@ expect(mcp8.pin(8).cfg.ivrt, "pin address getter failed").to.equal(1) }); - const ADDR = 0x20, - W = 0x09, - R = 0x0A, - PINSON = 129, - PINSOFF = 0x00 - - let testout = new MCP.MCP23008(bus1, ADDR, { - pin_cfg_default: 'output', - name: 'outputs 1-8' - }) - - let tasks = [ - testout.init(), - testout.write(W, PINSON) - - ] - - testout.init().then(() => - testout.write(W, PINSON).then(() => - testout.read(R).then((resp) => { - console.log('Pins Set On', resp) - testout.write(W, PINSOFF) - }) - ) - ) - }); }); + + const ADDR = 0x20, + W = 0x09, + R = 0x0A, + PINSON = 129, + PINSOFF = 0x00 + + let testout = new MCP.MCP23008(bus1, ADDR, { + pin_cfg_default: 'output', + name: 'outputs 1-8' + }) + + // let tasks = [ + // testout.init(), + // testout.write(W, PINSON) + // + // ] + + 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))