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))
|
if (!std::get<ButtonDown>(lastState) && std::get<ButtonDown>(state))
|
||||||
InputDispatcher::rotate(1);
|
InputDispatcher::rotate(1);
|
||||||
if (std::get<ButtonConfirm>(lastState) != std::get<ButtonConfirm>(state))
|
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;
|
lastState = state;
|
||||||
}
|
}
|
||||||
|
@@ -75,7 +75,9 @@ void updateDpadHack()
|
|||||||
if (!std::get<ButtonDown>(lastState) && std::get<ButtonDown>(state))
|
if (!std::get<ButtonDown>(lastState) && std::get<ButtonDown>(state))
|
||||||
InputDispatcher::rotate(1);
|
InputDispatcher::rotate(1);
|
||||||
if (std::get<ButtonConfirm>(lastState) != std::get<ButtonConfirm>(state))
|
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;
|
lastState = state;
|
||||||
}
|
}
|
||||||
|
@@ -42,8 +42,10 @@ Display *currentDisplay{};
|
|||||||
|
|
||||||
int rotated{};
|
int rotated{};
|
||||||
bool requestFullRedraw{};
|
bool requestFullRedraw{};
|
||||||
bool buttonLongPressed{};
|
bool confirmButtonPressed{};
|
||||||
bool buttonPressed{};
|
bool confirmButtonLongPressed{};
|
||||||
|
bool backButtonPressed{};
|
||||||
|
bool backButtonLongPressed{};
|
||||||
|
|
||||||
class InputDispatcher
|
class InputDispatcher
|
||||||
{
|
{
|
||||||
@@ -53,7 +55,7 @@ public:
|
|||||||
rotated += offset;
|
rotated += offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void button(bool pressed)
|
static void confirmButton(bool pressed)
|
||||||
{
|
{
|
||||||
static unsigned long pressBegin = 0;
|
static unsigned long pressBegin = 0;
|
||||||
|
|
||||||
@@ -65,15 +67,36 @@ public:
|
|||||||
{
|
{
|
||||||
const auto duration = now - pressBegin;
|
const auto duration = now - pressBegin;
|
||||||
|
|
||||||
if (duration < 1000)
|
if (duration < 500)
|
||||||
buttonPressed = true;
|
confirmButtonPressed = true;
|
||||||
else if (duration < 3000)
|
else if (duration < 2000)
|
||||||
buttonLongPressed = true;
|
confirmButtonLongPressed = true;
|
||||||
else
|
else
|
||||||
requestFullRedraw = true;
|
requestFullRedraw = true;
|
||||||
|
|
||||||
pressBegin = 0;
|
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();
|
currentDisplay->initScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buttonLongPressed)
|
if (confirmButtonLongPressed)
|
||||||
{
|
{
|
||||||
buttonLongPressed = false;
|
confirmButtonLongPressed = false;
|
||||||
Serial.println("todo: implement long press");
|
Serial.println("todo: implement long press");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buttonPressed)
|
if (confirmButtonPressed)
|
||||||
{
|
{
|
||||||
buttonPressed = false;
|
confirmButtonPressed = false;
|
||||||
|
|
||||||
if (currentDisplay)
|
if (currentDisplay)
|
||||||
currentDisplay->button();
|
currentDisplay->button();
|
||||||
|
@@ -83,8 +83,12 @@ void handleSerial()
|
|||||||
InputDispatcher::rotate(1);
|
InputDispatcher::rotate(1);
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
InputDispatcher::button(true);
|
InputDispatcher::confirmButton(true);
|
||||||
InputDispatcher::button(false);
|
InputDispatcher::confirmButton(false);
|
||||||
|
break;
|
||||||
|
case 'D':
|
||||||
|
InputDispatcher::backButton(true);
|
||||||
|
InputDispatcher::backButton(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -54,7 +54,7 @@ void initWebserver()
|
|||||||
{
|
{
|
||||||
HtmlTag pTag{"p", content};
|
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))
|
if (auto constCurrentDisplay = static_cast<const Display *>(currentDisplay))
|
||||||
@@ -117,8 +117,17 @@ void initWebserver()
|
|||||||
});
|
});
|
||||||
|
|
||||||
webServer.on("/confirm", HTTP_GET, [](){
|
webServer.on("/confirm", HTTP_GET, [](){
|
||||||
InputDispatcher::button(true);
|
InputDispatcher::confirmButton(true);
|
||||||
InputDispatcher::button(false);
|
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("Connection", "close");
|
||||||
webServer.sendHeader("Location", "/");
|
webServer.sendHeader("Location", "/");
|
||||||
|
Reference in New Issue
Block a user