diff --git a/package.json b/package.json index d472ebd..4239ee4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@uci/mcp", "main": "src", - "version": "0.1.22", + "version": "0.1.23", "description": "Classes and Helper Functions for using the MCP chip on I2C Bus", "scripts": { "relays": "node -r esm examples/relays", diff --git a/src/config.js b/src/config.js index daab9e5..931f882 100644 --- a/src/config.js +++ b/src/config.js @@ -41,7 +41,15 @@ export const PIN = { usedef: 0, // if usedef = 0 defval not used defval: 0 }, - toggle_switch: { // includes pullup by default + input: { + dir: 1, // 0 output,1 input + ivrt: 0, + pullup: 0, + intr: 0, // if intr = 0 usedef,deval not used + usedef: 0, // if usedef = 0 defval not used + defval: 0 + }, + input_interrupt: { // includes pullup by default dir: 1, // 0 output,1 input ivrt: 1, // for reading let 1 be zero and vice versa pullup: 1, @@ -49,7 +57,7 @@ export const PIN = { usedef: 0, // if usedef = 0 defval not used defval: 0 }, - toggle_switch_no_pullup: { + input_interrupt_ext_up: { dir: 1, // 0 output,1 input ivrt: 1, // for reading let 1 be zero and vice versa pullup: 0, // use external pullup 5V with external resister! @@ -57,7 +65,7 @@ export const PIN = { usedef: 0, // if usedef = 0 defval not used defval: 0 }, - toggle_switch_pulldown: { + input_interrupt_ext_down: { dir: 1, // 0 output,1 input ivrt: 0, // for reading let 1 be zero and vice versa pullup: 0, // use external pulldown @@ -65,7 +73,7 @@ export const PIN = { usedef: 0, // if usedef = 0 defval not used defval: 0 }, - momentary_switch: { + momentary_interrupt: { dir: 1, // 0 output,1 input ivrt: 1, // for reading let 1 be zero and vice versa pullup: 1, diff --git a/src/mcp230xx.js b/src/mcp230xx.js index cf35e37..6765365 100644 --- a/src/mcp230xx.js +++ b/src/mcp230xx.js @@ -29,6 +29,7 @@ class MCP230XX extends Device { log.fatal({msg:'unable to configure mcp chip', error:res.error, cfg:this.chipCfg, address:this.address}) throw `${res.error} at address ${this.address}/${this.address.toString(16)}` } + await this.commands.pin.cfg({pins:'all'}) //pins are outputs by default } } // end of MCP230XX Class diff --git a/src/mcp230xxi.js b/src/mcp230xxi.js index ebbe07c..fd48d19 100644 --- a/src/mcp230xxi.js +++ b/src/mcp230xxi.js @@ -79,7 +79,7 @@ class MCP230XXi extends MCP230XX { let cfg = { port: this[pin].mport || 'A', pins: this[pin].pins || 'all', - cfg: this[pin].type || 'toggle_switch' + cfg: this[pin].type || 'input_interrupt' } // this will set default type to internal pullup, only need to to change indivial pins to external if desired await this.pin.cfg(cfg) @@ -141,12 +141,13 @@ const ipincommands = { packet.reg = null if (packet.pins) { // avoid bad interrupt (i.e. no pin caused interrupt) - res.state = (await this.pin.status(packet)).status.pins[0][1] - res.port = packet.port res.ipin = inter.pin + res.port = packet.port delete inter.cmd; delete inter._header; delete inter.pin Object.assign(res,inter) delete res.status + res.state = (await this.pin.status(packet)).status.pins[0][1] + console.log('emitted interrupt packet', res) this.emit('interrupt', res) log.debug({msg:'found pin now resetting mcp port interrupt', response:res}) }