From 078b24e9d73a2e307ff80ee8a38d64f3af106ac8 Mon Sep 17 00:00:00 2001 From: David Kebler Date: Wed, 6 Mar 2019 16:45:53 -0800 Subject: [PATCH] 0.1.19 alter the multple pin options processing, now accepts opts.interrupt and deals with port and path so as to match uci/interrupt options changes when making consumers --- package.json | 2 +- src/commands.js | 2 +- src/mcp230xxi.js | 25 ++++++++++++------------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 2504617..dc33740 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@uci/mcp", "main": "src", - "version": "0.1.18", + "version": "0.1.19", "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 bcd654a..62e8912 100644 --- a/src/commands.js +++ b/src/commands.js @@ -72,7 +72,7 @@ export default { }, _state: async function(packet,op,reg){ reg = (reg!==undefined)? reg : PIN.cmd.gpio - // console.log(op, reg, packet) + // console.log('_state change request', op, reg, packet) let reply = { cmd:'reply'} let pins = parsePins(packet.pins) let state = new _.Byte() diff --git a/src/mcp230xxi.js b/src/mcp230xxi.js index ce34464..b9c2457 100644 --- a/src/mcp230xxi.js +++ b/src/mcp230xxi.js @@ -8,6 +8,7 @@ let log = {} class MCP230XXi extends MCP230XX { constructor(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') { opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + 'inter#c>t' @@ -19,24 +20,21 @@ class MCP230XXi extends MCP230XX { opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + 'inter#c>n' } } else { + // otherwise each pin will have its own socket so make a client for each pins.forEach((pin, index) => { let ipin = 'i' + pin - opts[ipin] = opts[pin] || {} - if (index === 1) opts[ipin].mport = opts[ipin].mort || 'B' + opts[ipin] = opts[pin] || opts.interrupt || {} + if (index === 1) opts[ipin].mport = opts[ipin].mport || 'B' delete opts[pin] - if (opts[ipin].port || opts.iport !== 'number') { - opts[ipin].port = opts[ipin].port || opts.iport - if (typeof opts[ipin].port !== 'number') opts[ipin].port = 9000 + pin - opts[ipin].host = opts[ipin].host || opts.ihost || opts.host - opts.sockets = - (opts.sockets ? opts.sockets + ',' : '') + ipin + '#c>t' + if (opts[ipin].host) { + 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' } - // either on the same host as bus and interrupt or not - no need for both + // no host will make a pipe by default else { - opts[pin].path = opts[pin].path || opts.ipath - if (!opts[pin].path) - Object.assign(opts[pin], { path: 'interrupt:' + pin }) - opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + pin + '#c>n' + opts[ipin].path = (opts[ipin].path || 'interrupt') + ':'+ pin + opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + ipin + '#c>n' } }) } @@ -70,6 +68,7 @@ class MCP230XXi extends MCP230XX { pins: this[pin].pins || 'all', cfg: this[pin].type || 'toggle_switch' } + // this will set default type to internal pullup, only need to to change indivial pins to external if desired await this.pin.cfg(cfg) // shouldn't need this as reset is pushed upon connection to interrupt socket // log.info('initial resetting of mcp interrupt port for corresponding sbc gpio pin')