menu overflow implemented and other improvements
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
// Arduino includes
|
||||
#include <Arduino.h>
|
||||
// system includes
|
||||
#include <optional>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <espchrono.h>
|
||||
|
||||
// local includes
|
||||
@ -18,14 +19,64 @@ bool confirmButtonLongPressed{};
|
||||
bool backButtonPressed{};
|
||||
bool backButtonLongPressed{};
|
||||
|
||||
std::optional<espchrono::millis_clock::time_point> upPressedSince;
|
||||
int upPressRepeat{};
|
||||
std::optional<espchrono::millis_clock::time_point> downPressedSince;
|
||||
int downPressRepeat{};
|
||||
|
||||
class InputDispatcher
|
||||
{
|
||||
public:
|
||||
static void update()
|
||||
{
|
||||
if (upPressedSince && espchrono::ago(*upPressedSince) > (upPressRepeat > 3 ? 100ms : 500ms))
|
||||
{
|
||||
upPressedSince = espchrono::millis_clock::now();
|
||||
upPressRepeat++;
|
||||
rotated -= 1;
|
||||
}
|
||||
|
||||
if (downPressedSince && espchrono::ago(*downPressedSince) > (downPressRepeat > 3 ? 100ms : 500ms))
|
||||
{
|
||||
downPressedSince = espchrono::millis_clock::now();
|
||||
downPressRepeat++;
|
||||
rotated += 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void rotate(int offset)
|
||||
{
|
||||
rotated += offset;
|
||||
}
|
||||
|
||||
static void upButton(bool pressed)
|
||||
{
|
||||
if (pressed)
|
||||
{
|
||||
upPressedSince = espchrono::millis_clock::now();
|
||||
upPressRepeat = 0;
|
||||
rotated -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
upPressedSince = std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
static void downButton(bool pressed)
|
||||
{
|
||||
if (pressed)
|
||||
{
|
||||
downPressedSince = espchrono::millis_clock::now();
|
||||
downPressRepeat = 0;
|
||||
rotated += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
downPressedSince = std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
static void confirmButton(bool pressed)
|
||||
{
|
||||
static espchrono::millis_clock::time_point pressBegin{};
|
||||
|
@ -177,12 +177,10 @@ bool parseBoardcomputerCanMessage(const twai_message_t &message)
|
||||
};
|
||||
|
||||
if (lastButtonsState.up != newState.up)
|
||||
if (newState.up)
|
||||
InputDispatcher::rotate(-1);
|
||||
InputDispatcher::upButton(newState.up);
|
||||
|
||||
if (lastButtonsState.down != newState.down)
|
||||
if (newState.down)
|
||||
InputDispatcher::rotate(1);
|
||||
InputDispatcher::downButton(newState.down);
|
||||
|
||||
if (lastButtonsState.confirm != newState.confirm)
|
||||
InputDispatcher::confirmButton(newState.confirm);
|
||||
|
@ -67,15 +67,13 @@ void update()
|
||||
|
||||
if (std::get<ButtonUp>(lastState) != std::get<ButtonUp>(state) && now-debounceUp > settings.boardcomputerHardware.dpadDebounce)
|
||||
{
|
||||
if (std::get<ButtonUp>(state))
|
||||
InputDispatcher::rotate(-1);
|
||||
InputDispatcher::upButton(std::get<ButtonUp>(state));
|
||||
std::get<ButtonUp>(lastState) = std::get<ButtonUp>(state);
|
||||
debounceUp = now;
|
||||
}
|
||||
if (std::get<ButtonDown>(lastState) != std::get<ButtonDown>(state) && now-debounceDown > settings.boardcomputerHardware.dpadDebounce)
|
||||
{
|
||||
if (std::get<ButtonDown>(state))
|
||||
InputDispatcher::rotate(1);
|
||||
InputDispatcher::downButton(std::get<ButtonDown>(state));
|
||||
std::get<ButtonDown>(lastState) = std::get<ButtonDown>(state);
|
||||
debounceDown = now;
|
||||
}
|
||||
|
@ -81,15 +81,13 @@ void update()
|
||||
|
||||
if (std::get<ButtonUp>(lastState) != std::get<ButtonUp>(state) && now-debounceUp > settings.boardcomputerHardware.dpadDebounce)
|
||||
{
|
||||
if (std::get<ButtonUp>(state))
|
||||
InputDispatcher::rotate(-1);
|
||||
InputDispatcher::upButton(std::get<ButtonUp>(state));
|
||||
std::get<ButtonUp>(lastState) = std::get<ButtonUp>(state);
|
||||
debounceUp = now;
|
||||
}
|
||||
if (std::get<ButtonDown>(lastState) != std::get<ButtonDown>(state) && now-debounceDown > settings.boardcomputerHardware.dpadDebounce)
|
||||
{
|
||||
if (std::get<ButtonDown>(state))
|
||||
InputDispatcher::rotate(1);
|
||||
InputDispatcher::downButton(std::get<ButtonDown>(state));
|
||||
std::get<ButtonDown>(lastState) = std::get<ButtonDown>(state);
|
||||
debounceDown = now;
|
||||
}
|
||||
|
@ -122,15 +122,13 @@ void update()
|
||||
|
||||
if (lastState.up != newState.up && now - debounceUp > dpadDebounce)
|
||||
{
|
||||
if (newState.up)
|
||||
InputDispatcher::rotate(-1);
|
||||
InputDispatcher::upButton(newState.up);
|
||||
debounceUp = now;
|
||||
}
|
||||
|
||||
if (lastState.down != newState.down && now - debounceDown > dpadDebounce)
|
||||
{
|
||||
if (newState.down)
|
||||
InputDispatcher::rotate(1);
|
||||
InputDispatcher::downButton(newState.down);
|
||||
debounceDown = now;
|
||||
}
|
||||
|
||||
|
@ -318,6 +318,8 @@ extern "C" void app_main()
|
||||
lastWifiUpdate = now;
|
||||
}
|
||||
|
||||
InputDispatcher::update();
|
||||
|
||||
#ifdef FEATURE_DPAD
|
||||
dpad::update();
|
||||
#endif
|
||||
|
@ -168,9 +168,9 @@ void MenuDisplay::update()
|
||||
m_selectedIndex = m_selectedIndex + offset;
|
||||
|
||||
if (m_selectedIndex < 0)
|
||||
m_selectedIndex = 0;
|
||||
m_selectedIndex += itemCount;
|
||||
if (m_selectedIndex >= itemCount)
|
||||
m_selectedIndex = itemCount - 1;
|
||||
m_selectedIndex -= itemCount;
|
||||
|
||||
if (m_selectedIndex < m_scrollOffset)
|
||||
m_scrollOffset = m_selectedIndex;
|
||||
|
Reference in New Issue
Block a user