Basic button calibration implementation
This commit is contained in:
@ -1,18 +1,32 @@
|
|||||||
#include "buttoncalibratedisplay.h"
|
#include "buttoncalibratedisplay.h"
|
||||||
|
|
||||||
|
// esp-idf includes
|
||||||
|
#include <esp_log.h>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr const char TAG[] = "BUTTON";
|
||||||
|
} // namespace
|
||||||
|
|
||||||
std::string ButtonCalibrateDisplay::text() const
|
std::string ButtonCalibrateDisplay::text() const
|
||||||
{
|
{
|
||||||
return "TODO";
|
return "Button calibrate";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonCalibrateDisplay::start()
|
void ButtonCalibrateDisplay::start()
|
||||||
{
|
{
|
||||||
Base::start();
|
Base::start();
|
||||||
|
|
||||||
|
m_oldMode = currentMode;
|
||||||
|
currentMode = &m_mode;
|
||||||
|
m_lastButton = std::nullopt;
|
||||||
|
m_status = WaitingLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonCalibrateDisplay::initScreen()
|
void ButtonCalibrateDisplay::initScreen()
|
||||||
{
|
{
|
||||||
Base::initScreen();
|
Base::initScreen();
|
||||||
|
|
||||||
|
m_label.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonCalibrateDisplay::update()
|
void ButtonCalibrateDisplay::update()
|
||||||
@ -23,21 +37,96 @@ void ButtonCalibrateDisplay::update()
|
|||||||
void ButtonCalibrateDisplay::redraw()
|
void ButtonCalibrateDisplay::redraw()
|
||||||
{
|
{
|
||||||
Base::redraw();
|
Base::redraw();
|
||||||
|
|
||||||
|
switch (m_status)
|
||||||
|
{
|
||||||
|
case WaitingLeft:
|
||||||
|
if (m_lastButton)
|
||||||
|
m_label.redraw("Press LEFT again");
|
||||||
|
else
|
||||||
|
m_label.redraw("Press LEFT");
|
||||||
|
break;
|
||||||
|
case WaitingRight:
|
||||||
|
if (m_lastButton)
|
||||||
|
m_label.redraw("Press RIGHT again");
|
||||||
|
else
|
||||||
|
m_label.redraw("Press RIGHT");
|
||||||
|
break;
|
||||||
|
case WaitingUp:
|
||||||
|
if (m_lastButton)
|
||||||
|
m_label.redraw("Press UP again");
|
||||||
|
else
|
||||||
|
m_label.redraw("Press UP");
|
||||||
|
break;
|
||||||
|
case WaitingDown:
|
||||||
|
if (m_lastButton)
|
||||||
|
m_label.redraw("Press DOWN again");
|
||||||
|
else
|
||||||
|
m_label.redraw("Press DOWN");
|
||||||
|
break;
|
||||||
|
case Finished:
|
||||||
|
m_label.redraw("Finished");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonCalibrateDisplay::stop()
|
void ButtonCalibrateDisplay::stop()
|
||||||
{
|
{
|
||||||
Base::stop();
|
Base::stop();
|
||||||
|
|
||||||
|
if (currentMode == &m_mode)
|
||||||
|
{
|
||||||
|
// to avoid crash after deconstruction
|
||||||
|
m_mode.stop();
|
||||||
|
lastMode = nullptr;
|
||||||
|
|
||||||
|
currentMode = m_oldMode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonCalibrateDisplay::rawButtonPressed(uint8_t button)
|
void ButtonCalibrateDisplay::rawButtonPressed(uint8_t button)
|
||||||
{
|
{
|
||||||
//Base::rawButtonPressed(button);
|
//Base::rawButtonPressed(button);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "button=%hhu", button);
|
||||||
|
|
||||||
|
if (!m_lastButton || *m_lastButton != button)
|
||||||
|
m_lastButton = button;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (m_status)
|
||||||
|
{
|
||||||
|
case WaitingLeft:
|
||||||
|
m_leftButton = button;
|
||||||
|
m_lastButton = std::nullopt;
|
||||||
|
m_status = WaitingRight;
|
||||||
|
break;
|
||||||
|
case WaitingRight:
|
||||||
|
m_rightButton = button;
|
||||||
|
m_lastButton = std::nullopt;
|
||||||
|
m_status = WaitingUp;
|
||||||
|
break;
|
||||||
|
case WaitingUp:
|
||||||
|
m_upButton = button;
|
||||||
|
m_lastButton = std::nullopt;
|
||||||
|
m_status = WaitingDown;
|
||||||
|
break;
|
||||||
|
case WaitingDown:
|
||||||
|
m_downButton = button;
|
||||||
|
m_lastButton = std::nullopt;
|
||||||
|
m_status = Finished;
|
||||||
|
break;
|
||||||
|
case Finished:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonCalibrateDisplay::rawButtonReleased(uint8_t button)
|
void ButtonCalibrateDisplay::rawButtonReleased(uint8_t button)
|
||||||
{
|
{
|
||||||
//Base::rawButtonReleased(button);
|
//Base::rawButtonReleased(button);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "button=%hhu", button);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonCalibrateDisplay::buttonPressed(espgui::Button button)
|
void ButtonCalibrateDisplay::buttonPressed(espgui::Button button)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
// 3rdparty lib includes
|
// 3rdparty lib includes
|
||||||
#include <displaywithtitle.h>
|
#include <displaywithtitle.h>
|
||||||
|
#include <widgets/label.h>
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
@ -32,4 +33,12 @@ private:
|
|||||||
const bool m_bootup{false};
|
const bool m_bootup{false};
|
||||||
ModeInterface *m_oldMode;
|
ModeInterface *m_oldMode;
|
||||||
IgnoreInputMode m_mode{0, bobbycar::protocol::ControlType::FieldOrientedControl, bobbycar::protocol::ControlMode::Torque};
|
IgnoreInputMode m_mode{0, bobbycar::protocol::ControlType::FieldOrientedControl, bobbycar::protocol::ControlMode::Torque};
|
||||||
|
|
||||||
|
std::optional<uint8_t> m_lastButton;
|
||||||
|
|
||||||
|
enum { WaitingLeft, WaitingRight, WaitingUp, WaitingDown, Finished } m_status;
|
||||||
|
|
||||||
|
espgui::Label m_label{25, 72};
|
||||||
|
|
||||||
|
uint8_t m_leftButton, m_rightButton, m_upButton, m_downButton;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user