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
master
David Kebler 2019-03-06 16:45:53 -08:00
parent 7ede4d93b5
commit 078b24e9d7
3 changed files with 14 additions and 15 deletions

View File

@ -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",

View File

@ -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()

View File

@ -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')