diff --git a/package.json b/package.json index 3f16b0f..c28b935 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@uci/interrupt", "main": "src", - "version": "0.2.24", + "version": "0.2.25", "description": "a class for adding interrupt processesing for gpio pins on Raspberry Pi and Similar SBCs", "scripts": { "single": "node -r esm examples/single", diff --git a/src/interrupt.js b/src/interrupt.js index 6ed9bbe..1081a80 100644 --- a/src/interrupt.js +++ b/src/interrupt.js @@ -65,6 +65,8 @@ class Interrupt extends Base { this.emit('log',{level:'info', msg:`new interrupt pin ${this.pin_num} created and watching`, state:await this.status(), edge:this.edge,debounce:this.wait}) + super.init() + } // end init // manual firing for testing @@ -90,17 +92,13 @@ class Interrupt extends Base { } async intervalReset(packet) { - // console.log('intervalReset ---- passed argument',packet) let interval = typeof packet === 'number'? packet : (packet || {}).interval - console.log('----------intervalReset--------', this.pin_num, interval) if (!interval || interval<=0) { clearInterval(this._intervalReset) this._intervalReset = null - console.log('---------disabled--------') } else { this._intervalReset = setInterval(this.reset.bind(this), interval*1000) - console.log('----------enabled----------') } return this._intervalReset ? true : false } diff --git a/src/interrupts.js b/src/interrupts.js index 8a6a181..b738b84 100644 --- a/src/interrupts.js +++ b/src/interrupts.js @@ -3,7 +3,6 @@ import Base from '@uci/base' import logger from '@uci-utils/logger' let log = {} - // will more easily create a group of sbc pin interrupts class Interrupts extends Base { @@ -70,7 +69,7 @@ class Interrupts extends Base { interrupt(pin) { return this._interrupts.get(Number(pin)) } // get a handle to single interrupt async init() { - + super.init() return Promise.all( Array.from(this._interrupts).map(inter => { return inter[1].init() @@ -78,7 +77,6 @@ class Interrupts extends Base { ) } - // only adds consumer sockets to each interrupt to same socket/server // alternatively use listen handler and single socket async addInterSocket(name,type) { @@ -99,14 +97,17 @@ class Interrupts extends Base { export default Interrupts - async function makefunc(fn, packet={}) { if (!packet.pin || packet.pin==='all') { - let res = {} + let rpacket = {pins:[]} for (let inter of this._interrupts.entries()) { - res[inter[0]] = await inter[1][fn](packet) + let ipacket = Object.assign({},packet) + delete(ipacket.cmd);delete(ipacket._header) + let res = await inter[1][fn](ipacket) + res.pin = inter[0] + rpacket.pins.push(res) } - return Object.assign(packet,res) + return rpacket } let pin = isNaN(Number(packet)) ? packet.pin : packet if (this._interrupts.has(Number(pin))) return await this.interrupt(packet.pin)[fn](packet)