Implemented back button in input framework
This commit is contained in:
@@ -58,7 +58,9 @@ void updateDpad()
|
||||
if (!std::get<ButtonDown>(lastState) && std::get<ButtonDown>(state))
|
||||
InputDispatcher::rotate(1);
|
||||
if (std::get<ButtonConfirm>(lastState) != std::get<ButtonConfirm>(state))
|
||||
InputDispatcher::button(std::get<ButtonConfirm>(state));
|
||||
InputDispatcher::confirmButton(std::get<ButtonConfirm>(state));
|
||||
if (std::get<ButtonBack>(lastState) != std::get<ButtonBack>(state))
|
||||
InputDispatcher::backButton(std::get<ButtonBack>(state));
|
||||
|
||||
lastState = state;
|
||||
}
|
||||
|
@@ -75,7 +75,9 @@ void updateDpadHack()
|
||||
if (!std::get<ButtonDown>(lastState) && std::get<ButtonDown>(state))
|
||||
InputDispatcher::rotate(1);
|
||||
if (std::get<ButtonConfirm>(lastState) != std::get<ButtonConfirm>(state))
|
||||
InputDispatcher::button(std::get<ButtonConfirm>(state));
|
||||
InputDispatcher::confirmButton(std::get<ButtonConfirm>(state));
|
||||
if (std::get<ButtonBack>(lastState) != std::get<ButtonBack>(state))
|
||||
InputDispatcher::backButton(std::get<ButtonBack>(state));
|
||||
|
||||
lastState = state;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -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();
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ void initWebserver()
|
||||
{
|
||||
HtmlTag pTag{"p", content};
|
||||
|
||||
content += "<a href=\"/up\">Up</a> <a href=\"/down\">Down</a> <a href=\"/confirm\">Confirm</a>";
|
||||
content += "<a href=\"/up\">Up</a> <a href=\"/down\">Down</a> <a href=\"/confirm\">Confirm</a> <a href=\"/Back\">Back</a>";
|
||||
}
|
||||
|
||||
if (auto constCurrentDisplay = static_cast<const Display *>(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", "/");
|
||||
|
Reference in New Issue
Block a user