41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
import Interrupt from '../src/interrupt'
|
|
|
|
const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
|
|
|
const IPIN = process.env.IPIN || 4
|
|
|
|
let interrupt = new Interrupt(IPIN,{id:'test-interrupt', wait:0, edge:'rising', resetInterval:1, reset:true})
|
|
|
|
interrupt.on('interrupt', packet => {
|
|
console.log('event: interrupt fired for',interrupt.pin_num)
|
|
console.log('count:', packet.count, 'state:',packet.state, 'cmd:',packet.cmd, 'data:',packet.data)
|
|
})
|
|
|
|
interrupt.on('interrupt.reset', packet => {
|
|
console.log('interrupt reset packet sent/emitted')
|
|
console.dir(packet)
|
|
})
|
|
|
|
;
|
|
(async () => {
|
|
|
|
await interrupt.init()
|
|
console.log('interrupt ready and waiting')
|
|
console.log('manual fire of interrupt with default hook')
|
|
interrupt.fire()
|
|
console.log('manual fire of interrupt via after changing hook')
|
|
|
|
interrupt.registerHook((packet) => {
|
|
packet.data='some hook added data'
|
|
console.log('custom hook data prop added:', packet.data)
|
|
return packet
|
|
})
|
|
|
|
interrupt.fire()
|
|
|
|
|
|
})().catch(err => {
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
process.kill(process.pid, 'SIGTERM')
|
|
})
|