0.3.3 Bug fix - Make sure that the number key for the interrupts map is ALWAYS a number even if string is passed

master
David Kebler 2020-07-26 17:29:24 -07:00
parent a3d23947cb
commit 7b8d5d7552
5 changed files with 71 additions and 5 deletions

38
examples/multi.js.old Normal file
View File

@ -0,0 +1,38 @@
import Interrupts from '../src/interrupts'
const PINS = [process.env.PIN1 || 9 ,process.env.PIN2 || 10]
const EDGE = process.env.EDGE || 'rising' // 'both'
// outbound consumer
const REMOTE_HOST = process.env.REMOTE_HOST || 'sbc'
const REMOTE_PORT = process.env.REMOTE_PORT || 9001
const PATH = process.env.PATH || 'mcp'
const LISTEN_TCP = process.env.LISTEN_TCP || '8020'
const LISTEN_PATH = process.env.LISTEN_PATH || 'interrupt'
let interrupts = new Interrupts(PINS, { id:'multi-interrupt', cmd:'interrupt.find', resetCmd:'interrupt.reset', resetInterval:0, edge:EDGE })
interrupts.amendConsumerCommands( {reply:() => {}} )
interrupts.on('log', ev => {
if (ev.level !== 'debug' && ev.level !== 'trace') console.log(`LOG:'--${ev.level}-- ${ev.msg}`)
// console.log(`LOG:'--${ev.level}-- ${ev.msg}`)
})
interrupts.on('connection:socket', ev => {
console.log(`remote socket connection event ${ev.socketName}: ${ev.state}`)
})
;
(async () => {
// interrupts.registerSocket('interrupt','c','t',{host:REMOTE_HOST, port:REMOTE_PORT, name:'interrupt', data:{pins:PINS, type:'interrupt'}})
interrupts.registerSocket('interrupt','c','n',{path:PATH, name:'interrupt', data:{name:'interrupt', pins:PINS, type:'interrupt'}})
// interrupts.registerSocket('listen','s','t',{port:1777})
await interrupts.init()
await interrupts.socketsInit()
})().catch(err => {
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
// process.kill(process.pid, 'SIGTERM')
})

20
examples/multi.yaml Normal file
View File

@ -0,0 +1,20 @@
name: interrupt
path: interrupt # make a named pipe socket (listnerer)
sockets: # make a consumer to the mcp device
- name: switches
type: c
transport: n
options:
data:
id: interrupt
name: interrupt # name of consumer
initTimeout: 0
retryWait: 5
path: switches # pipe at which to connect
pins:
- 24
resetCmd: reset # command that will be pushed
resetInterval: 0 # will broadcast a generic reset request, 0 is disabled
interruptCmd: find # command that will be pushed on all consumers/sockets
edge: rising
pull: down

5
nodemon.json Normal file
View File

@ -0,0 +1,5 @@
{
"ignoreRoot": [".git"],
"watch": ["node_modules/@uci/","node_modules/@uci-utils/","src/","examples/"],
"ext":"js,json,yaml,yml"
}

View File

@ -1,7 +1,7 @@
{
"name": "@uci/interrupt",
"main": "src",
"version": "0.3.2",
"version": "0.3.3",
"description": "a class for adding interrupt processesing for gpio pins on Raspberry Pi and Similar SBCs",
"scripts": {
"single": "node -r esm examples/single",
@ -34,7 +34,7 @@
"homepage": "https://github.com/uCOMmandIt/uci-interrrupt#readme",
"dependencies": {
"@uci-utils/logger": "^0.0.18",
"@uci/base": "^0.5.2",
"@uci/base": "^0.5.4",
"death": "^1.1.0",
"onoff": "^6.0.0"
},

View File

@ -22,13 +22,13 @@ class Interrupts extends Base {
intervalReset:makefunc.bind(this,'intervalReset')
})
let pinopts = {}
pins.forEach(pin => {
this.pins.forEach(pin => {
// remove per pin opts and store
pinopts[pin] = Object.assign({}, opts[pin])
delete opts[pin]
pinopts[pin].multiple=true // each pin will only extend a simple emitter, uci-base
})
pins.forEach(pin => {
this.pins.forEach(pin => {
pinopts[pin] = Object.assign({}, opts, pinopts[pin])
pinopts[pin].id = pinopts[pin].id || this.id + ':' + pin
log.debug({ opts: pinopts[pin], method:'constructor', line:25, msg:`pin options for pin ${pin}`})
@ -60,7 +60,10 @@ class Interrupts extends Base {
} // end constructor
interrupt(pin) { return this._interrupts.get(Number(pin)) } // get a handle to single interrupt
interrupt(pin) {
if (isNaN(pin)) return null
return this._interrupts.get(Number(pin))
} // pin type here same as when instantiated above.
async init() {
await super.init()