made find function more robust against user abuse like flipping switches fast and continuouly.
changed the reset command to be for pushed reset request and moved old/actual reset to private function of class. Now when instance connects to interrupt socket it should get a reset command pushed.master
parent
95926a892c
commit
16cea2ef02
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "@uci/mcp",
|
"name": "@uci/mcp",
|
||||||
"main": "src",
|
"main": "src",
|
||||||
"version": "0.1.8",
|
"version": "0.1.9",
|
||||||
"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",
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
"homepage": "https://github.com/uCOMmandIt/uci-mcp#readme",
|
"homepage": "https://github.com/uCOMmandIt/uci-mcp#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@uci/i2c-device": "^0.1.4",
|
"@uci/i2c-device": "^0.1.4",
|
||||||
"@uci/logger": "0.0.3",
|
"@uci/logger": "0.0.4",
|
||||||
"@uci/utils": "^0.1.1"
|
"@uci/utils": "^0.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -59,8 +59,9 @@ export default class MCP230XXi extends MCP230XX {
|
||||||
this.pins.forEach(async pin => {
|
this.pins.forEach(async pin => {
|
||||||
let cfg = {port:this[pin].mport||'A',pins:this[pin].pins||'all', cfg:this[pin].type ||'toggle_switch'}
|
let cfg = {port:this[pin].mport||'A',pins:this[pin].pins||'all', cfg:this[pin].type ||'toggle_switch'}
|
||||||
await this.pin.cfg(cfg)
|
await this.pin.cfg(cfg)
|
||||||
log.info('resetting mcp port for corresponding gpio pin')
|
// shouldn't need this as reset is pushed upon connection to interrupt socket
|
||||||
await this.pin.interrupt.reset(this[pin].mport)
|
// log.info('initial resetting of mcp interrupt port for corresponding sbc gpio pin')
|
||||||
|
// await this._reset(this[pin].mport)
|
||||||
this.ready=true
|
this.ready=true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -75,36 +76,46 @@ export default class MCP230XXi extends MCP230XX {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _reset(port) { // local non-packet hidden command
|
||||||
|
log.info(`resetting interrupt for port ${port || 'A'},${this.id}`)
|
||||||
|
return await this.bus.read(port!=='B' ? 0x08 : 0x18) // 0x08 is intcap interrupt capture register
|
||||||
|
}
|
||||||
|
|
||||||
interruptProcessor(func) {this._interruptProcess = func}
|
interruptProcessor(func) {this._interruptProcess = func}
|
||||||
|
|
||||||
} // end of MCP230XX Class
|
} // end of MCP230XX Class
|
||||||
|
|
||||||
// commands to be added to pin command functions
|
// commands to be added to pin packet command functions
|
||||||
const ipincommands= { interrupt: {
|
const ipincommands= { interrupt: {
|
||||||
reset: async function (port) {
|
reset: async function (packet) {
|
||||||
log.info(`resetting interrupt for port ${port || 'A'},${this.id}`)
|
log.info({packet:packet},`'socket has push requested a reset of mcp interrupt port for gpio pin ${packet.pin}`)
|
||||||
return await this.bus.read(port!=='B' ? 0x08 : 0x18) // 0x08 is intcap interrupt capture register
|
let port = this[packet.pin].mport || 'A'
|
||||||
|
await this._reset(port)
|
||||||
},
|
},
|
||||||
// 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) { // inter is a hash packet
|
find: async function (inter) { // inter is a UCI packet
|
||||||
if(this.ready){ // protects tripped interrupt before it's fully initialized and reset
|
if(this.ready){ // protects tripped interrupt before it's fully initialized, or interrupt requests arriving before porcessing is complete
|
||||||
|
this.ready = false
|
||||||
log.info({packet:inter},'finding mcp pin which caused interrupt')
|
log.info({packet:inter},'finding mcp pin which caused interrupt')
|
||||||
let packet = {pins:'all',reg:'intf'}
|
let packet = {pins:'all',reg:'intf'}
|
||||||
packet.port = inter.port || this[inter.pin].mport || 'A'
|
packet.port = inter.port || this[inter.pin].mport || 'A'
|
||||||
let res = await this.pin.status(packet)
|
let res = await this.pin.status(packet)
|
||||||
log.info('found pin now resetting mcp port interrupt')
|
log.info('found pin now resetting mcp port interrupt')
|
||||||
await this.pin.interrupt.reset(packet.port)
|
|
||||||
if (!res.status) return {error:'no pin associated with interrupt'}
|
if (!res.status) return {error:'no pin associated with interrupt'}
|
||||||
let pin = byteFormat(res.status.port, { in: 'ARY', out: 'PLC' })
|
let pin = byteFormat(res.status.port, { in: 'ARY', out: 'PLC' })
|
||||||
res.pin = pin[0]
|
res.pin = pin[0]
|
||||||
packet.pins = pin[0]
|
packet.pins = pin[0]
|
||||||
packet.reg = null
|
packet.reg = null
|
||||||
|
if (packet.pins) { // avoid bad interrupt (i.e. no pin caused interrupt)
|
||||||
res.state = (await this.pin.status(packet)).status.pins[0][1]
|
res.state = (await this.pin.status(packet)).status.pins[0][1]
|
||||||
res.port = packet.port
|
res.port = packet.port
|
||||||
res.count = inter.count
|
res.count = inter.count
|
||||||
res.inter = inter.pin
|
res.inter = inter.pin
|
||||||
delete res.status
|
delete res.status
|
||||||
this.emit('interrupt',res)
|
this.emit('interrupt',res)
|
||||||
|
}
|
||||||
|
await this._reset(packet.port)
|
||||||
|
this.ready=true
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue