diff --git a/src/dpad.h b/src/dpad.h index 561aedf..ad8fa23 100644 --- a/src/dpad.h +++ b/src/dpad.h @@ -58,7 +58,9 @@ void updateDpad() if (!std::get(lastState) && std::get(state)) InputDispatcher::rotate(1); if (std::get(lastState) != std::get(state)) - InputDispatcher::button(std::get(state)); + InputDispatcher::confirmButton(std::get(state)); + if (std::get(lastState) != std::get(state)) + InputDispatcher::backButton(std::get(state)); lastState = state; } diff --git a/src/dpadHack.h b/src/dpadHack.h index f8e54fb..a8f9ddb 100644 --- a/src/dpadHack.h +++ b/src/dpadHack.h @@ -75,7 +75,9 @@ void updateDpadHack() if (!std::get(lastState) && std::get(state)) InputDispatcher::rotate(1); if (std::get(lastState) != std::get(state)) - InputDispatcher::button(std::get(state)); + InputDispatcher::confirmButton(std::get(state)); + if (std::get(lastState) != std::get(state)) + InputDispatcher::backButton(std::get(state)); lastState = state; } diff --git a/src/globals.h b/src/globals.h index cfc4932..6855776 100644 --- a/src/globals.h +++ b/src/globals.h @@ -42,8 +42,10 @@ Display *currentDisplay{}; int rotated{}; bool requestFullRedraw{}; -bool buttonLongPressed{}; -bool buttonPressed{}; +bool confirmButtonPressed{}; +bool confirmButtonLongPressed{}; +bool backButtonPressed{}; +bool backButtonLongPressed{}; class InputDispatcher { @@ -53,7 +55,7 @@ public: rotated += offset; } - static void button(bool pressed) + static void confirmButton(bool pressed) { static unsigned long pressBegin = 0; @@ -65,15 +67,36 @@ public: { const auto duration = now - pressBegin; - if (duration < 1000) - buttonPressed = true; - else if (duration < 3000) - buttonLongPressed = true; + if (duration < 500) + confirmButtonPressed = true; + else if (duration < 2000) + confirmButtonLongPressed = true; else requestFullRedraw = true; pressBegin = 0; } } + + static void backButton(bool pressed) + { + static unsigned long pressBegin = 0; + + const auto now = millis(); + + if (pressed) + pressBegin = now; + else + { + const auto duration = now - pressBegin; + + if (duration < 500) + backButtonPressed = true; + else + backButtonLongPressed = true; + + pressBegin = 0; + } + } }; } diff --git a/src/screens.h b/src/screens.h index ac9fe46..784b53b 100644 --- a/src/screens.h +++ b/src/screens.h @@ -345,15 +345,15 @@ void updateDisplay() currentDisplay->initScreen(); } - if (buttonLongPressed) + if (confirmButtonLongPressed) { - buttonLongPressed = false; + confirmButtonLongPressed = false; Serial.println("todo: implement long press"); } - if (buttonPressed) + if (confirmButtonPressed) { - buttonPressed = false; + confirmButtonPressed = false; if (currentDisplay) currentDisplay->button(); diff --git a/src/serialhandler.h b/src/serialhandler.h index 2396f43..8ed6e52 100644 --- a/src/serialhandler.h +++ b/src/serialhandler.h @@ -83,8 +83,12 @@ void handleSerial() InputDispatcher::rotate(1); break; case 'C': - InputDispatcher::button(true); - InputDispatcher::button(false); + InputDispatcher::confirmButton(true); + InputDispatcher::confirmButton(false); + break; + case 'D': + InputDispatcher::backButton(true); + InputDispatcher::backButton(false); break; } } diff --git a/src/webserver.h b/src/webserver.h index d0e1e23..3cc9b82 100644 --- a/src/webserver.h +++ b/src/webserver.h @@ -54,7 +54,7 @@ void initWebserver() { HtmlTag pTag{"p", content}; - content += "Up Down Confirm"; + content += "Up Down Confirm Back"; } if (auto constCurrentDisplay = static_cast(currentDisplay)) @@ -117,8 +117,17 @@ void initWebserver() }); webServer.on("/confirm", HTTP_GET, [](){ - InputDispatcher::button(true); - InputDispatcher::button(false); + InputDispatcher::confirmButton(true); + InputDispatcher::confirmButton(false); + + webServer.sendHeader("Connection", "close"); + webServer.sendHeader("Location", "/"); + webServer.send(302, "text/html", "ok"); + }); + + webServer.on("/back", HTTP_GET, [](){ + InputDispatcher::backButton(true); + InputDispatcher::backButton(false); webServer.sendHeader("Connection", "close"); webServer.sendHeader("Location", "/");