uci-interrupt/lib/interrupt.js

33 lines
690 B
JavaScript

'use strict'
const Gpio = require('onoff').Gpio
// **********************************
class Interrupt {
// bus is i2c-bus bus object
constructor(pin_number, processor, opts = {}) {
let dtimeout = opts.debounceTimeout ? opts.debounceTimeout : 200
this.pin = new Gpio(pin_number, 'in', 'falling', { debounceTimeout: dtimeout })
this.processor = processor
}
init() {
this.addListener(this.processor)
process.on('SIGINT', function () {
this.pin.unexport();
})
}
addListener(processor) {
this.pin.watch((err, value) => {
if (err) { return Promise.reject(err) }
return processor
});
}
}
module.exports.Interrupt = Interrupt