diff --git a/package.json b/package.json index dc33740..ecc23a6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@uci/mcp", "main": "src", - "version": "0.1.19", + "version": "0.1.20", "description": "Classes and Helper Functions for using the MCP chip on I2C Bus", "scripts": { "relays": "node -r esm examples/relays", diff --git a/src/commands.js b/src/commands.js index 62e8912..023a5b1 100644 --- a/src/commands.js +++ b/src/commands.js @@ -43,7 +43,6 @@ export default { else cfg = PIN.cfgset[packet.cfg] for(let name of Object.keys(PIN.setting)) { let op = cfg[name] ? 'on' : 'off' - // console.log(name, op) let busreply = await this.pin._state(packet,op,PIN.setting[name]) if (busreply.error) return busreply reply.status[name] = busreply.status diff --git a/src/mcp230xxi.js b/src/mcp230xxi.js index b9c2457..48a2060 100644 --- a/src/mcp230xxi.js +++ b/src/mcp230xxi.js @@ -7,7 +7,13 @@ let log = {} // if opts.iport not set then will be generated based on pin number class MCP230XXi extends MCP230XX { - constructor(pins, opts) { + constructor(pins, options={}) { + if (!Array.isArray(pins)) { options = pins; pins = options.interrupt.pins} // if pins sent via .interrupt.pins + + let opts = Object.assign({},options) // don't allow options to mutate + if (opts.interrupt) delete opts.interrupt.pins // if .interrupt is passed then .pins must be removed + delete opts.sockets // .sockets is used by uci base so clear it was sent by mistake + // console.log('options as ready for mcp',pins, opts) // if iport or ipath is set then all interrupts have a single consolidating socket if (typeof opts.iport === 'number' || opts.ipath) { if (typeof opts.iport === 'number') { @@ -27,7 +33,7 @@ class MCP230XXi extends MCP230XX { if (index === 1) opts[ipin].mport = opts[ipin].mport || 'B' delete opts[pin] if (opts[ipin].host) { - opts[ipin].port = opts[ipin].port ? opts[ipin].port + pin : 9000 + pin + opts[ipin].port = opts[ipin].port ? opts[ipin].port + +pin : 9000 + +pin opts[ipin].host = opts[ipin].host opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + ipin + '#c>t' } @@ -88,7 +94,7 @@ class MCP230XXi extends MCP230XX { async _reset(port) { // local non-packet hidden command - log.info(`resetting interrupt for port ${port || 'A'},${this.id}`) + console.log(`resetting interrupt for port ${port || 'A'},${this.id} arg ${port !== 'B' ? 0x08 : 0x1}`) return await this.bus.read(port !== 'B' ? 0x08 : 0x18) // 0x08 is intcap interrupt capture register } @@ -115,6 +121,7 @@ const ipincommands = { // given a gpio interrupt then push a packet with cmd: 'pin.interrupt.find' and pin: the gpio pin number find: async function(inter) { // inter is a UCI packet + console.log('packet from interrupt to interpret',inter) if (this.ready) { // protects tripped interrupt before it's fully initialized, or interrupt requests arriving before porcessing is complete this.ready = false