set "both" as default so on or off triggers
parent
19ea1f88ff
commit
846979a48f
|
@ -19,15 +19,15 @@ class Interrupt extends EventEmitter {
|
||||||
this.num = pin_number;
|
this.num = pin_number;
|
||||||
this.hook = opts.hook // will be passed back with the emit
|
this.hook = opts.hook // will be passed back with the emit
|
||||||
this.path = GPIO_ROOT_PATH + 'gpio' + this.num + '/'
|
this.path = GPIO_ROOT_PATH + 'gpio' + this.num + '/'
|
||||||
this.edge = opts.edge // default 'falling'
|
this.edge = opts.edge // default 'both'
|
||||||
this.delay = opts.delay // default = 50
|
this.delay = opts.delay // default = 50
|
||||||
this.pullup = opts.pullup ? opts.pullup : (num, state) => { return `raspi-gpio set ${num} ${state}` } // default rpi using raspi-gpio
|
this.pullup = opts.pullup ? opts.pullup : (num, state) => { return `raspi-gpio set ${num} ${state}` } // default rpi using raspi-gpio
|
||||||
// this.pullup = (num, state) => { return `raspi-gpio set ${num} ${state}` }
|
// this.pullup = (num, state) => { return `raspi-gpio set ${num} ${state}` }
|
||||||
this.dbt = opts.debounce ? opts.debounce : 300
|
this.dbt = opts.debounce ? opts.debounce : 200
|
||||||
this.poller = new Epoll(
|
this.poller = new Epoll(
|
||||||
debounce((err, fd, events) => {
|
debounce((err, fd, events) => {
|
||||||
if (err) { this.emit('error', err) } else { this.clear().then(this.emit('fired', this.hook)) }
|
if (err) { this.emit('error', err) } else { this.clear().then(this.emit('fired', this.hook)) }
|
||||||
}, this.dbt, true)
|
}, this.dbt, true) // true = leading
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class Interrupt extends EventEmitter {
|
||||||
this._pull(this.num),
|
this._pull(this.num),
|
||||||
this._export(this.num),
|
this._export(this.num),
|
||||||
this._direction('in', this.delay),
|
this._direction('in', this.delay),
|
||||||
() => this._edge(this.edge),
|
() => this._edge(this.edge), // TODO determine why these need additional function
|
||||||
() => this._fd(),
|
() => this._fd(),
|
||||||
() => this.clear().then(() => {
|
() => this.clear().then(() => {
|
||||||
this.start()
|
this.start()
|
||||||
|
@ -95,7 +95,7 @@ class Interrupt extends EventEmitter {
|
||||||
this.poller.remove(this.valuefd).close();
|
this.poller.remove(this.valuefd).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************/
|
/*******private methods*********/
|
||||||
|
|
||||||
_pull(num, state = 'pu') {
|
_pull(num, state = 'pu') {
|
||||||
if (this.pullup === 'external') { return Promise.resolve('pull must be set externally') } else {
|
if (this.pullup === 'external') { return Promise.resolve('pull must be set externally') } else {
|
||||||
|
@ -131,7 +131,7 @@ class Interrupt extends EventEmitter {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
_edge(edge = 'falling') {
|
_edge(edge = 'both') {
|
||||||
return fs.writeFile(this.path + 'edge', edge)
|
return fs.writeFile(this.path + 'edge', edge)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return Promise.resolve('edge set')
|
return Promise.resolve('edge set')
|
||||||
|
|
Loading…
Reference in New Issue