2018-03-04 15:09:18 -08:00
|
|
|
import Interrupt from '../src/interrupt'
|
|
|
|
|
2019-03-14 10:43:09 -07:00
|
|
|
const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
2018-03-04 15:09:18 -08:00
|
|
|
|
2019-08-15 14:05:30 -07:00
|
|
|
const IPIN = process.env.IPIN || 4
|
|
|
|
|
2019-12-23 14:15:50 -08:00
|
|
|
const EDGE = process.env.EDGE || 'both'
|
2020-03-24 14:41:03 -07:00
|
|
|
// const REMOTE_HOST = process.env.REMOTE_HOST || 'sbc'
|
|
|
|
// const REMOTE_PORT = process.env.REMOTE_PORT || 9000
|
2019-12-23 14:15:50 -08:00
|
|
|
const PORT = process.env.PORT || 9000 + IPIN
|
|
|
|
|
|
|
|
let interrupt = new Interrupt(IPIN,{id:'test-interrupt', wait:0, edge:EDGE, resetInterval:1, reset:true})
|
2019-08-15 14:05:30 -07:00
|
|
|
|
|
|
|
interrupt.on('interrupt', packet => {
|
|
|
|
console.log('event: interrupt fired for',interrupt.pin_num)
|
2019-12-23 14:15:50 -08:00
|
|
|
console.log('count:', packet.count, ', state:',packet.state, ', cmd:',packet.cmd, ', data:',packet.data)
|
2019-08-15 14:05:30 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
interrupt.on('interrupt.reset', packet => {
|
|
|
|
console.log('interrupt reset packet sent/emitted')
|
|
|
|
console.dir(packet)
|
|
|
|
})
|
2018-03-04 15:09:18 -08:00
|
|
|
|
|
|
|
;
|
|
|
|
(async () => {
|
|
|
|
|
2019-08-15 14:05:30 -07:00
|
|
|
interrupt.registerHook((packet) => {
|
2019-12-23 14:15:50 -08:00
|
|
|
packet.data='a custom property <data> added to packet via hook'
|
|
|
|
// console.log('custom hook data prop added:', packet.data)
|
2018-07-31 10:05:13 -07:00
|
|
|
return packet
|
2019-08-15 14:05:30 -07:00
|
|
|
})
|
2019-12-23 14:15:50 -08:00
|
|
|
await interrupt.init()
|
2020-03-24 14:41:03 -07:00
|
|
|
// interrupt.addSocket('inter','c','t',{host:REMOTE_HOST, port:REMOTE_PORT})
|
2019-12-23 14:15:50 -08:00
|
|
|
interrupt.addSocket('inters','s','t',{port:PORT})
|
|
|
|
console.log(await interrupt.socketsInit())
|
|
|
|
console.log('interrupt ready and waiting')
|
2019-08-15 14:05:30 -07:00
|
|
|
|
2018-03-04 15:09:18 -08:00
|
|
|
|
|
|
|
})().catch(err => {
|
|
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
2018-07-31 10:05:13 -07:00
|
|
|
process.kill(process.pid, 'SIGTERM')
|
2018-03-04 15:09:18 -08:00
|
|
|
})
|