removed removed this.pins to revert back to using this.commands.pins

emit locally on interrupt
master
David Kebler 2019-04-20 16:44:32 -07:00
parent ea9a04f6dc
commit 7e0327ebf0
3 changed files with 20 additions and 49 deletions

View File

@ -51,7 +51,7 @@ export default {
for(let name of Object.keys(PIN.setting)) {
let op = cfg[name] ? 'on' : 'off'
log.debug({msg:'setting pin register', operation:op, registerName:name, resgisterNum:PIN.setting[name]})
let busreply = await this.pin._state(packet,op,PIN.setting[name])
let busreply = await this.commands.pin._state(packet,op,PIN.setting[name])
if (busreply.error) return busreply
reply.status[name] = busreply.status
}
@ -98,13 +98,13 @@ export default {
// threse three only for output pins
state : {
on: async function (packet) {
return this.pin._state(packet,'on')
return this.commands.pin._state(packet,'on')
},
off: async function (packet) {
return this.pin._state(packet,'off')
return this.commands.pin._state(packet,'off')
},
toggle: async function (packet) {
return this.pin._state(packet,'toggle')
return this.commands.pin._state(packet,'toggle')
}
}
} // end pin.

View File

@ -18,19 +18,19 @@ class MCP230XX extends Device {
this.chipCfg = opts.chipCfg || 'default'
this.commands = this.bindFuncs(commands)
this.addNamespace('commands', 's') // allow access to commands via socket/server
this.pin = this.commands.pin // add a simplier reference for local access
this.chipcfg = this.commands.chip.cfg // add a simplier reference for local access
// this._pin = this.commands.pin // add a simplier reference for local access
// this._chipcfg = this.commands.chip.cfg // add a simplier reference for local access
}
async init() {
await super.init()
let res = await this.chipcfg({cfg:this.chipCfg})
let res = await this.commands.chip.cfg({cfg:this.chipCfg})
if (res.error) {
log.fatal({msg:'unable to configure mcp chip', error:res.error, cfg:this.chipCfg, address:this.address})
throw `${res.error} at address ${this.address}/${this.address.toString(16)}`
}
await this.commands.pin.cfg({pins:'all'}) //pins are outputs by default
if (this.chip17) await this.commands.pin.cfg({pins:'all', port:'B'})
if (this.chip17) await this.commands.pin.cfg({pins:'all', port:'B'})
}
} // end of MCP230XX Class

View File

@ -19,41 +19,6 @@ class MCP230XXi extends MCP230XX {
if (opts.interrupt) delete opts.interrupt.pins // if .interrupt was passed then .pins must be removed
delete opts.sockets // .sockets is used by uci base so clear it if was used by enduser and sent by mistake
log.debug({msg:'passed options before setting',options:opts})
// if options doesn't contain a pin number key with mport and other interrupt pin related information
// then it is assume that pins[0] is port A and pins[1] is port B
// 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'
// opts.inter = { port: opts.iport }
// opts.inter.host = opts.ihost || opts.host
// }
// if (opts.ipath) {
// opts.inter = { path: opts.ipath || 'interrupt' }
// 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] || Object.assign({},opts.interrupt) || {}
// if (index === 1) opts[ipin].mport = opts[ipin].mport || 'B'
// delete opts[pin]
// if (opts[ipin].host) {
// opts[ipin].port = opts[ipin].port ? opts[ipin].port + +pin : 9000 + parseInt(pin)
// opts[ipin].host = opts[ipin].host
// opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + ipin + '#c>t'
// }
// // no host will make a pipe by default
// else {
// opts[ipin].path = (opts[ipin].path || 'interrupt') + ':'+ pin
// opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + ipin + '#c>n'
// }
// })
// }
super(opts)
this.opts = opts
@ -82,11 +47,11 @@ class MCP230XXi extends MCP230XX {
if (this.iport) await this.addSocket('inter-t','s','t',{port:this.iport})
await super.init()
// this will set default type to internal pullup, only need to to change indivial pins to external if desired
await this.pin.cfg({port:'A',pins:'all',cfg:'input_interrupt'})
await this.commands.pin.cfg({port:'A',pins:'all',cfg:'input_interrupt'})
let status = await this._resetInterrupt('A')
log.debug('configure all port A pins as interrupts. Reset port A interrupt', status)
if (this.chip17) {
await this.pin.cfg({port:'B',pins:'all',cfg:'input_interrupt'})
await this.commands.pin.cfg({port:'B',pins:'all',cfg:'input_interrupt'})
let status = await this._resetInterrupt('B')
log.debug('configure all port B pins as interrupts. Reset port B interrupt', status)
}
@ -106,6 +71,7 @@ class MCP230XXi extends MCP230XX {
async _resetInterrupt(port) {
log.debug(`resetting interrupt for port ${port || 'A'},${this.id} arg ${port !== 'B' ? 0x08 : 0x18}`)
await this.bus.read(port !== 'B' ? 0x08 : 0x18) // 0x08 is intcap interrupt capture register
console.log('reset interrupt==============')
return(await this._readyInterrupt(port))
}
@ -153,14 +119,16 @@ const icommands = {
},
// given a gpio interrupt then push a packet with cmd: 'pin.interrupt.find' and pin: the gpio pin number
find: async function(inter) {
console.log('interrupt find calledxxxxx', inter, this.ready)
if (this.ready) {
// protects tripped interrupt before it's fully initialized, or interrupt requests arriving before porcessing is complete
this.ready = false
log.debug({msg:'raw packet from interrupt, finding pin that caused interrupt', inter:inter})
let packet = { pins: 'all', reg: 'intf' }
packet.port = inter.port || this._getPortByPin(inter.pin)
let res = await this.pin.status(packet) // read port interrupt status
let res = await this.commands.pin.status(packet) // read port interrupt status
let status = await this._resetInterrupt(packet.port)
// console.log('interrupt reset ready?', status)
log.debug({interrupt:res, reset:status, msg:'interrupt read and reset'})
this.ready = true
if (!res.status) {
@ -177,9 +145,12 @@ const icommands = {
delete inter.cmd; delete inter._header; delete inter.pin
Object.assign(res,inter)
delete res.status
res.state = (await this.pin.status(packet)).status.pins[0][1]
log.debug('emit/call interrupt details processing', res)
this.emit('mcpInterrupt',Object.assign({},res)) // emit for end user purposes, don't allow mutation
res.interrupt_ready = status || false
res.state = (await this.commands.pin.status(packet)).status.pins[0][1]
// console.log('emitting local on interrupt')
this.emit('interrupt',Object.assign({},res)) // emit for end user purposes, don't allow mutation
// this.emit('interrupt') // emit for end user purposes, don't allow mutation
// console.log('============emitted now calling processor=======================================')
this._interruptProcess(res)
return res
} else {