add mcp interrupt processing commands, find, reset

master
David Kebler 2018-02-23 21:16:35 -08:00
parent 5833f42464
commit cb1977a8ea
1 changed files with 19 additions and 5 deletions

View File

@ -99,14 +99,28 @@ export const pin = {
},
// will create packet to determine pin caused interrupt, packet will come from interrupt module
interrupt: {
find: async function (packet) {
console.log('interrupt fired',packet)
return Promise.resolve({cmd:null})
reset: async function (port) {
console.log('resetting interrupt for port', (port ? 'B' : 'A'))
return await this.bus.read(sreg(PIN.cmd.intcap,port))
},
find: async function (inter) {
console.log('lookup info on device and port for pin fired',inter.pin, inter.times)
let port = null
let packet = {pins:'all',reg:'intf', port:port}
let res = await this.pin.status(packet)
this.pin.interrupt.reset()
let pin = _.byteFormat(res.status.port, { in: 'ARY', out: 'PLC' })[0]
console.log('pin that caused the interrupt', pin)
// found it now tell someone what relay(s) to fire
res.pin = pin
res.times = inter.times
res.inter = inter.pin
return res
},
report: ()=>{}, // come here after determining which pin to report to requester
async: async ()=>{}
}
}
} // end pin.
const parsePins = function(pins) {
if (typeof pins==='number') pins = [pins]