0.1.20 make sure options don't mutuate, also that if pin is string it gets cast to number
parent
078b24e9d7
commit
f6b40be73b
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "@uci/mcp",
|
"name": "@uci/mcp",
|
||||||
"main": "src",
|
"main": "src",
|
||||||
"version": "0.1.19",
|
"version": "0.1.20",
|
||||||
"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",
|
||||||
|
|
|
@ -43,7 +43,6 @@ export default {
|
||||||
else cfg = PIN.cfgset[packet.cfg]
|
else cfg = PIN.cfgset[packet.cfg]
|
||||||
for(let name of Object.keys(PIN.setting)) {
|
for(let name of Object.keys(PIN.setting)) {
|
||||||
let op = cfg[name] ? 'on' : 'off'
|
let op = cfg[name] ? 'on' : 'off'
|
||||||
// console.log(name, op)
|
|
||||||
let busreply = await this.pin._state(packet,op,PIN.setting[name])
|
let busreply = await this.pin._state(packet,op,PIN.setting[name])
|
||||||
if (busreply.error) return busreply
|
if (busreply.error) return busreply
|
||||||
reply.status[name] = busreply.status
|
reply.status[name] = busreply.status
|
||||||
|
|
|
@ -7,7 +7,13 @@ let log = {}
|
||||||
// if opts.iport not set then will be generated based on pin number
|
// if opts.iport not set then will be generated based on pin number
|
||||||
|
|
||||||
class MCP230XXi extends MCP230XX {
|
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 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') {
|
||||||
|
@ -27,7 +33,7 @@ class MCP230XXi extends MCP230XX {
|
||||||
if (index === 1) opts[ipin].mport = opts[ipin].mport || 'B'
|
if (index === 1) opts[ipin].mport = opts[ipin].mport || 'B'
|
||||||
delete opts[pin]
|
delete opts[pin]
|
||||||
if (opts[ipin].host) {
|
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[ipin].host = opts[ipin].host
|
||||||
opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + ipin + '#c>t'
|
opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + ipin + '#c>t'
|
||||||
}
|
}
|
||||||
|
@ -88,7 +94,7 @@ class MCP230XXi extends MCP230XX {
|
||||||
|
|
||||||
async _reset(port) {
|
async _reset(port) {
|
||||||
// local non-packet hidden command
|
// 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
|
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
|
// given a gpio interrupt then push a packet with cmd: 'pin.interrupt.find' and pin: the gpio pin number
|
||||||
find: async function(inter) {
|
find: async function(inter) {
|
||||||
// inter is a UCI packet
|
// inter is a UCI packet
|
||||||
|
console.log('packet from interrupt to interpret',inter)
|
||||||
if (this.ready) {
|
if (this.ready) {
|
||||||
// protects tripped interrupt before it's fully initialized, or interrupt requests arriving before porcessing is complete
|
// protects tripped interrupt before it's fully initialized, or interrupt requests arriving before porcessing is complete
|
||||||
this.ready = false
|
this.ready = false
|
||||||
|
|
Loading…
Reference in New Issue