1
0
mirror of https://github.com/revspace/operame synced 2024-12-04 21:57:30 +00:00

Smarter debouncing; act after key release

This commit is contained in:
Juerd Waalboer 2020-12-27 19:37:39 +01:00
parent 1d7f5d2614
commit 5889fcdaa5

View File

@ -121,18 +121,21 @@ void setup_ota() {
ArduinoOTA.begin(); ArduinoOTA.begin();
} }
bool button(int pin) {
if (digitalRead(pin)) return false;
unsigned long start = millis();
while (!digitalRead(pin)) {
if (millis() - start >= 50) display_big("");
}
return millis() - start >= 50;
}
void check_portalbutton() { void check_portalbutton() {
if (digitalRead(portalbutton)) return; if (button(portalbutton)) WiFiSettings.portal();
delay(50);
if (digitalRead(portalbutton)) return;
WiFiSettings.portal();
} }
void check_demobutton() { void check_demobutton() {
if (digitalRead(demobutton)) return; if (button(demobutton)) ppm_demo();
delay(50);
if (digitalRead(demobutton)) return;
ppm_demo();
} }
void check_buttons() { void check_buttons() {
@ -166,10 +169,9 @@ void ppm_demo() {
delay(1000); delay(1000);
for (int p = 400; p < 1200; p++) { for (int p = 400; p < 1200; p++) {
display_ppm(p); display_ppm(p);
if (!digitalRead(demobutton)) { if (button(demobutton)) {
display_logo(); display_logo();
delay(500); delay(500);
while (!digitalRead(demobutton));
return; return;
} }
delay(30); delay(30);
@ -235,8 +237,8 @@ void setup() {
if (ota_enabled) WiFiSettings.onPortal = setup_ota; if (ota_enabled) WiFiSettings.onPortal = setup_ota;
WiFiSettings.onConnect = [] { WiFiSettings.onConnect = [] {
check_buttons();
display_big("Verbinden met WiFi...", TFT_BLUE); display_big("Verbinden met WiFi...", TFT_BLUE);
check_portalbutton();
return 50; return 50;
}; };
WiFiSettings.onFailure = [] { WiFiSettings.onFailure = [] {
@ -295,10 +297,7 @@ void setup() {
} }
if (ota_enabled) ArduinoOTA.handle(); if (ota_enabled) ArduinoOTA.handle();
if (!digitalRead(portalbutton)) { if (button(portalbutton)) ESP.restart();
delay(50);
if (!digitalRead(portalbutton)) ESP.restart();
}
}; };
if (wifi_enabled) WiFiSettings.connect(false, 15); if (wifi_enabled) WiFiSettings.connect(false, 15);