Calibrate display save button configs

This commit is contained in:
2021-12-30 23:44:58 +01:00
parent 97c12b103c
commit 0288ac93a3
2 changed files with 76 additions and 11 deletions

View File

@ -3,6 +3,16 @@
// esp-idf includes
#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 {
constexpr const char TAG[] = "BUTTON";
} // namespace
@ -20,54 +30,98 @@ void ButtonCalibrateDisplay::start()
currentMode = &m_mode;
m_lastButton = std::nullopt;
m_status = WaitingLeft;
m_finished = false;
}
void ButtonCalibrateDisplay::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()
{
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()
{
Base::redraw();
espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK);
switch (m_status)
{
case WaitingLeft:
if (m_lastButton)
m_label.redraw("Press LEFT again");
m_labelInstruction.redraw("Press LEFT again");
else
m_label.redraw("Press LEFT");
m_labelInstruction.redraw("Press LEFT");
break;
case WaitingRight:
if (m_lastButton)
m_label.redraw("Press RIGHT again");
m_labelInstruction.redraw("Press RIGHT again");
else
m_label.redraw("Press RIGHT");
m_labelInstruction.redraw("Press RIGHT");
break;
case WaitingUp:
if (m_lastButton)
m_label.redraw("Press UP again");
m_labelInstruction.redraw("Press UP again");
else
m_label.redraw("Press UP");
m_labelInstruction.redraw("Press UP");
break;
case WaitingDown:
if (m_lastButton)
m_label.redraw("Press DOWN again");
m_labelInstruction.redraw("Press DOWN again");
else
m_label.redraw("Press DOWN");
m_labelInstruction.redraw("Press DOWN");
break;
case Finished:
m_label.redraw("Finished");
m_labelInstruction.redraw("Finished");
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()
@ -117,6 +171,8 @@ void ButtonCalibrateDisplay::rawButtonPressed(uint8_t button)
m_status = Finished;
break;
case Finished:
if (button == m_rightButton)
m_finished = true;
break;
}
}

View File

@ -38,7 +38,16 @@ private:
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;
bool m_finished;
};