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 consumersmaster
parent
7ede4d93b5
commit
078b24e9d7
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "@uci/mcp",
|
"name": "@uci/mcp",
|
||||||
"main": "src",
|
"main": "src",
|
||||||
"version": "0.1.18",
|
"version": "0.1.19",
|
||||||
"description": "Classes and Helper Functions for using the MCP chip on I2C Bus",
|
"description": "Classes and Helper Functions for using the MCP chip on I2C Bus",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"relays": "node -r esm examples/relays",
|
"relays": "node -r esm examples/relays",
|
||||||
|
|
|
@ -72,7 +72,7 @@ export default {
|
||||||
},
|
},
|
||||||
_state: async function(packet,op,reg){
|
_state: async function(packet,op,reg){
|
||||||
reg = (reg!==undefined)? reg : PIN.cmd.gpio
|
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 reply = { cmd:'reply'}
|
||||||
let pins = parsePins(packet.pins)
|
let pins = parsePins(packet.pins)
|
||||||
let state = new _.Byte()
|
let state = new _.Byte()
|
||||||
|
|
|
@ -8,6 +8,7 @@ let log = {}
|
||||||
|
|
||||||
class MCP230XXi extends MCP230XX {
|
class MCP230XXi extends MCP230XX {
|
||||||
constructor(pins, opts) {
|
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.ipath) {
|
||||||
if (typeof opts.iport === 'number') {
|
if (typeof opts.iport === 'number') {
|
||||||
opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + 'inter#c>t'
|
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'
|
opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + 'inter#c>n'
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// otherwise each pin will have its own socket so make a client for each
|
||||||
pins.forEach((pin, index) => {
|
pins.forEach((pin, index) => {
|
||||||
let ipin = 'i' + pin
|
let ipin = 'i' + pin
|
||||||
opts[ipin] = opts[pin] || {}
|
opts[ipin] = opts[pin] || opts.interrupt || {}
|
||||||
if (index === 1) opts[ipin].mport = opts[ipin].mort || 'B'
|
if (index === 1) opts[ipin].mport = opts[ipin].mport || 'B'
|
||||||
delete opts[pin]
|
delete opts[pin]
|
||||||
if (opts[ipin].port || opts.iport !== 'number') {
|
if (opts[ipin].host) {
|
||||||
opts[ipin].port = opts[ipin].port || opts.iport
|
opts[ipin].port = opts[ipin].port ? opts[ipin].port + pin : 9000 + pin
|
||||||
if (typeof opts[ipin].port !== 'number') opts[ipin].port = 9000 + pin
|
opts[ipin].host = opts[ipin].host
|
||||||
opts[ipin].host = opts[ipin].host || opts.ihost || opts.host
|
opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + ipin + '#c>t'
|
||||||
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 {
|
else {
|
||||||
opts[pin].path = opts[pin].path || opts.ipath
|
opts[ipin].path = (opts[ipin].path || 'interrupt') + ':'+ pin
|
||||||
if (!opts[pin].path)
|
opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + ipin + '#c>n'
|
||||||
Object.assign(opts[pin], { path: 'interrupt:' + pin })
|
|
||||||
opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + pin + '#c>n'
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -70,6 +68,7 @@ class MCP230XXi extends MCP230XX {
|
||||||
pins: this[pin].pins || 'all',
|
pins: this[pin].pins || 'all',
|
||||||
cfg: this[pin].type || 'toggle_switch'
|
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)
|
await this.pin.cfg(cfg)
|
||||||
// shouldn't need this as reset is pushed upon connection to interrupt socket
|
// 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')
|
// log.info('initial resetting of mcp interrupt port for corresponding sbc gpio pin')
|
||||||
|
|
Loading…
Reference in New Issue