Poti screen
This commit is contained in:
@ -9,8 +9,7 @@
|
||||
|
||||
// local includes
|
||||
#include "bobbyerrorhandler.h"
|
||||
#include "displays/setup/ask_setup_clouds.h"
|
||||
// #include "displays/setup/calibrate_potis.h" // commented out until implemented
|
||||
#include "displays/setup/calibrate_potis.h"
|
||||
#include "setup.h"
|
||||
#include "utils.h"
|
||||
|
||||
@ -52,7 +51,7 @@ void SetupBasicButtonsDisplay::update()
|
||||
}
|
||||
else
|
||||
{
|
||||
espgui::switchScreen<SetupAskSetupCloudsDisplay>();
|
||||
espgui::switchScreen<SetupCalibratePotisDisplay>();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1 +1,309 @@
|
||||
#include "calibrate_potis.h"
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <cpputils.h>
|
||||
#include <screenmanager.h>
|
||||
#include <tftinstance.h>
|
||||
|
||||
// local includes
|
||||
#include "displays/setup/ask_setup_clouds.h"
|
||||
#include "globals.h"
|
||||
#include "setup.h"
|
||||
|
||||
using namespace espgui;
|
||||
|
||||
void SetupCalibratePotisDisplay::initScreen()
|
||||
{
|
||||
Base::initScreen();
|
||||
|
||||
tft.setTextFont(4);
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
|
||||
tft.drawString("gas:", 25, 47);
|
||||
tft.drawString("brems:", 25, 147);
|
||||
|
||||
for (auto &label : m_labels)
|
||||
label.start();
|
||||
|
||||
for (auto &progressBar : m_progressBars)
|
||||
progressBar.start();
|
||||
|
||||
m_renderedButton = -1;
|
||||
}
|
||||
|
||||
void SetupCalibratePotisDisplay::start()
|
||||
{
|
||||
Base::start();
|
||||
|
||||
setup::lock();
|
||||
|
||||
m_selectedButton = 0;
|
||||
m_status = Status::Begin;
|
||||
copyFromSettings();
|
||||
m_gas = std::nullopt;
|
||||
m_brems = std::nullopt;
|
||||
}
|
||||
void SetupCalibratePotisDisplay::update()
|
||||
{
|
||||
Base::update();
|
||||
|
||||
if (raw_gas)
|
||||
m_gas = cpputils::mapValueClamped<float>(*raw_gas, m_gasMin, m_gasMax, 0.f, 1000.f);
|
||||
else
|
||||
m_gas = std::nullopt;
|
||||
|
||||
if (raw_brems)
|
||||
m_brems = cpputils::mapValueClamped<float>(*raw_brems, m_bremsMin, m_bremsMax, 0.f, 1000.f);
|
||||
else
|
||||
m_brems = std::nullopt;
|
||||
}
|
||||
|
||||
void SetupCalibratePotisDisplay::redraw()
|
||||
{
|
||||
Base::redraw();
|
||||
|
||||
m_labels[0].redraw(m_gas ? fmt::format("{:.02f}", *m_gas) : "?");
|
||||
m_labels[1].redraw(raw_gas ? std::to_string(*raw_gas) : "?");
|
||||
if (m_status == Status::GasMin)
|
||||
espgui::tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
m_labels[2].redraw(std::to_string(m_gasMin));
|
||||
if (m_status == Status::GasMin)
|
||||
espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
if (m_status == Status::GasMax)
|
||||
espgui::tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
m_labels[3].redraw(std::to_string(m_gasMax));
|
||||
if (m_status == Status::GasMax)
|
||||
espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
|
||||
m_progressBars[0].redraw(m_gas ? *m_gas : 0);
|
||||
|
||||
m_labels[4].redraw(m_brems ? fmt::format("{:.02f}", *m_brems) : "?");
|
||||
m_labels[5].redraw(raw_brems ? std::to_string(*raw_brems) : "?");
|
||||
if (m_status == Status::BremsMin)
|
||||
espgui::tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
m_labels[6].redraw(std::to_string(m_bremsMin));
|
||||
if (m_status == Status::BremsMin)
|
||||
espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
if (m_status == Status::BremsMax)
|
||||
espgui::tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
m_labels[7].redraw(std::to_string(m_bremsMax));
|
||||
if (m_status == Status::BremsMax)
|
||||
espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
|
||||
m_progressBars[1].redraw(m_brems ? *m_brems : 0);
|
||||
|
||||
m_labels[8].redraw([&](){
|
||||
switch (m_status)
|
||||
{
|
||||
case Status::Begin: return "Start calibrating?";
|
||||
#ifdef FEATURE_JOYSTICK
|
||||
case Status::Mitte: return "Release joystick";
|
||||
#endif
|
||||
case Status::GasMin: return "Release gas";
|
||||
case Status::GasMax: return "Press gas";
|
||||
case Status::BremsMin: return "Release brems";
|
||||
case Status::BremsMax: return "Press brems";
|
||||
case Status::Confirm: return "Verify";
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}());
|
||||
|
||||
{
|
||||
const auto failed = !m_gas || !m_brems || (m_status == Status::Confirm && (*m_gas > 100 || *m_brems > 100));
|
||||
const auto color = failed ? TFT_DARKGREY : TFT_WHITE;
|
||||
espgui::tft.setTextColor(color, TFT_BLACK);
|
||||
m_labels[9].redraw([&](){
|
||||
switch (m_status)
|
||||
{
|
||||
case Status::Begin: return "Yes";
|
||||
#ifdef FEATURE_JOYSTICK
|
||||
case Status::Mitte:
|
||||
#endif
|
||||
case Status::GasMin:
|
||||
case Status::GasMax:
|
||||
case Status::BremsMin:
|
||||
case Status::BremsMax: return "Next";
|
||||
case Status::Confirm: return "Save";
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}());
|
||||
|
||||
if (m_selectedButton != m_renderedButton && (m_selectedButton == 0 || m_renderedButton == 0))
|
||||
espgui::tft.drawRect(3, 275, 100, 27, m_selectedButton == 0 ? color : TFT_BLACK);
|
||||
}
|
||||
|
||||
espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
m_labels[10].redraw([&](){
|
||||
switch (m_status)
|
||||
{
|
||||
case Status::Begin: return "No";
|
||||
#ifdef FEATURE_JOYSTICK
|
||||
case Status::Mitte:
|
||||
#endif
|
||||
case Status::GasMin:
|
||||
case Status::GasMax:
|
||||
case Status::BremsMin:
|
||||
case Status::BremsMax:
|
||||
case Status::Confirm: return "Abort";
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}());
|
||||
|
||||
if (m_selectedButton != m_renderedButton && (m_selectedButton == 1 || m_renderedButton == 1))
|
||||
espgui::tft.drawRect(123, 275, 100, 27, m_selectedButton == 1 ? TFT_WHITE : TFT_BLACK);
|
||||
|
||||
m_renderedButton = m_selectedButton;
|
||||
}
|
||||
|
||||
void SetupCalibratePotisDisplay::stop()
|
||||
{
|
||||
if (m_early_return)
|
||||
{
|
||||
setup::unlock();
|
||||
}
|
||||
|
||||
Base::stop();
|
||||
}
|
||||
|
||||
void SetupCalibratePotisDisplay::buttonPressed(espgui::Button button)
|
||||
{
|
||||
Base::buttonPressed(button);
|
||||
|
||||
switch (button)
|
||||
{
|
||||
using espgui::Button;
|
||||
case Button::Up:
|
||||
m_selectedButton--;
|
||||
|
||||
if (m_selectedButton < 0)
|
||||
m_selectedButton = 1;
|
||||
|
||||
break;
|
||||
case Button::Down:
|
||||
m_selectedButton++;
|
||||
|
||||
if (m_selectedButton > 1)
|
||||
m_selectedButton = 0;
|
||||
|
||||
break;
|
||||
case Button::Left:
|
||||
back:
|
||||
switch (m_status)
|
||||
{
|
||||
case Status::Begin:
|
||||
if (m_early_return)
|
||||
espgui::popScreen();
|
||||
else
|
||||
espgui::switchScreen<SetupAskSetupCloudsDisplay>();
|
||||
break;
|
||||
#ifdef FEATURE_JOYSTICK
|
||||
case Status::Mitte:
|
||||
#endif
|
||||
case Status::GasMin:
|
||||
case Status::GasMax:
|
||||
case Status::BremsMin:
|
||||
case Status::BremsMax:
|
||||
case Status::Confirm:
|
||||
m_selectedButton = 0;
|
||||
m_status = Status::Begin;
|
||||
copyFromSettings();
|
||||
}
|
||||
|
||||
break;
|
||||
case Button::Right:
|
||||
switch (m_selectedButton)
|
||||
{
|
||||
case 0: // left button pressed
|
||||
if (!raw_gas || !raw_brems || !m_gas || !m_brems)
|
||||
return;
|
||||
|
||||
switch (m_status)
|
||||
{
|
||||
#ifndef FEATURE_JOYSTICK
|
||||
case Status::Begin:
|
||||
m_status = Status::GasMin;
|
||||
break;
|
||||
#else
|
||||
case Status::Begin:
|
||||
m_status = Status::Mitte;
|
||||
break;
|
||||
|
||||
case Status::Mitte:
|
||||
m_gasMitte = *raw_gas;
|
||||
m_bremsMitte = *raw_brems;
|
||||
m_status = Status::GasMin;
|
||||
break;
|
||||
#endif
|
||||
case Status::GasMin:
|
||||
m_gasMin = *raw_gas;
|
||||
m_status = Status::GasMax;
|
||||
break;
|
||||
case Status::GasMax:
|
||||
m_gasMax = *raw_gas;
|
||||
m_status = Status::BremsMin;
|
||||
{
|
||||
const auto dead = (m_gasMax - m_gasMin)/20;
|
||||
m_gasMin += dead;
|
||||
m_gasMax -= dead;
|
||||
}
|
||||
break;
|
||||
case Status::BremsMin:
|
||||
m_bremsMin = *raw_brems;
|
||||
m_status = Status::BremsMax;
|
||||
break;
|
||||
case Status::BremsMax:
|
||||
m_bremsMax = *raw_brems;
|
||||
m_status = Status::Confirm;
|
||||
{
|
||||
const auto dead = (m_bremsMax - m_bremsMin)/20;
|
||||
m_bremsMin += dead;
|
||||
m_bremsMax -= dead;
|
||||
}
|
||||
break;
|
||||
case Status::Confirm:
|
||||
if (*m_gas > 100 || *m_brems > 100)
|
||||
return;
|
||||
|
||||
copyToSettings();
|
||||
|
||||
if (m_early_return)
|
||||
espgui::popScreen();
|
||||
else
|
||||
espgui::switchScreen<SetupAskSetupCloudsDisplay>();
|
||||
}
|
||||
break;
|
||||
case 1: // right button pressed
|
||||
goto back;
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
std::string SetupCalibratePotisDisplay::text() const
|
||||
{
|
||||
return "Calibrate Potis";
|
||||
}
|
||||
|
||||
void SetupCalibratePotisDisplay::copyFromSettings()
|
||||
{
|
||||
#ifdef FEATURE_JOYSTICK
|
||||
m_gasMitte = configs.gasMitte.value();
|
||||
m_bremsMitte = configs.bremsMitte.value();
|
||||
#endif
|
||||
m_gasMin = configs.gasMin.value();
|
||||
m_gasMax = configs.gasMax.value();
|
||||
m_bremsMin = configs.bremsMin.value();
|
||||
m_bremsMax = configs.bremsMax.value();
|
||||
}
|
||||
|
||||
void SetupCalibratePotisDisplay::copyToSettings() const
|
||||
{
|
||||
#ifdef FEATURE_JOYSTICK
|
||||
configs.write_config(configs.gasMitte, m_gasMitte);
|
||||
configs.write_config(configs.bremsMitte, m_bremsMitte);
|
||||
#endif
|
||||
configs.write_config(configs.gasMin, m_gasMin);
|
||||
configs.write_config(configs.gasMax, m_gasMax);
|
||||
configs.write_config(configs.bremsMin, m_bremsMin);
|
||||
configs.write_config(configs.bremsMax, m_bremsMax);
|
||||
}
|
||||
|
@ -1,5 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
// system includes
|
||||
#include <array>
|
||||
#include <optional>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <widgets/label.h>
|
||||
#include <widgets/progressbar.h>
|
||||
|
||||
// local includes
|
||||
#include "displays/bobbydisplaywithtitle.h"
|
||||
|
||||
@ -17,13 +25,62 @@ public:
|
||||
void redraw() override;
|
||||
void stop() override;
|
||||
|
||||
void rawButtonPressed(uint8_t button) override;
|
||||
void rawButtonReleased(uint8_t button) override;
|
||||
void buttonPressed(espgui::Button button) override;
|
||||
void buttonReleased(espgui::Button button) override;
|
||||
|
||||
[[nodiscard]] std::string text() const override;
|
||||
|
||||
private:
|
||||
void copyFromSettings();
|
||||
void copyToSettings() const;
|
||||
|
||||
const bool m_early_return;
|
||||
|
||||
std::array<espgui::Label, 11> m_labels {{
|
||||
espgui::Label{25, 72}, // 100, 23
|
||||
espgui::Label{145, 72}, // 100, 23
|
||||
espgui::Label{25, 97}, // 100, 23
|
||||
espgui::Label{145, 97}, // 100, 23
|
||||
|
||||
espgui::Label{25, 172}, // 100, 23
|
||||
espgui::Label{145, 172}, // 100, 23
|
||||
espgui::Label{25, 197}, // 100, 23
|
||||
espgui::Label{145, 197}, // 100, 23
|
||||
|
||||
espgui::Label{25, 247}, // 190, 23
|
||||
|
||||
espgui::Label{25, 277}, // 100, 23
|
||||
espgui::Label{145, 277}, // 100, 23
|
||||
}};
|
||||
|
||||
std::array<espgui::ProgressBar, 2> m_progressBars {{
|
||||
espgui::ProgressBar{20, 129, 200, 10, 0, 1000},
|
||||
espgui::ProgressBar{20, 229, 200, 10, 0, 1000}
|
||||
}};
|
||||
|
||||
enum Status {
|
||||
Begin,
|
||||
#ifdef FEATURE_JOYSTICK
|
||||
Mitte,
|
||||
#endif
|
||||
GasMin,
|
||||
GasMax,
|
||||
BremsMin,
|
||||
BremsMax,
|
||||
Confirm
|
||||
};
|
||||
|
||||
int8_t m_selectedButton, m_renderedButton;
|
||||
|
||||
Status m_status;
|
||||
int16_t
|
||||
m_gasMin,
|
||||
m_gasMax,
|
||||
m_bremsMin,
|
||||
m_bremsMax
|
||||
#ifdef FEATURE_JOYSTICK
|
||||
,m_gasMitte
|
||||
,m_bremsMitte
|
||||
#endif
|
||||
;
|
||||
std::optional<float> m_gas, m_brems;
|
||||
};
|
||||
|
@ -148,9 +148,9 @@ extern "C" void app_main()
|
||||
BOOT_PROGRESS("Calibtration");
|
||||
espgui::switchScreen<SetupBasicButtonsDisplay>(true);
|
||||
break;
|
||||
/*case SetupStep::CALIBRATE_POTIS:
|
||||
case SetupStep::CALIBRATE_POTIS:
|
||||
espgui::switchScreen<SetupCalibratePotisDisplay>(true);
|
||||
break;*/
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user