48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
import Interrupts from '../src/interrupts'
|
|
|
|
const PINS = [4]
|
|
|
|
let interrupts = new Interrupts(PINS,{id:'multi-interrupt-example', resetInterval:1, resetEnabled:false, 4:{name:'mybutton'} })
|
|
|
|
let hook = function (packet)
|
|
{
|
|
packet.cmd = 'interrupt.find'
|
|
return packet
|
|
}
|
|
|
|
// interrupts.registerHook(hook)
|
|
|
|
interrupts.on('status', ev => {
|
|
console.log(`STATUS:'--${ev.level}--" ${ev.msg}`)}
|
|
)
|
|
interrupts.on('consumer-connection', ev => {
|
|
console.log(`client ${ev.name} was ${ev.state}`)
|
|
})
|
|
|
|
interrupts.listen(function (packet) {
|
|
console.log(`============== ${this.id}=========`)
|
|
console.log(`emitted packet from interrupt ${packet.id}, pin:${packet.pin}`)
|
|
console.dir(packet)
|
|
this.push(packet)
|
|
console.log('------------------------')
|
|
})
|
|
|
|
|
|
interrupts.listenReset(function (packet) {
|
|
console.log(`============== ${this.id}=========`)
|
|
console.log('an interrupt reset request emitted')
|
|
console.dir(packet)
|
|
console.log('------------------------')
|
|
})
|
|
;
|
|
(async () => {
|
|
|
|
interrupts.addSocket('server','s','t')
|
|
await interrupts.init()
|
|
// interrupts.fire()
|
|
|
|
})().catch(err => {
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
// process.kill(process.pid, 'SIGTERM')
|
|
})
|