0.2.17 enble reset on reconnect. change resetTimeout to resetInterval for timed reset enable

master
David Kebler 2019-04-23 07:41:40 -07:00
parent f132b1d271
commit 8f22017fd1
2 changed files with 9 additions and 10 deletions

View File

@ -1,7 +1,7 @@
{
"name": "@uci/interrupt",
"main": "src",
"version": "0.2.16",
"version": "0.2.17",
"description": "a class for adding interrupt processesing for gpio pins on Raspberry Pi and Similar SBCs",
"scripts": {
"single": "node -r esm examples/single",

View File

@ -93,16 +93,16 @@ class Interrupt extends Base {
log.debug({msg:'new interrupt pin created and watching', num:this.pin_num, status:await this.status() ? 'ready' : 'not ready', pin:this.pin, edge:this.edge,debounce:this.wait})
log.debug('setting reconnect listener')
this.socket.mcp.on('reconnected', () => console.log('test listen reconnected'))
console.log('setting connect listener')
this.consumersListen('reconnected', () => console.log('connected to a socket emit a reset'))
// await this.reset()
// })
this.consumersListen('reconnected', () => {
log.debug('reconnected to a socket send a reset request')
this.reset()
})
this.socket.mcp.emit('reconnected')
if (this.resetTimeout) setInterval(this.reset.bind(this),this.resetTimeout)
if (this.resetInterval) setInterval(this.commands.reset,this.resetInterval)
this.pin.watch( function (err,value) {
log.debug('sbc interrupt tripped, value:', value, 'error:', err)
@ -139,7 +139,7 @@ class Interrupt extends Base {
this.emit(this.resetCmd) // emit locally
await this.send(packet)
await this.push(packet)
log.debug({msg: `interrupt was reset. ready now? ${(await this.status()).ready}`})
log.error({msg: `interrupt was forced reset. ready now? ${(await this.status()).ready}`})
return {cmd:'reply', reset:true, ready: (await this.status()).ready}
}
return {cmd:'reply', reset:false, ready:true}
@ -157,9 +157,8 @@ class Interrupt extends Base {
if (this.hook) packet = await this._hookFunc.call(this,packet)
log.debug({packet: packet, msg:'interrupt tripped, emit/send/push packet to all connected/listening'})
this.emit('interrupt',packet) // emit locally
await this.send(packet) // will send a packet via client to any socket
this.send(packet) // will send a packet via client to any socket
this.push(packet) // will push on any socket
// if (this.resetTimeout) await this.reset() // extra insurance that interrupt got reset
}
registerHook(func) {