encodeur fix debounce
This commit is contained in:
parent
21294b7fbb
commit
743ca41758
@ -1,8 +1,13 @@
|
|||||||
#include "../include/SwitchableEncodeur.h"
|
#include "../include/SwitchableEncodeur.h"
|
||||||
|
|
||||||
IRAM_ATTR void switchEncoder() {
|
IRAM_ATTR void switchEncoder() {
|
||||||
|
static unsigned long last_interrupt_time = 0;
|
||||||
|
unsigned long interrupt_time = millis();
|
||||||
|
// If interrupts come faster than 200ms, assume it's a bounce and ignore
|
||||||
|
if (interrupt_time - last_interrupt_time > 200){
|
||||||
SwitchableEncodeur::getInstance()->addMenu();
|
SwitchableEncodeur::getInstance()->addMenu();
|
||||||
delay(200);
|
}
|
||||||
|
last_interrupt_time = interrupt_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwitchableEncodeur* SwitchableEncodeur::instance = nullptr;
|
SwitchableEncodeur* SwitchableEncodeur::instance = nullptr;
|
||||||
@ -43,6 +48,9 @@ bool SwitchableEncodeur::update() {
|
|||||||
if (newPosition != this->oldPosition || this->menu != this->oldMenu) {
|
if (newPosition != this->oldPosition || this->menu != this->oldMenu) {
|
||||||
this->oldMenu = this->menu;
|
this->oldMenu = this->menu;
|
||||||
this->oldPosition = newPosition;
|
this->oldPosition = newPosition;
|
||||||
|
if(this->oldPosition < 0){
|
||||||
|
this->oldPosition = 0;
|
||||||
|
}
|
||||||
sortie = true;
|
sortie = true;
|
||||||
}
|
}
|
||||||
return sortie;
|
return sortie;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user