add conPacket to each socket using the resetCmd option for the command and included the pin: key so the port can be looked up

master
David Kebler 2018-07-31 17:28:02 -07:00
parent cc75908894
commit e196083d5e
3 changed files with 4 additions and 9 deletions

View File

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

View File

@ -10,10 +10,10 @@ let log = {}
export default class Interrupt extends Base { export default class Interrupt extends Base {
constructor(pin,opts={}) { constructor(pin,opts={}) {
if (opts.path || opts.itrn ) { if (opts.path || opts.itrn ) {
opts.itrn = opts.itrn || {} opts.itrn = opts.itrn || {}
opts.itrn.path = opts.path || opts.itrn.path || 'interrupt:'+ pin opts.itrn.path = opts.path || opts.itrn.path || 'interrupt:'+ pin
opts.itrn.conPacket = opts.conPacket
opts.sockets = (opts.sockets ? (opts.sockets + ',') : '') + 'itrn#s>n' opts.sockets = (opts.sockets ? (opts.sockets + ',') : '') + 'itrn#s>n'
} }
if (opts.topics || opts.itrm) { if (opts.topics || opts.itrm) {
@ -30,6 +30,7 @@ export default class Interrupt extends Base {
if (opts.itrt || opts.port || !opts.sockets) { if (opts.itrt || opts.port || !opts.sockets) {
opts.itrt = opts.itrt || {} opts.itrt = opts.itrt || {}
opts.itrt.port = opts.itrt.port || opts.port || 9000+pin opts.itrt.port = opts.itrt.port || opts.port || 9000+pin
opts.itrt.conPacket = opts.conPacket
opts.sockets = (opts.sockets ? (opts.sockets + ',') : '') + 'itrt#s>t' opts.sockets = (opts.sockets ? (opts.sockets + ',') : '') + 'itrt#s>t'
} }
super(opts) super(opts)
@ -70,13 +71,6 @@ export default class Interrupt extends Base {
this.exit().then((resp) => console.log('\n', resp)) // unexport on cntrl-c this.exit().then((resp) => console.log('\n', resp)) // unexport on cntrl-c
.catch(err => console.log('error:', err)) .catch(err => console.log('error:', err))
}) })
// const pinDebounce = function (processor, wait, options, packet) {
// console.log(processor,wait,options,packet)
// return debounce.bind(this,processor.bind(this,packet),wait, options)
// return debounce.bind(processor.bind(this,packet),wait)
// return debounce.bind(null,processor,{ wait:wait})
// }
// else cb = pinDebounce(this.interruptProcess,this.wait,this.dbopts,this.packet)
let cb = () => {} let cb = () => {}
if (this.wait===0) { if (this.wait===0) {

View File

@ -17,6 +17,7 @@ export default class Interrupts {
pins.forEach (pin =>{ pins.forEach (pin =>{
pinopts[pin] = Object.assign({}, opts, pinopts[pin]) pinopts[pin] = Object.assign({}, opts, pinopts[pin])
pinopts[pin].id = (opts.id ||'interrupt') + ':' + pin pinopts[pin].id = (opts.id ||'interrupt') + ':' + pin
pinopts[pin].conPacket = { cmd:opts.resetCmd, pin:pin }
log.info({opts:pinopts[pin]},`pin options for pin ${pin}`) log.info({opts:pinopts[pin]},`pin options for pin ${pin}`)
this.interrupt[pin] = new Interrupt(pin,pinopts[pin]) this.interrupt[pin] = new Interrupt(pin,pinopts[pin])
}) })