Calibrate display save button configs
This commit is contained in:
@ -3,6 +3,16 @@
|
|||||||
// esp-idf includes
|
// esp-idf includes
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <tftinstance.h>
|
||||||
|
#include <fmt/core.h>
|
||||||
|
#include <screenmanager.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "newsettings.h"
|
||||||
|
#include "displays/menus/boardcomputerhardwaresettingsmenu.h"
|
||||||
|
#include "bobbyerrorhandler.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr const char TAG[] = "BUTTON";
|
constexpr const char TAG[] = "BUTTON";
|
||||||
} // namespace
|
} // namespace
|
||||||
@ -20,54 +30,98 @@ void ButtonCalibrateDisplay::start()
|
|||||||
currentMode = &m_mode;
|
currentMode = &m_mode;
|
||||||
m_lastButton = std::nullopt;
|
m_lastButton = std::nullopt;
|
||||||
m_status = WaitingLeft;
|
m_status = WaitingLeft;
|
||||||
|
|
||||||
|
m_finished = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonCalibrateDisplay::initScreen()
|
void ButtonCalibrateDisplay::initScreen()
|
||||||
{
|
{
|
||||||
Base::initScreen();
|
Base::initScreen();
|
||||||
|
|
||||||
m_label.start();
|
m_labelInstruction.start();
|
||||||
|
m_labelLeft.start();
|
||||||
|
m_labelRight.start();
|
||||||
|
m_labelUp.start();
|
||||||
|
m_labelDown.start();
|
||||||
|
m_labelEnd.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonCalibrateDisplay::update()
|
void ButtonCalibrateDisplay::update()
|
||||||
{
|
{
|
||||||
Base::update();
|
Base::update();
|
||||||
|
|
||||||
|
if (m_finished)
|
||||||
|
{
|
||||||
|
m_finished = false;
|
||||||
|
|
||||||
|
if (auto result = configs.write_config(configs.dpadMappingLeft, m_leftButton); !result)
|
||||||
|
{
|
||||||
|
BobbyErrorHandler{}.errorOccured(std::move(result).error());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (auto result = configs.write_config(configs.dpadMappingRight, m_rightButton); !result)
|
||||||
|
{
|
||||||
|
BobbyErrorHandler{}.errorOccured(std::move(result).error());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (auto result = configs.write_config(configs.dpadMappingUp, m_upButton); !result)
|
||||||
|
{
|
||||||
|
BobbyErrorHandler{}.errorOccured(std::move(result).error());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (auto result = configs.write_config(configs.dpadMappingDown, m_downButton); !result)
|
||||||
|
{
|
||||||
|
BobbyErrorHandler{}.errorOccured(std::move(result).error());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
espgui::switchScreen<BoardcomputerHardwareSettingsMenu>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonCalibrateDisplay::redraw()
|
void ButtonCalibrateDisplay::redraw()
|
||||||
{
|
{
|
||||||
Base::redraw();
|
Base::redraw();
|
||||||
|
|
||||||
|
espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||||
|
|
||||||
switch (m_status)
|
switch (m_status)
|
||||||
{
|
{
|
||||||
case WaitingLeft:
|
case WaitingLeft:
|
||||||
if (m_lastButton)
|
if (m_lastButton)
|
||||||
m_label.redraw("Press LEFT again");
|
m_labelInstruction.redraw("Press LEFT again");
|
||||||
else
|
else
|
||||||
m_label.redraw("Press LEFT");
|
m_labelInstruction.redraw("Press LEFT");
|
||||||
break;
|
break;
|
||||||
case WaitingRight:
|
case WaitingRight:
|
||||||
if (m_lastButton)
|
if (m_lastButton)
|
||||||
m_label.redraw("Press RIGHT again");
|
m_labelInstruction.redraw("Press RIGHT again");
|
||||||
else
|
else
|
||||||
m_label.redraw("Press RIGHT");
|
m_labelInstruction.redraw("Press RIGHT");
|
||||||
break;
|
break;
|
||||||
case WaitingUp:
|
case WaitingUp:
|
||||||
if (m_lastButton)
|
if (m_lastButton)
|
||||||
m_label.redraw("Press UP again");
|
m_labelInstruction.redraw("Press UP again");
|
||||||
else
|
else
|
||||||
m_label.redraw("Press UP");
|
m_labelInstruction.redraw("Press UP");
|
||||||
break;
|
break;
|
||||||
case WaitingDown:
|
case WaitingDown:
|
||||||
if (m_lastButton)
|
if (m_lastButton)
|
||||||
m_label.redraw("Press DOWN again");
|
m_labelInstruction.redraw("Press DOWN again");
|
||||||
else
|
else
|
||||||
m_label.redraw("Press DOWN");
|
m_labelInstruction.redraw("Press DOWN");
|
||||||
break;
|
break;
|
||||||
case Finished:
|
case Finished:
|
||||||
m_label.redraw("Finished");
|
m_labelInstruction.redraw("Finished");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_labelLeft.redraw(m_status > WaitingLeft ? fmt::format("Left: {}", m_leftButton) : std::string{});
|
||||||
|
m_labelRight.redraw(m_status > WaitingRight ? fmt::format("Right: {}", m_rightButton) : std::string{});
|
||||||
|
m_labelUp.redraw(m_status > WaitingUp ? fmt::format("Up: {}", m_upButton) : std::string{});
|
||||||
|
m_labelDown.redraw(m_status > WaitingDown ? fmt::format("Down: {}", m_downButton) : std::string{});
|
||||||
|
|
||||||
|
m_labelEnd.redraw(m_status == Finished ? "Press RIGHT to save" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonCalibrateDisplay::stop()
|
void ButtonCalibrateDisplay::stop()
|
||||||
@ -117,6 +171,8 @@ void ButtonCalibrateDisplay::rawButtonPressed(uint8_t button)
|
|||||||
m_status = Finished;
|
m_status = Finished;
|
||||||
break;
|
break;
|
||||||
case Finished:
|
case Finished:
|
||||||
|
if (button == m_rightButton)
|
||||||
|
m_finished = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,16 @@ private:
|
|||||||
|
|
||||||
enum { WaitingLeft, WaitingRight, WaitingUp, WaitingDown, Finished } m_status;
|
enum { WaitingLeft, WaitingRight, WaitingUp, WaitingDown, Finished } m_status;
|
||||||
|
|
||||||
espgui::Label m_label{25, 72};
|
espgui::Label m_labelInstruction{25, 72};
|
||||||
|
|
||||||
|
espgui::Label m_labelLeft{25, 100};
|
||||||
|
espgui::Label m_labelRight{25, 125};
|
||||||
|
espgui::Label m_labelUp{25, 150};
|
||||||
|
espgui::Label m_labelDown{25, 175};
|
||||||
|
|
||||||
|
espgui::Label m_labelEnd{25, 225};
|
||||||
|
|
||||||
uint8_t m_leftButton, m_rightButton, m_upButton, m_downButton;
|
uint8_t m_leftButton, m_rightButton, m_upButton, m_downButton;
|
||||||
|
|
||||||
|
bool m_finished;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user