Files
bobbycar-boardcomputer-firm…/main/bobbybuttons.cpp
T

106 lines
2.9 KiB
C++
Raw Normal View History

2021-12-28 13:41:12 +01:00
#include "bobbybuttons.h"
// esp-idf includes
#include <esp_log.h>
2021-12-30 00:00:31 +01:00
// local includes
#include "newsettings.h"
#include "settingsutils.h"
2022-01-17 13:02:57 +01:00
#include "modes/defaultmode.h"
#include "ledstripdefines.h"
#include "ledstrip.h"
2022-01-05 01:21:42 +01:00
#include "bobbyquickactions.h"
namespace {
constexpr const char TAG[] = "BUTTONS";
} // namespace
2021-12-30 00:00:31 +01:00
2021-12-29 19:50:45 +01:00
[[nodiscard]] std::optional<espgui::Button> translateRawButton(uint8_t button)
2021-12-28 13:41:12 +01:00
{
2021-12-30 00:00:31 +01:00
// Invalid
if (button == INPUT_MAPPING_NONE)
return std::nullopt;
2021-12-28 13:41:12 +01:00
using espgui::Button;
2021-12-30 00:00:31 +01:00
if (configs.dpadMappingLeft.value == button)
return Button::Left;
if (configs.dpadMappingRight.value == button)
return Button::Right;
if (configs.dpadMappingUp.value == button)
return Button::Up;
if (configs.dpadMappingDown.value == button)
return Button::Down;
if (configs.dpadMappingProfile0.value == button)
return Button(BobbyButton::Profile0);
if (configs.dpadMappingProfile1.value == button)
return Button(BobbyButton::Profile1);
if (configs.dpadMappingProfile2.value == button)
return Button(BobbyButton::Profile2);
if (configs.dpadMappingProfile3.value == button)
return Button(BobbyButton::Profile3);
if (configs.dpadMappingLeft2.value == button)
return Button(BobbyButton::Left2);
if (configs.dpadMappingRight2.value == button)
return Button(BobbyButton::Right2);
if (configs.dpadMappingUp2.value == button)
return Button(BobbyButton::Up2);
if (configs.dpadMappingDown2.value == button)
return Button(BobbyButton::Down2);
2021-12-29 18:09:57 +01:00
ESP_LOGW(TAG, "unknown raw button %hhu", button);
2021-12-29 18:09:57 +01:00
return std::nullopt;
2021-12-28 13:41:12 +01:00
}
2021-12-29 18:09:57 +01:00
void buttonPressedCommon(espgui::Button button)
2021-12-28 13:41:12 +01:00
{
switch (BobbyButton(button))
{
case BobbyButton::Profile0:
settingsutils::switchProfile(0);
break;
case BobbyButton::Profile1:
settingsutils::switchProfile(1);
break;
case BobbyButton::Profile2:
settingsutils::switchProfile(2);
break;
case BobbyButton::Profile3:
settingsutils::switchProfile(3);
break;
2022-01-05 01:21:42 +01:00
case BobbyButton::Left2:
case BobbyButton::Right2:
case BobbyButton::Up2:
case BobbyButton::Down2:
2022-01-05 01:21:42 +01:00
quickactions::handle_bobby_quickaction(button);
break;
2021-12-28 13:41:12 +01:00
default:;
}
}
2021-12-29 18:09:57 +01:00
void BobbyButtons::rawButtonPressed(uint8_t button)
{
//Base::rawButtonPressed(button);
if (const auto translated = translateRawButton(button))
buttonPressed(*translated);
}
void BobbyButtons::rawButtonReleased(uint8_t button)
{
//Base::rawButtonReleased(button);
if (const auto translated = translateRawButton(button))
buttonReleased(*translated);
}
void BobbyButtons::buttonPressed(espgui::Button button)
{
//Base::buttonPressed(button);
buttonPressedCommon(button);
}
2021-12-28 13:41:12 +01:00
void BobbyButtons::buttonReleased(espgui::Button button)
{
//Base::buttonReleased(button);
}