Event is fired multiple times
YuriVivaldi opened this issue · 0 comments
YuriVivaldi commented
Hi, I'm using this library to read a button status via GPIO
The code is simply this:
class GpioCtrl{
emitter: EventEmitter
button = new Gpio(GPIO.BUTTON, 'in', 'both', { activeLow: true, debounceTimeout: 1000 });
constructor(event_emitter: EventEmitter) {
this.emitter = event_emitter
}
async setup(): Promise<void> {
this.button.watch((err, value) => {
console.debug('Btn event', value,'\nErr: ',err, Date.now())
if (err) { console.error(GpioEvents.button, err); throw err; }
else
this.emitter.emit(GpioEvents.button, value)
})
}
When run, this is the printout (the minus and plus are to show which are the events that should be fired, and which not):
(previous prints)
(missing print on activated gpio )
+ Btn event 0
Err: null 1683026447408
+ Btn event 1
Err: null 1683026451988
- Btn event 1
Err: null 1683026451995
+ Btn event 0
Err: null 1683026455587
- Btn event 0
Err: null 1683026455592
- Btn event 0
Err: null 1683026455595
+ Btn event 1
Err: null 1683026458666
- Btn event 1
Err: null 1683026458673
- Btn event 1
Err: null 1683026458676
- Btn event 1
Err: null 1683026458678
+ Btn event 0
Err: null 1683026461938
- Btn event 0
Err: null 1683026461942
- Btn event 0
Err: null 1683026461945
- Btn event 0
Err: null 1683026461950
- Btn event 0
Err: null 1683026461952
and keeps like that, firing each change in value more times ,i.e. :
- 1st change => prints nothing, should detect a 1 in the pin and fire an event
- 2nd change => fires one event, (as it should)
- 3rd change => fires two events, should fire a single event, value 1
- 4th change => fires three events, should fire a single event, value 0
- 5th change => fires four events, should fire a single event, value 1
- 6th change => fires five events, should fire a single event, value 0
Can anyone help me diagnose?
Thank you in advance