From cb1977a8ea8715ca4bfe28736e6a31387cddac51 Mon Sep 17 00:00:00 2001 From: David Kebler Date: Fri, 23 Feb 2018 21:16:35 -0800 Subject: [PATCH] add mcp interrupt processing commands, find, reset --- src/commands.mjs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/commands.mjs b/src/commands.mjs index 2ea995a..f5c923a 100644 --- a/src/commands.mjs +++ b/src/commands.mjs @@ -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]