From 1de44c630b692cd5dfba31ce2c1041805b737acf Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Tue, 2 Nov 2021 01:43:58 +0100 Subject: [PATCH] Rewrite --- main/CMakeLists.txt | 1 + main/actions/bluetoothbeginaction.cpp | 15 + main/actions/bluetoothbeginaction.h | 19 +- main/battery.cpp | 1 + main/battery.h | 169 ++++----- main/ble_bobby.h | 4 +- main/cloud.h | 2 +- main/controller.cpp | 7 +- main/controller.h | 2 +- main/debugtexthelpers.h | 2 +- main/displays/bmsdisplay.h | 5 - main/displays/calibratedisplay.cpp | 276 +++++++++++++++ main/displays/calibratedisplay.h | 303 ++-------------- main/displays/calibratevoltagedisplay.cpp | 82 +++++ main/displays/calibratevoltagedisplay.h | 82 +---- main/displays/gametrakcalibratedisplay.h | 5 - main/displays/menus/aboutmenu.cpp | 46 +++ main/displays/menus/aboutmenu.h | 57 +-- main/displays/menus/batterymenu.cpp | 55 +++ main/displays/menus/batterymenu.h | 76 +--- main/displays/menus/blesettingsmenu.h | 5 - main/displays/menus/bluetoothsettingsmenu.h | 5 - .../boardcomputerhardwaresettingsmenu.cpp | 183 ++++++++++ .../menus/boardcomputerhardwaresettingsmenu.h | 190 +--------- main/displays/menus/buzzermenu.h | 6 - main/displays/menus/cloudsettingsmenu.h | 6 - .../menus/controllerhardwaresettingsmenu.h | 9 - main/displays/menus/crashmenu.h | 5 - main/displays/menus/limitssettingsmenu.h | 6 - main/displays/menus/lockscreensettingsmenu.h | 6 - main/displays/menus/mainmenu.cpp | 90 +++++ main/displays/menus/mainmenu.h | 94 +---- main/displays/menus/modessettingsmenu.h | 9 - main/displays/menus/otamenu.h | 9 - main/displays/menus/selectbatterytypemenu.cpp | 35 ++ main/displays/menus/selectbatterytypemenu.h | 57 +-- main/displays/menus/selectbuildservermenu.cpp | 71 ++++ main/displays/menus/selectbuildservermenu.h | 79 +---- main/displays/menus/settingsmenu.cpp | 94 +++++ main/displays/menus/settingsmenu.h | 97 +----- main/displays/menus/timersmenu.h | 5 - main/displays/menus/timesettingsmenu.h | 6 - main/displays/menus/wifisettingsmenu.h | 8 - main/displays/metersdisplay.cpp | 70 ++++ main/displays/metersdisplay.h | 101 ++---- main/displays/powersupplydisplay.h | 5 - main/displays/statusdisplay.cpp | 261 ++++++++++++++ main/displays/statusdisplay.h | 325 +++--------------- main/main.cpp | 99 +----- main/screens.cpp | 93 +++++ main/screens.h | 96 +----- main/serialhandler.cpp | 121 +++++++ main/serialhandler.h | 115 +------ main/statistics.h | 4 +- main/texts.h | 2 - main/webserver_displaycontrol.h | 27 +- main/webserver_ota.h | 2 + 57 files changed, 1789 insertions(+), 1816 deletions(-) create mode 100644 main/displays/menus/selectbuildservermenu.cpp diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index f6e5611..2578d9d 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -317,6 +317,7 @@ set(sources displays/menus/presetsmenu.cpp displays/menus/profilesmenu.cpp displays/menus/selectbatterytypemenu.cpp + displays/menus/selectbuildservermenu.cpp displays/menus/selectmodemenu.cpp displays/menus/settingsmenu.cpp displays/menus/stationwifisettingsmenu.cpp diff --git a/main/actions/bluetoothbeginaction.cpp b/main/actions/bluetoothbeginaction.cpp index e69de29..6e894ee 100644 --- a/main/actions/bluetoothbeginaction.cpp +++ b/main/actions/bluetoothbeginaction.cpp @@ -0,0 +1,15 @@ +#include "bluetoothbeginaction.h" + +// local includes +#include "globals.h" + +#ifdef FEATURE_BLUETOOTH +void BluetoothBeginAction::triggered() +{ + if (!bluetoothSerial.begin(deviceName)) + { + //Serial.println("Could not begin bluetooth"); + // TODO: better error handling + } +} +#endif diff --git a/main/actions/bluetoothbeginaction.h b/main/actions/bluetoothbeginaction.h index b06ffbe..1485973 100644 --- a/main/actions/bluetoothbeginaction.h +++ b/main/actions/bluetoothbeginaction.h @@ -1,23 +1,12 @@ #pragma once -#include "actioninterface.h" -#include "globals.h" +// 3rdparty lib includes +#include -using namespace espgui; - -namespace { #ifdef FEATURE_BLUETOOTH -class BluetoothBeginAction : public virtual ActionInterface +class BluetoothBeginAction : public virtual espgui::ActionInterface { public: - void triggered() override - { - if (!bluetoothSerial.begin(deviceName)) - { - //Serial.println("Could not begin bluetooth"); - // TODO: better error handling - } - } + void triggered() override; }; #endif -} diff --git a/main/battery.cpp b/main/battery.cpp index e69de29..63e94e1 100644 --- a/main/battery.cpp +++ b/main/battery.cpp @@ -0,0 +1 @@ +#include "battery.h" diff --git a/main/battery.h b/main/battery.h index f4b4c0c..7bbe210 100644 --- a/main/battery.h +++ b/main/battery.h @@ -3,10 +3,10 @@ // 3rdparty lib includes #include #include +#include // local includes #include "globals.h" -#include "cpputils.h" #define BatteryCellTypeValues(x) \ x(_22P) \ @@ -16,91 +16,94 @@ DECLARE_TYPESAFE_ENUM(BatteryCellType, : uint8_t, BatteryCellTypeValues) namespace { - -float mapFloat(float x, float in_min, float in_max, float out_min, float out_max) { - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} -#define CURVE(higherVoltage,lowerVoltage,fromAh,toAh) if(cellVoltage >= lowerVoltage && cellVoltage <= higherVoltage) return 100 * (expected_ah - mapFloat(cellVoltage, higherVoltage, lowerVoltage, fromAh, toAh)) / expected_ah; +#define CURVE(higherVoltage,lowerVoltage,fromAh,toAh) \ + if (cellVoltage >= lowerVoltage && cellVoltage <= higherVoltage) \ + return 100 * (expected_ah - cpputils::mapValue(cellVoltage, higherVoltage, lowerVoltage, fromAh, toAh)) / expected_ah; float getBatteryPercentage(float batVoltage, BatteryCellType cellType) { const float cellVoltage = batVoltage / settings.battery.cellsSeries; - switch (cellType) { - case BatteryCellType::_22P: { - const float expected_ah = 2.2; - if(cellVoltage > 4.15){ - return 100; - } - CURVE(4.15, 4.04, 0, 0.25) - CURVE(4.04, 3.95, 0.25, 0.5) - CURVE(3.95, 3.86, 0.5, 0.75) - CURVE(3.86, 3.74, 0.75, 1.0) - CURVE(3.74, 3.64, 1.0, 1.25) - CURVE(3.64, 3.59, 1.25, 1.5) - CURVE(3.59, 3.54, 1.5, 1.75) - CURVE(3.54, 3.43, 1.75, 2.0) - CURVE(3.43, 3.35, 2.0, 2.1) - CURVE(3.35, 2.50, 2.1, 2.2) - break; - } - case BatteryCellType::MH1: { - const float expected_ah = 3.2; - if(cellVoltage > 4.15){ - return 100; - } - CURVE(4.15, 4.09, 0, 0.25) - CURVE(4.09, 4.04, 0.25, 0.5) - CURVE(4.04, 3.95, 0.5, 0.75) - CURVE(3.95, 3.88, 0.75, 1.0) - CURVE(3.88, 3.79, 1.0, 1.25) - CURVE(3.79, 3.70, 1.25, 1.5) - CURVE(3.70, 3.65, 1.5, 1.75) - CURVE(3.65, 3.60, 1.75, 2.0) - CURVE(3.60, 3.56, 2.0, 2.25) - CURVE(3.56, 3.50, 2.25, 2.5) - CURVE(3.50, 3.40, 2.5, 2.75) - CURVE(3.40, 3.30, 2.75, 3.0) - CURVE(3.30, 2.5, 3.0, 3.2) - break; - } - case BatteryCellType::HG2: { - const float expected_ah = 3.0; - if(cellVoltage > 4.15){ - return 100; - } - CURVE(4.15, 4.08, 0, 0.25) - CURVE(4.08, 4.01, 0.25, 0.5) - CURVE(4.01, 3.92, 0.5, 0.75) - CURVE(3.92, 3.84, 0.75, 1.0) - CURVE(3.84, 3.75, 1.0, 1.25) - CURVE(3.75, 3.67, 1.25, 1.5) - CURVE(3.67, 3.62, 1.5, 1.75) - CURVE(3.62, 3.55, 1.75, 2.0) - CURVE(3.55, 3.44, 2.0, 2.25) - CURVE(3.44, 3.30, 2.25, 2.5) - CURVE(3.30, 3.05, 2.5, 2.75) - CURVE(3.05, 2.50, 2.75, 3.0) - break; - } - case BatteryCellType::VTC5: { - const float expected_ah = 2.6; - if(cellVoltage > 4.15){ - return 100; - } - CURVE(4.15, 4.08, 0, 0.25) - CURVE(4.08, 3.98, 0.25, 0.5) - CURVE(3.98, 3.89, 0.5, 0.75) - CURVE(3.89, 3.79, 0.75, 1.0) - CURVE(3.79, 3.71, 1.0, 1.25) - CURVE(3.71, 3.64, 1.25, 1.5) - CURVE(3.64, 3.53, 1.5, 1.75) - CURVE(3.53, 3.44, 1.75, 2.0) - CURVE(3.44, 3.20, 2.0, 2.25) - CURVE(3.20, 2.80, 2.25, 2.5) - CURVE(2.80, 2.50, 2.5, 2.60) - break; - } + switch (cellType) + { + case BatteryCellType::_22P: + { + const float expected_ah = 2.2; + if (cellVoltage > 4.15) + return 100; + + CURVE(4.15, 4.04, 0, 0.25) + CURVE(4.04, 3.95, 0.25, 0.5) + CURVE(3.95, 3.86, 0.5, 0.75) + CURVE(3.86, 3.74, 0.75, 1.0) + CURVE(3.74, 3.64, 1.0, 1.25) + CURVE(3.64, 3.59, 1.25, 1.5) + CURVE(3.59, 3.54, 1.5, 1.75) + CURVE(3.54, 3.43, 1.75, 2.0) + CURVE(3.43, 3.35, 2.0, 2.1) + CURVE(3.35, 2.50, 2.1, 2.2) + break; + } + case BatteryCellType::MH1: + { + const float expected_ah = 3.2; + if (cellVoltage > 4.15) + return 100; + + CURVE(4.15, 4.09, 0, 0.25) + CURVE(4.09, 4.04, 0.25, 0.5) + CURVE(4.04, 3.95, 0.5, 0.75) + CURVE(3.95, 3.88, 0.75, 1.0) + CURVE(3.88, 3.79, 1.0, 1.25) + CURVE(3.79, 3.70, 1.25, 1.5) + CURVE(3.70, 3.65, 1.5, 1.75) + CURVE(3.65, 3.60, 1.75, 2.0) + CURVE(3.60, 3.56, 2.0, 2.25) + CURVE(3.56, 3.50, 2.25, 2.5) + CURVE(3.50, 3.40, 2.5, 2.75) + CURVE(3.40, 3.30, 2.75, 3.0) + CURVE(3.30, 2.5, 3.0, 3.2) + break; + } + case BatteryCellType::HG2: + { + const float expected_ah = 3.0; + if (cellVoltage > 4.15) + return 100; + + CURVE(4.15, 4.08, 0, 0.25) + CURVE(4.08, 4.01, 0.25, 0.5) + CURVE(4.01, 3.92, 0.5, 0.75) + CURVE(3.92, 3.84, 0.75, 1.0) + CURVE(3.84, 3.75, 1.0, 1.25) + CURVE(3.75, 3.67, 1.25, 1.5) + CURVE(3.67, 3.62, 1.5, 1.75) + CURVE(3.62, 3.55, 1.75, 2.0) + CURVE(3.55, 3.44, 2.0, 2.25) + CURVE(3.44, 3.30, 2.25, 2.5) + CURVE(3.30, 3.05, 2.5, 2.75) + CURVE(3.05, 2.50, 2.75, 3.0) + break; + } + case BatteryCellType::VTC5: + { + const float expected_ah = 2.6; + if (cellVoltage > 4.15) + return 100; + + CURVE(4.15, 4.08, 0, 0.25) + CURVE(4.08, 3.98, 0.25, 0.5) + CURVE(3.98, 3.89, 0.5, 0.75) + CURVE(3.89, 3.79, 0.75, 1.0) + CURVE(3.79, 3.71, 1.0, 1.25) + CURVE(3.71, 3.64, 1.25, 1.5) + CURVE(3.64, 3.53, 1.5, 1.75) + CURVE(3.53, 3.44, 1.75, 2.0) + CURVE(3.44, 3.20, 2.0, 2.25) + CURVE(3.20, 2.80, 2.25, 2.5) + CURVE(2.80, 2.50, 2.5, 2.60) + break; + } } return 0.f; } @@ -116,7 +119,7 @@ float getRemainingWattHours() float avgVoltage = 0; for (auto &controller : controllers) { - avgVoltage += controller.getCalibratedVoltage(settings.battery.applyCalibration); + avgVoltage += controller.getCalibratedVoltage(); } avgVoltage = avgVoltage / controllers.size(); @@ -128,7 +131,7 @@ std::string getBatteryPercentageString() float avgVoltage = 0; for (auto &controller : controllers) { - avgVoltage += controller.getCalibratedVoltage(settings.battery.applyCalibration); + avgVoltage += controller.getCalibratedVoltage(); } avgVoltage = avgVoltage / controllers.size(); diff --git a/main/ble_bobby.h b/main/ble_bobby.h index ccf926b..069a4d4 100644 --- a/main/ble_bobby.h +++ b/main/ble_bobby.h @@ -81,11 +81,11 @@ void handleBle() { auto arr = doc.createNestedArray("v"); if (controllers.front.feedbackValid) - arr.add(controllers.front.getCalibratedVoltage(settings.battery.applyCalibration)); + arr.add(controllers.front.getCalibratedVoltage()); else arr.add(nullptr); if (controllers.back.feedbackValid) - arr.add(controllers.back.getCalibratedVoltage(settings.battery.applyCalibration)); + arr.add(controllers.back.getCalibratedVoltage()); else arr.add(nullptr); } diff --git a/main/cloud.h b/main/cloud.h index e56aca8..61b5d13 100644 --- a/main/cloud.h +++ b/main/cloud.h @@ -110,7 +110,7 @@ void cloudCollect() } cloudBuffer += fmt::format(",[{:.02f},{:.02f}", - controller.getCalibratedVoltage(settings.battery.applyCalibration), + controller.getCalibratedVoltage(), fixBoardTemp(controller.feedback.boardTemp)); constexpr const auto addMotor = [](const bobbycar::protocol::serial::MotorState &command, diff --git a/main/controller.cpp b/main/controller.cpp index 2f467c2..14d0ab7 100644 --- a/main/controller.cpp +++ b/main/controller.cpp @@ -1,5 +1,8 @@ #include "controller.h" +// local includes +#include "globals.h" + Controller::Controller( #ifdef FEATURE_SERIAL HardwareSerial &serial, @@ -15,10 +18,10 @@ Controller::Controller( { } -float Controller::getCalibratedVoltage(bool applyCalibration) const +float Controller::getCalibratedVoltage() const { float voltage = feedback.batVoltage; - if (applyCalibration) + if (settings.battery.applyCalibration) { voltage = ((voltage - float(voltageCalib30V)) * (20.f / (float(voltageCalib50V) - float(voltageCalib30V))) + 30.f); } diff --git a/main/controller.h b/main/controller.h index 4c39302..8a6eba6 100644 --- a/main/controller.h +++ b/main/controller.h @@ -53,5 +53,5 @@ struct Controller FeedbackParser parser{serial, feedbackValid, feedback}; #endif - float getCalibratedVoltage(bool applyCalibration) const; + float getCalibratedVoltage() const; }; diff --git a/main/debugtexthelpers.h b/main/debugtexthelpers.h index ecb135f..bdaa1a2 100644 --- a/main/debugtexthelpers.h +++ b/main/debugtexthelpers.h @@ -48,7 +48,7 @@ public: using RightCommand = CommandTexts; //struct BatVoltageText : public virtual TextInterface { public: std::string text() const override { std::string line{"batVoltage: "}; if (controller::get().feedbackValid) line += std::to_string(controller::get().feedback.batVoltage); return line; } }; - struct BatVoltageFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"batVoltage: "}; if (controller::get().feedbackValid) line += fmt::format("{:.2f}V", controller::get().getCalibratedVoltage(settings.battery.applyCalibration)); return line; } }; + struct BatVoltageFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"batVoltage: "}; if (controller::get().feedbackValid) line += fmt::format("{:.2f}V", controller::get().getCalibratedVoltage()); return line; } }; //struct BoardTempText : public virtual TextInterface { public: std::string text() const override { std::string line{"boardTemp: "}; if (controller::get().feedbackValid) line += std::to_string(controller::get().feedback.boardTemp); return line; } }; struct BoardTempFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"boardTemp: "}; if (controller::get().feedbackValid) line += fmt::format("{:.2f}C", fixBoardTemp(controller::get().feedback.boardTemp)); return line; } }; struct TimeoutCntSerialText : public virtual TextInterface { public: std::string text() const override { std::string line{"timeoutCntSerial: "}; if (controller::get().feedbackValid) line += std::to_string(controller::get().feedback.timeoutCntSerial); return line; } }; diff --git a/main/displays/bmsdisplay.h b/main/displays/bmsdisplay.h index 4897b1b..a9b60c2 100644 --- a/main/displays/bmsdisplay.h +++ b/main/displays/bmsdisplay.h @@ -11,11 +11,6 @@ #include "widgets/label.h" #include "screenmanager.h" -namespace { -class MainMenu; -class MetersDisplay; -class StatusDisplay; -} namespace { #if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) class BmsDisplay : public Display, public ConfirmActionInterface>, public DummyBack diff --git a/main/displays/calibratedisplay.cpp b/main/displays/calibratedisplay.cpp index e69de29..903b53e 100644 --- a/main/displays/calibratedisplay.cpp +++ b/main/displays/calibratedisplay.cpp @@ -0,0 +1,276 @@ +#include "calibratedisplay.h" + +// 3rdparty lib includes +#include +#include + +// local includes +#include "displays/statusdisplay.h" +#include "displays/menus/boardcomputerhardwaresettingsmenu.h" + +CalibrateDisplay::CalibrateDisplay(bool bootup) : + m_bootup{bootup} +{ +} + +std::string CalibrateDisplay::text() const +{ + return TEXT_CALIBRATE; +} + +void CalibrateDisplay::start() +{ + Base::start(); + + m_oldMode = currentMode; + currentMode = &m_mode; + m_selectedButton = 0; + m_status = Status::Begin; + copyFromSettings(); + m_gas = std::nullopt; + m_brems = std::nullopt; +} + +void CalibrateDisplay::initScreen() +{ + Base::initScreen(); + + espgui::tft.setTextFont(4); + espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK); + + espgui::tft.drawString("gas:", 25, 47); + espgui::tft.drawString("brems:", 25, 147); + + for (auto &label : m_labels) + label.start(); + + for (auto &progressBar : m_progressBars) + progressBar.start(); + + m_renderedButton = -1; +} + +void CalibrateDisplay::update() +{ + Base::update(); + + if (raw_gas) + m_gas = cpputils::mapValueClamped(*raw_gas, m_gasMin, m_gasMax, 0., 1000.); + else + m_gas = std::nullopt; + + if (raw_brems) + m_brems = cpputils::mapValueClamped(*raw_brems, m_bremsMin, m_bremsMax, 0., 1000.); + else + m_brems = std::nullopt; +} + +void CalibrateDisplay::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?"; + 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"; + 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"; + 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 CalibrateDisplay::stop() +{ + Base::stop(); + + if (currentMode == &m_mode) + { + // to avoid crash after deconstruction + m_mode.stop(); + lastMode = nullptr; + + currentMode = m_oldMode; + } +} + +void CalibrateDisplay::rotate(int offset) +{ + Base::rotate(offset); + + m_selectedButton += offset; + + if (m_selectedButton < 0) + m_selectedButton = 1; + if (m_selectedButton > 1) + m_selectedButton = 0; +} + +void CalibrateDisplay::back() +{ + Base::back(); + + switch (m_status) + { + case Status::Begin: + if (m_bootup) + espgui::switchScreen(); + else + espgui::switchScreen(); + break; + case Status::GasMin: + case Status::GasMax: + case Status::BremsMin: + case Status::BremsMax: + case Status::Confirm: + m_selectedButton = 0; + m_status = Status::Begin; + copyFromSettings(); + } +} + +void CalibrateDisplay::confirm() +{ + Base::confirm(); + + switch (m_selectedButton) + { + case 0: // left button pressed + if (!raw_gas || !raw_brems || !m_gas || !m_brems) + return; + + switch (m_status) + { + case Status::Begin: + m_status = Status::GasMin; + break; + 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(); + saveSettings(); + if (m_bootup) + espgui::switchScreen(); + else + espgui::switchScreen(); + } + break; + case 1: // right button pressed + back(); + } +} + +void CalibrateDisplay::copyFromSettings() +{ + m_gasMin = settings.boardcomputerHardware.gasMin; + m_gasMax = settings.boardcomputerHardware.gasMax; + m_bremsMin = settings.boardcomputerHardware.bremsMin; + m_bremsMax = settings.boardcomputerHardware.bremsMax; +} + +void CalibrateDisplay::copyToSettings() +{ + settings.boardcomputerHardware.gasMin = m_gasMin; + settings.boardcomputerHardware.gasMax = m_gasMax; + settings.boardcomputerHardware.bremsMin = m_bremsMin; + settings.boardcomputerHardware.bremsMax = m_bremsMax; +} diff --git a/main/displays/calibratedisplay.h b/main/displays/calibratedisplay.h index befda29..45b14bd 100644 --- a/main/displays/calibratedisplay.h +++ b/main/displays/calibratedisplay.h @@ -7,29 +7,26 @@ // 3rdparty lib includes #include #include +#include +#include +#include +#include // local includes -#include "display.h" -#include "actions/switchscreenaction.h" #include "globals.h" #include "utils.h" #include "texts.h" -#include "widgets/label.h" -#include "widgets/progressbar.h" #include "modes/ignoreinputmode.h" -namespace { -class StatusDisplay; -class BoardcomputerHardwareSettingsMenu; -} - -namespace { -class CalibrateDisplay : public Display +class CalibrateDisplay : public espgui::DisplayWithTitle { + using Base = espgui::DisplayWithTitle; + public: CalibrateDisplay() = default; CalibrateDisplay(bool bootup); + std::string text() const override; void start() override; void initScreen() override; void update() override; @@ -50,26 +47,26 @@ private: ModeInterface *m_oldMode; IgnoreInputMode m_mode{0, bobbycar::protocol::ControlType::FieldOrientedControl, bobbycar::protocol::ControlMode::Torque}; - std::array m_labels {{ - Label{25, 72}, // 100, 23 - Label{145, 72}, // 100, 23 - Label{25, 97}, // 100, 23 - Label{145, 97}, // 100, 23 + std::array 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 - Label{25, 172}, // 100, 23 - Label{145, 172}, // 100, 23 - Label{25, 197}, // 100, 23 - Label{145, 197}, // 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 - Label{25, 247}, // 190, 23 + espgui::Label{25, 247}, // 190, 23 - Label{25, 277}, // 100, 23 - Label{145, 277}, // 100, 23 + espgui::Label{25, 277}, // 100, 23 + espgui::Label{145, 277}, // 100, 23 }}; - std::array m_progressBars {{ - ProgressBar{20, 129, 200, 10, 0, 1000}, - ProgressBar{20, 229, 200, 10, 0, 1000} + std::array m_progressBars {{ + espgui::ProgressBar{20, 129, 200, 10, 0, 1000}, + espgui::ProgressBar{20, 229, 200, 10, 0, 1000} }}; enum Status { @@ -87,257 +84,3 @@ private: int16_t m_gasMin, m_gasMax, m_bremsMin, m_bremsMax; std::optional m_gas, m_brems; }; - -CalibrateDisplay::CalibrateDisplay(bool bootup) : - m_bootup{bootup} -{ -} - -void CalibrateDisplay::start() -{ - m_oldMode = currentMode; - currentMode = &m_mode; - m_selectedButton = 0; - m_status = Status::Begin; - copyFromSettings(); - m_gas = std::nullopt; - m_brems = std::nullopt; -} - -void CalibrateDisplay::initScreen() -{ - tft.fillScreen(TFT_BLACK); - tft.setTextFont(4); - tft.setTextColor(TFT_YELLOW); - - tft.drawString(TEXT_CALIBRATE, 5, 5, 4); - - tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE); - - 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 CalibrateDisplay::update() -{ - if (raw_gas) - m_gas = cpputils::mapValueClamped(*raw_gas, m_gasMin, m_gasMax, 0., 1000.); - else - m_gas = std::nullopt; - - if (raw_brems) - m_brems = cpputils::mapValueClamped(*raw_brems, m_bremsMin, m_bremsMax, 0., 1000.); - else - m_brems = std::nullopt; -} - -void CalibrateDisplay::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) - tft.setTextColor(TFT_RED, TFT_BLACK); - m_labels[2].redraw(std::to_string(m_gasMin)); - if (m_status == Status::GasMin) - tft.setTextColor(TFT_WHITE, TFT_BLACK); - if (m_status == Status::GasMax) - tft.setTextColor(TFT_RED, TFT_BLACK); - m_labels[3].redraw(std::to_string(m_gasMax)); - if (m_status == Status::GasMax) - 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) - tft.setTextColor(TFT_RED, TFT_BLACK); - m_labels[6].redraw(std::to_string(m_bremsMin)); - if (m_status == Status::BremsMin) - tft.setTextColor(TFT_WHITE, TFT_BLACK); - if (m_status == Status::BremsMax) - tft.setTextColor(TFT_RED, TFT_BLACK); - m_labels[7].redraw(std::to_string(m_bremsMax)); - if (m_status == Status::BremsMax) - 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?"; - 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; - tft.setTextColor(color, TFT_BLACK); - m_labels[9].redraw([&](){ - switch (m_status) - { - case Status::Begin: return "Yes"; - 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)) - tft.drawRect(3, 275, 100, 27, m_selectedButton == 0 ? color : TFT_BLACK); - } - - tft.setTextColor(TFT_WHITE, TFT_BLACK); - m_labels[10].redraw([&](){ - switch (m_status) - { - case Status::Begin: return "No"; - 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)) - tft.drawRect(123, 275, 100, 27, m_selectedButton == 1 ? TFT_WHITE : TFT_BLACK); - - m_renderedButton = m_selectedButton; -} - -void CalibrateDisplay::stop() -{ - if (currentMode == &m_mode) - { - // to avoid crash after deconstruction - m_mode.stop(); - lastMode = nullptr; - - currentMode = m_oldMode; - } -} - -void CalibrateDisplay::rotate(int offset) -{ - m_selectedButton += offset; - - if (m_selectedButton < 0) - m_selectedButton = 1; - if (m_selectedButton > 1) - m_selectedButton = 0; -} - -void CalibrateDisplay::back() -{ - switch (m_status) - { - case Status::Begin: - if (m_bootup) - switchScreen(); - else - switchScreen(); - break; - case Status::GasMin: - case Status::GasMax: - case Status::BremsMin: - case Status::BremsMax: - case Status::Confirm: - m_selectedButton = 0; - m_status = Status::Begin; - copyFromSettings(); - } -} - -void CalibrateDisplay::confirm() -{ - switch (m_selectedButton) - { - case 0: // left button pressed - if (!raw_gas || !raw_brems || !m_gas || !m_brems) - return; - - switch (m_status) - { - case Status::Begin: - m_status = Status::GasMin; - break; - 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(); - saveSettings(); - if (m_bootup) - switchScreen(); - else - switchScreen(); - } - break; - case 1: // right button pressed - back(); - } -} - -void CalibrateDisplay::copyFromSettings() -{ - m_gasMin = settings.boardcomputerHardware.gasMin; - m_gasMax = settings.boardcomputerHardware.gasMax; - m_bremsMin = settings.boardcomputerHardware.bremsMin; - m_bremsMax = settings.boardcomputerHardware.bremsMax; -} - -void CalibrateDisplay::copyToSettings() -{ - settings.boardcomputerHardware.gasMin = m_gasMin; - settings.boardcomputerHardware.gasMax = m_gasMax; - settings.boardcomputerHardware.bremsMin = m_bremsMin; - settings.boardcomputerHardware.bremsMax = m_bremsMax; -} -} diff --git a/main/displays/calibratevoltagedisplay.cpp b/main/displays/calibratevoltagedisplay.cpp index e69de29..2105c96 100644 --- a/main/displays/calibratevoltagedisplay.cpp +++ b/main/displays/calibratevoltagedisplay.cpp @@ -0,0 +1,82 @@ +#include "calibratevoltagedisplay.h" + +// 3rdparty lib includes +#include +#include +#include + +// local includes +#include "displays/menus/batterymenu.h" +#include "accessors/settingsaccessors.h" + +namespace { +class Save30VCalibrationAction : public virtual espgui::ActionInterface +{ +public: + void triggered() override + { + settings.battery.front30VoltCalibration = controllers.front.feedback.batVoltage; + settings.battery.back30VoltCalibration = controllers.back.feedback.batVoltage; + saveSettings(); + } +}; + +class Save50VCalibrationAction : public virtual espgui::ActionInterface +{ +public: + void triggered() override + { + settings.battery.front50VoltCalibration = controllers.front.feedback.batVoltage; + settings.battery.back50VoltCalibration = controllers.back.feedback.batVoltage; + saveSettings(); + } +}; + +class ResetCalibrationAction : public virtual espgui::ActionInterface +{ +public: + void triggered() override + { + settings.battery.front30VoltCalibration = 3000; + settings.battery.back30VoltCalibration = 3000; + settings.battery.front50VoltCalibration = 5000; + settings.battery.back50VoltCalibration = 5000; + saveSettings(); + } +}; + +float convertToFloat(int16_t value) +{ + return value/100.; +} + +class BatteryVoltageCalibrationFront30VText : public virtual espgui::TextInterface { public: std::string text() const override { return fmt::format("30V Front: {}", convertToFloat(settings.battery.front30VoltCalibration)); } }; +class BatteryVoltageCalibrationBack30VText : public virtual espgui::TextInterface { public: std::string text() const override { return fmt::format("30V Back: {}", convertToFloat(settings.battery.back30VoltCalibration)); } }; +class BatteryVoltageCalibrationFront50VText : public virtual espgui::TextInterface { public: std::string text() const override { return fmt::format("50V Front: {}", convertToFloat(settings.battery.front50VoltCalibration)); } }; +class BatteryVoltageCalibrationBack50VText : public virtual espgui::TextInterface { public: std::string text() const override { return fmt::format("50V Back: {}", convertToFloat(settings.battery.back50VoltCalibration)); } }; +class BatteryVoltageCalibratedText : public virtual espgui::TextInterface { public: std::string text() const override { if (settings.battery.applyCalibration) return fmt::format("F{:.2f}V B{:.2f}", controllers.front.getCalibratedVoltage(), controllers.back.getCalibratedVoltage()); else return "Not activated"; } }; +} // namespace + +using namespace espgui; + +CalibrateVoltageDisplay::CalibrateVoltageDisplay() +{ + constructMenuItem, Save30VCalibrationAction>>(); + constructMenuItem, Save50VCalibrationAction>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, BatteryApplyCalibrationAccessor>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); + + constructMenuItem>(); + + constructMenuItem>(); + constructMenuItem>(); + constructMenuItem>(); + constructMenuItem>(); + constructMenuItem>(); + constructMenuItem, ResetCalibrationAction>>(); +} + +void CalibrateVoltageDisplay::back() +{ + switchScreen(); +} diff --git a/main/displays/calibratevoltagedisplay.h b/main/displays/calibratevoltagedisplay.h index 67c9646..7578b45 100644 --- a/main/displays/calibratevoltagedisplay.h +++ b/main/displays/calibratevoltagedisplay.h @@ -14,78 +14,12 @@ #include "widgets/label.h" #include "globals.h" -using namespace espgui; +class CalibrateVoltageDisplay : + public espgui::MenuDisplay, + public espgui::StaticText +{ +public: + CalibrateVoltageDisplay(); -namespace { - class CalibrateVoltageDisplay; - class BatteryMenu; - - class Save30VCalibrationAction : public virtual ActionInterface - { - public: - void triggered() override { - settings.battery.front30VoltCalibration = controllers.front.feedback.batVoltage; - settings.battery.back30VoltCalibration = controllers.back.feedback.batVoltage; - saveSettings(); - } - }; - - class Save50VCalibrationAction : public virtual ActionInterface - { - public: - void triggered() override { - settings.battery.front50VoltCalibration = controllers.front.feedback.batVoltage; - settings.battery.back50VoltCalibration = controllers.back.feedback.batVoltage; - saveSettings(); - } - }; - - class ResetCalibrationAction : public virtual ActionInterface - { - public: - void triggered() override { - settings.battery.front30VoltCalibration = 3000; - settings.battery.back30VoltCalibration = 3000; - settings.battery.front50VoltCalibration = 5000; - settings.battery.back50VoltCalibration = 5000; - saveSettings(); - } - }; - - float convertToFloat(int16_t value) - { - return value/100.; - } - - class BatteryVoltageCalibrationFront30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Front: {}", convertToFloat(settings.battery.front30VoltCalibration)); } }; - class BatteryVoltageCalibrationBack30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Back: {}", convertToFloat(settings.battery.back30VoltCalibration)); } }; - class BatteryVoltageCalibrationFront50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Front: {}", convertToFloat(settings.battery.front50VoltCalibration)); } }; - class BatteryVoltageCalibrationBack50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Back: {}", convertToFloat(settings.battery.back50VoltCalibration)); } }; - class BatteryVoltageCalibratedText : public virtual TextInterface { public: std::string text() const override { if (settings.battery.applyCalibration) return fmt::format("F{:.2f}V B{:.2f}", controllers.front.getCalibratedVoltage(settings.battery.applyCalibration), controllers.back.getCalibratedVoltage(settings.battery.applyCalibration)); else return "Not activated"; } }; -} - -namespace { - class CalibrateVoltageDisplay : - public MenuDisplay, - public StaticText, - public BackActionInterface> - { - public: - CalibrateVoltageDisplay() - { - constructMenuItem, Save30VCalibrationAction>>(); - constructMenuItem, Save50VCalibrationAction>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, BatteryApplyCalibrationAccessor>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - - constructMenuItem>(); - - constructMenuItem>(); - constructMenuItem>(); - constructMenuItem>(); - constructMenuItem>(); - constructMenuItem>(); - constructMenuItem, ResetCalibrationAction>>(); - } - }; -} // Namespace + void back() override; +}; diff --git a/main/displays/gametrakcalibratedisplay.h b/main/displays/gametrakcalibratedisplay.h index 92bbac5..da5a2b1 100644 --- a/main/displays/gametrakcalibratedisplay.h +++ b/main/displays/gametrakcalibratedisplay.h @@ -11,11 +11,6 @@ #include "widgets/progressbar.h" #include "modes/ignoreinputmode.h" -namespace { -class StatusDisplay; -class BoardcomputerHardwareSettingsMenu; -} - namespace { #ifdef FEATURE_GAMETRAK class GametrakCalibrateDisplay : public Display, public ConfirmActionInterface>, public BackActionInterface> diff --git a/main/displays/menus/aboutmenu.cpp b/main/displays/menus/aboutmenu.cpp index e69de29..548eb41 100644 --- a/main/displays/menus/aboutmenu.cpp +++ b/main/displays/menus/aboutmenu.cpp @@ -0,0 +1,46 @@ +#include "aboutmenu.h" + +// local includes +#include "utils.h" +#include "actions/dummyaction.h" +#include "actions/switchscreenaction.h" +#include "icons/back.h" +#include "esptexthelpers.h" +#ifdef FEATURE_OTA +#include +#include +#include "fmt/core.h" +#endif + +AboutMenu::AboutMenu() +{ + constructMenuItem>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); +#ifndef HEAP_LRGST_CRASH_TEXT_FIX + constructMenuItem, DisabledColor, DummyAction>>(); +#endif + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); +#ifndef HEAP_LRGST_CRASH_TEXT_FIX + constructMenuItem, DisabledColor, DummyAction>>(); +#endif + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void AboutMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/aboutmenu.h b/main/displays/menus/aboutmenu.h index 4e8a8c5..b3a30bc 100644 --- a/main/displays/menus/aboutmenu.h +++ b/main/displays/menus/aboutmenu.h @@ -1,29 +1,15 @@ #pragma once -// local includes -#include "menudisplay.h" -#include "utils.h" -#include "actions/dummyaction.h" -#include "actions/switchscreenaction.h" -#include "icons/back.h" -#include "esptexthelpers.h" -#include "texts.h" -#ifdef FEATURE_OTA -#include -#include -#include "fmt/core.h" -#endif +// 3rdparty lib includes +#include -// forward declares -namespace { -class SettingsMenu; -} // namespace +// local includes +#include "texts.h" using namespace espgui; namespace { - -class currentVersionText : public virtual TextInterface { public: std::string text() const override { +class CurrentVersionText : public virtual TextInterface { public: std::string text() const override { #ifdef FEATURE_OTA if (const esp_app_desc_t *app_desc = esp_ota_get_app_description()) { @@ -38,36 +24,11 @@ constexpr char TEXT_VERSION[] = "Version: 1.0"; class AboutMenu : public MenuDisplay, - public StaticText, - public BackActionInterface> + public StaticText { public: - AboutMenu() - { - constructMenuItem>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); -#ifndef HEAP_LRGST_CRASH_TEXT_FIX - constructMenuItem, DisabledColor, DummyAction>>(); -#endif - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); -#ifndef HEAP_LRGST_CRASH_TEXT_FIX - constructMenuItem, DisabledColor, DummyAction>>(); -#endif - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + AboutMenu(); + + void back() override; }; } // namespace diff --git a/main/displays/menus/batterymenu.cpp b/main/displays/menus/batterymenu.cpp index e69de29..3b3ae97 100644 --- a/main/displays/menus/batterymenu.cpp +++ b/main/displays/menus/batterymenu.cpp @@ -0,0 +1,55 @@ +#include "batterymenu.h" + +// 3rdparty lib includes +#include + +// local includes +#include "mainmenu.h" +#include "displays/calibratevoltagedisplay.h" +#include "accessors/settingsaccessors.h" + +class CurrentBatteryStatusText : public virtual espgui::TextInterface { public: std::string text() const override { return getBatteryPercentageString(); } }; + +using BatteryCellSeriesChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + BatterySeriesCellsAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +using BatteryCellParallelChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + BatteryParallelCellsAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +using BatteryWHperKMChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + BatteryWHperKMAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +using namespace espgui; + +BatteryMenu::BatteryMenu() +{ + constructMenuItem>(); + constructMenuItem>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::settings>>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void BatteryMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/batterymenu.h b/main/displays/menus/batterymenu.h index 8419a84..44c4668 100644 --- a/main/displays/menus/batterymenu.h +++ b/main/displays/menus/batterymenu.h @@ -1,71 +1,25 @@ #pragma once +// 3rdparty lib includes +#include +#include +#include +#include +#include + // Local includes -#include "menudisplay.h" #include "utils.h" -#include "menuitem.h" -#include "icons/back.h" #include "icons/settings.h" #include "texts.h" -#include "actions/dummyaction.h" -#include "actions/switchscreenaction.h" -#include "mainmenu.h" #include "battery.h" #include "selectbatterytypemenu.h" -#include "displays/calibratevoltagedisplay.h" -// Helper -class currentBatteryStatus : public virtual TextInterface { public: std::string text() const override { return getBatteryPercentageString(); } }; +class BatteryMenu : + public espgui::MenuDisplay, + public espgui::StaticText +{ +public: + BatteryMenu(); -using namespace espgui; - -namespace { - class BatteryMenu; - class CalibrateVoltageDisplay; - - using BatteryCellSeriesChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - BatterySeriesCellsAccessor, - BackActionInterface>, - SwitchScreenAction - >; - - using BatteryCellParallelChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - BatteryParallelCellsAccessor, - BackActionInterface>, - SwitchScreenAction - >; - - using BatteryWHperKMChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - BatteryWHperKMAccessor, - BackActionInterface>, - SwitchScreenAction - >; -} - -namespace { - class BatteryMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> - { - public: - BatteryMenu() - { - constructMenuItem>(); - constructMenuItem>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::settings>>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } - }; -} // Namespace + void back() override; +}; diff --git a/main/displays/menus/blesettingsmenu.h b/main/displays/menus/blesettingsmenu.h index 7e4ea02..62e550f 100644 --- a/main/displays/menus/blesettingsmenu.h +++ b/main/displays/menus/blesettingsmenu.h @@ -11,11 +11,6 @@ #include "icons/back.h" #include "texts.h" -// forward declares -namespace { -class SettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/bluetoothsettingsmenu.h b/main/displays/menus/bluetoothsettingsmenu.h index 26de103..965121a 100644 --- a/main/displays/menus/bluetoothsettingsmenu.h +++ b/main/displays/menus/bluetoothsettingsmenu.h @@ -21,11 +21,6 @@ #include "icons/back.h" #include "texts.h" -// forward declares -namespace { -class SettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/boardcomputerhardwaresettingsmenu.cpp b/main/displays/menus/boardcomputerhardwaresettingsmenu.cpp index e69de29..afe098a 100644 --- a/main/displays/menus/boardcomputerhardwaresettingsmenu.cpp +++ b/main/displays/menus/boardcomputerhardwaresettingsmenu.cpp @@ -0,0 +1,183 @@ +#include "boardcomputerhardwaresettingsmenu.h" + +// 3rdparty lib includes +#include +#include +#include +#include +#include +#include +#include + +// local includes +#include "utils.h" +#include "icons/lock.h" +#include "accessors/settingsaccessors.h" +#include "displays/menus/lockscreensettingsmenu.h" +#include "displays/calibratedisplay.h" + +namespace { +struct GasText : public virtual espgui::TextInterface { +public: + std::string text() const override + { + return fmt::format("{}: {}: {}", + "gas", + raw_gas ? std::to_string(*raw_gas) : "?", + gas ? fmt::format("{:.02f}", *gas) : "?"); + } +}; +struct BremsText : public virtual espgui::TextInterface { +public: + std::string text() const override + { + return fmt::format("{}: {}: {}", + "brems", + raw_brems ? std::to_string(*raw_brems) : "?", + brems ? fmt::format("{:.02f}", *brems) : "?"); + } +}; + +using SampleCountChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + SampleCountAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using GasMinChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + GasMinAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using GasMaxChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + GasMaxAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using BremsMinChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + BremsMinAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using BremsMaxChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + BremsMaxAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +#if defined(FEATURE_DPAD) || defined(FEATURE_DPAD_3WIRESW) || defined(FEATURE_DPAD_5WIRESW) || defined(FEATURE_DPAD_5WIRESW_2OUT) || defined (FEATURE_DPAD_6WIRESW) +using DPadDebounceChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + DPadDebounceAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +#endif + +#ifdef FEATURE_GAMETRAK +struct GametrakXText : public virtual TextInterface { +public: + std::string text() const override { return fmt::format("gametrakX: {}: {:.02f}", raw_gametrakX, gametrakX); } +}; +struct GametrakYText : public virtual TextInterface { +public: + std::string text() const override { return fmt::format("gametrakY: {}: {:.02f}", raw_gametrakY, gametrakY); } +}; +struct GametrakDistText : public virtual TextInterface { +public: + std::string text() const override { return fmt::format("gametrakDist: {}: {:.02f}", raw_gametrakDist, gametrakDist); } +}; + +using GametrakXMinChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + GametrakXMinAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using GametrakXMaxChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + GametrakXMaxAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using GametrakYMinChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + GametrakYMinAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using GametrakYMaxChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + GametrakYMaxAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using GametrakDistMinChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + GametrakDistMinAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using GametrakDistMaxChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + GametrakDistMaxAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +#endif +} // namespace + +using namespace espgui; + +BoardcomputerHardwareSettingsMenu::BoardcomputerHardwareSettingsMenu() +{ + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::lock>>>(); + constructMenuItem, DummyAction>>(); + constructMenuItem, DummyAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); +#if defined(FEATURE_DPAD) || defined(FEATURE_DPAD_3WIRESW) || defined(FEATURE_DPAD_5WIRESW) || defined(FEATURE_DPAD_5WIRESW_2OUT) || defined (FEATURE_DPAD_6WIRESW) + constructMenuItem, SwitchScreenAction>>(); +#endif +#ifdef FEATURE_GAMETRAK + constructMenuItem, + constructMenuItem, DummyAction>>(); + constructMenuItem, DummyAction>>(); + constructMenuItem, DummyAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); +#endif + constructMenuItem>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); +} + +void BoardcomputerHardwareSettingsMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/boardcomputerhardwaresettingsmenu.h b/main/displays/menus/boardcomputerhardwaresettingsmenu.h index 9fd6e0c..ffd61fa 100644 --- a/main/displays/menus/boardcomputerhardwaresettingsmenu.h +++ b/main/displays/menus/boardcomputerhardwaresettingsmenu.h @@ -1,195 +1,15 @@ #pragma once -// 3rdparty lib includes -#include - // local includes #include "menudisplay.h" -#include "utils.h" -#include "changevaluedisplay.h" -#include "actions/dummyaction.h" -#include "actions/switchscreenaction.h" -#include "actions/toggleboolaction.h" -#include "icons/lock.h" -#include "icons/back.h" -#include "checkboxicon.h" #include "texts.h" -#include "accessors/settingsaccessors.h" - -// forward declares -namespace { -class BoardcomputerHardwareSettingsMenu; -class LockscreenSettingsMenu; -class CalibrateDisplay; -class GametrakCalibrateDisplay; -class TimersMenu; -class SettingsMenu; -} // namespace - -using namespace espgui; - -namespace { -struct GasText : public virtual TextInterface { -public: - std::string text() const override - { - return fmt::format("{}: {}: {}", - "gas", - raw_gas ? std::to_string(*raw_gas) : "?", - gas ? fmt::format("{:.02f}", *gas) : "?"); - } -}; -struct BremsText : public virtual TextInterface { -public: - std::string text() const override - { - return fmt::format("{}: {}: {}", - "brems", - raw_brems ? std::to_string(*raw_brems) : "?", - brems ? fmt::format("{:.02f}", *brems) : "?"); - } -}; - -using SampleCountChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - SampleCountAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using GasMinChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - GasMinAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using GasMaxChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - GasMaxAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using BremsMinChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - BremsMinAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using BremsMaxChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - BremsMaxAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -#if defined(FEATURE_DPAD) || defined(FEATURE_DPAD_3WIRESW) || defined(FEATURE_DPAD_5WIRESW) || defined(FEATURE_DPAD_5WIRESW_2OUT) || defined (FEATURE_DPAD_6WIRESW) -using DPadDebounceChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - DPadDebounceAccessor, - BackActionInterface>, - SwitchScreenAction ->; -#endif - -#ifdef FEATURE_GAMETRAK -struct GametrakXText : public virtual TextInterface { -public: - std::string text() const override { return fmt::format("gametrakX: {}: {:.02f}", raw_gametrakX, gametrakX); } -}; -struct GametrakYText : public virtual TextInterface { -public: - std::string text() const override { return fmt::format("gametrakY: {}: {:.02f}", raw_gametrakY, gametrakY); } -}; -struct GametrakDistText : public virtual TextInterface { -public: - std::string text() const override { return fmt::format("gametrakDist: {}: {:.02f}", raw_gametrakDist, gametrakDist); } -}; - -using GametrakXMinChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - GametrakXMinAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using GametrakXMaxChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - GametrakXMaxAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using GametrakYMinChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - GametrakYMinAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using GametrakYMaxChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - GametrakYMaxAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using GametrakDistMinChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - GametrakDistMinAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using GametrakDistMaxChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - GametrakDistMaxAccessor, - BackActionInterface>, - SwitchScreenAction ->; -#endif class BoardcomputerHardwareSettingsMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - BoardcomputerHardwareSettingsMenu() - { - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::lock>>>(); - constructMenuItem, DummyAction>>(); - constructMenuItem, DummyAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); -#if defined(FEATURE_DPAD) || defined(FEATURE_DPAD_3WIRESW) || defined(FEATURE_DPAD_5WIRESW) || defined(FEATURE_DPAD_5WIRESW_2OUT) || defined (FEATURE_DPAD_6WIRESW) - constructMenuItem, SwitchScreenAction>>(); -#endif -#ifdef FEATURE_GAMETRAK - constructMenuItem, - constructMenuItem, DummyAction>>(); - constructMenuItem, DummyAction>>(); - constructMenuItem, DummyAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); -#endif - constructMenuItem>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + BoardcomputerHardwareSettingsMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/menus/buzzermenu.h b/main/displays/menus/buzzermenu.h index 12b7db9..c3505d6 100644 --- a/main/displays/menus/buzzermenu.h +++ b/main/displays/menus/buzzermenu.h @@ -13,12 +13,6 @@ #include "globals.h" #include "accessors/settingsaccessors.h" -// forward declares -namespace { -class BuzzerMenu; -class SettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/cloudsettingsmenu.h b/main/displays/menus/cloudsettingsmenu.h index 348be8c..42b8ad8 100644 --- a/main/displays/menus/cloudsettingsmenu.h +++ b/main/displays/menus/cloudsettingsmenu.h @@ -17,12 +17,6 @@ #include "accessors/settingsaccessors.h" #include "cloud.h" -// forward declares -namespace { -class CloudSettingsMenu; -class SettingsMenu; -} // namespace - namespace { using CloudTransmitTimeoutChangeScreen = makeComponent< ChangeValueDisplay, diff --git a/main/displays/menus/controllerhardwaresettingsmenu.h b/main/displays/menus/controllerhardwaresettingsmenu.h index 3f1020c..cff93df 100644 --- a/main/displays/menus/controllerhardwaresettingsmenu.h +++ b/main/displays/menus/controllerhardwaresettingsmenu.h @@ -14,15 +14,6 @@ #include "globals.h" #include "accessors/settingsaccessors.h" -// forward declares -namespace { -class ControllerHardwareSettingsMenu; -class BoardcomputerHardwareSettingsMenu; -class EnableMenu; -class InvertMenu; -class SettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/crashmenu.h b/main/displays/menus/crashmenu.h index 20bc6f4..0af4a24 100644 --- a/main/displays/menus/crashmenu.h +++ b/main/displays/menus/crashmenu.h @@ -9,11 +9,6 @@ #include "icons/back.h" #include "texts.h" -// forward declares -namespace { -class SettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/limitssettingsmenu.h b/main/displays/menus/limitssettingsmenu.h index dd749fc..a40417c 100644 --- a/main/displays/menus/limitssettingsmenu.h +++ b/main/displays/menus/limitssettingsmenu.h @@ -10,12 +10,6 @@ #include "texts.h" #include "accessors/settingsaccessors.h" -// forward declares -namespace { -class LimitsSettingsMenu; -class SettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/lockscreensettingsmenu.h b/main/displays/menus/lockscreensettingsmenu.h index 4429605..d1a2d2b 100644 --- a/main/displays/menus/lockscreensettingsmenu.h +++ b/main/displays/menus/lockscreensettingsmenu.h @@ -12,12 +12,6 @@ #include "accessors/settingsaccessors.h" #include "changevaluedisplay.h" -// forward declares -namespace { -class BoardcomputerHardwareSettingsMenu; -class LockscreenSettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/mainmenu.cpp b/main/displays/menus/mainmenu.cpp index e69de29..78df003 100644 --- a/main/displays/menus/mainmenu.cpp +++ b/main/displays/menus/mainmenu.cpp @@ -0,0 +1,90 @@ +#include "mainmenu.h" + +// 3rdparty lib includes +#include "actions/switchscreenaction.h" +#include "icons/back.h" + +// local includes +#include "displays/statusdisplay.h" +#include "displays/menus/selectmodemenu.h" +#include "displays/menus/selectmodemenu.h" +#include "displays/menus/ledstripmenu.h" +#include "actions/modesettingsaction.h" +#include "displays/menus/presetsmenu.h" +#include "displays/menus/profilesmenu.h" +#include "displays/menus/graphsmenu.h" +#include "displays/menus/batterymenu.h" +#include "displays/powersupplydisplay.h" +#include "displays/menus/bmsmenu.h" +#include "displays/menus/settingsmenu.h" +#include "displays/menus/mosfetsmenu.h" +#include "displays/menus/demosmenu.h" +#include "displays/lockscreen.h" +#include "displays/garagedisplay.h" +#include "displays/menus/otamenu.h" +#include "displays/poweroffdisplay.h" +#include "actions/rebootaction.h" +#include "displays/menus/debugmenu.h" +#include "icons/battery.h" +#include "icons/modes.h" +#include "icons/presets.h" +#include "icons/graph.h" +#ifdef FEATURE_BMS +#include "icons/bms.h" +#endif +#include "icons/settings.h" +#include "icons/lock.h" +#include "icons/demos.h" +#ifdef FEATURE_OTA +#include "icons/update.h" +#endif +#ifdef FEATURE_LEDSTRIP +#include "icons/neopixel.h" +#endif +#include "icons/poweroff.h" +#include "icons/reboot.h" + +using namespace espgui; + +MainMenu::MainMenu() +{ + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::modes>>>(); +#ifdef FEATURE_LEDSTRIP + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::neopixel>>>(); +#endif + if (SHOWITEM) { constructMenuItem, ModeSettingsAction>>(); } + if (SHOWITEM) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::presets>>>(); } + if (SHOWITEM) { constructMenuItem, SwitchScreenAction>>(); } + if (SHOWITEM) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::graph>>>(); } + if (SHOWITEM) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::battery>>>(); } +#if defined(FEATURE_CAN) && defined(FEATURE_POWERSUPPLY) + if (SHOWITEM) { constructMenuItem, SwitchScreenAction>>(); } +#endif +#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) + if (SHOWITEM) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::bms>>>(); } +#endif + if (SHOWITEM) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::settings>>>(); } +#ifdef FEATURE_MOSFETS + if (SHOWITEM) { constructMenuItem, SwitchScreenAction>>(); } +#endif + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::demos>>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::lock>>>(); +#ifdef FEATURE_GARAGE + if (SHOWITEM) { constructMenuItem, SwitchScreenAction>>(); } +#endif +#ifdef FEATURE_OTA + if (SHOWITEM) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::update>>>(); } +#endif + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::poweroff>>>(); + constructMenuItem, RebootAction, StaticMenuItemIcon<&bobbyicons::reboot>>>(); + if (SHOWITEM) { constructMenuItem, SwitchScreenAction>>(); } +#ifdef MAINMENU_PLUGIN + GMEN1 +#endif +} + +void MainMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/mainmenu.h b/main/displays/menus/mainmenu.h index 5b76179..ba241b2 100644 --- a/main/displays/menus/mainmenu.h +++ b/main/displays/menus/mainmenu.h @@ -1,55 +1,16 @@ #pragma once -// local includes +// 3rdparty lib includes #include "menudisplay.h" #include "menuitem.h" -#include "batterymenu.h" -#include "actions/switchscreenaction.h" -#include "actions/modesettingsaction.h" -#include "actions/rebootaction.h" + +// local includes #include "texts.h" -#include "icons/back.h" -#include "icons/battery.h" -#include "icons/modes.h" -#include "icons/presets.h" -#include "icons/graph.h" -#ifdef FEATURE_BMS -#include "icons/bms.h" -#endif -#include "icons/settings.h" -#include "icons/lock.h" -#include "icons/demos.h" -#ifdef FEATURE_OTA -#include "icons/update.h" -#endif -#ifdef FEATURE_LEDSTRIP -#include "icons/neopixel.h" -#endif -#include "icons/poweroff.h" -#include "icons/reboot.h" #ifdef MAINMENU_PLUGIN #include MAINMENU_PLUGIN #endif -// forward declares namespace { -class StatusDisplay; -class SelectModeMenu; -class LedstripMenu; -class ProfilesMenu; -class PresetsMenu; -class GraphsMenu; -class PowerSupplyDisplay; -class BmsMenu; -class SettingsMenu; -class Lockscreen; -class MosfetsMenu; -class DemosMenu; -class GarageDisplay; -class OtaMenu; -class PoweroffDisplay; -class DebugMenu; -class BatteryMenu; #ifdef MAINMENU_PLUGIN GMEN2 #endif @@ -60,51 +21,12 @@ class BatteryMenu; #endif } // namespace -using namespace espgui; - -namespace { class MainMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - MainMenu() - { - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::modes>>>(); -#ifdef FEATURE_LEDSTRIP - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::neopixel>>>(); -#endif - if (SHOWITEM) { constructMenuItem, ModeSettingsAction>>(); } - if (SHOWITEM) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::presets>>>(); } - if (SHOWITEM) { constructMenuItem, SwitchScreenAction>>(); } - if (SHOWITEM) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::graph>>>(); } - if (SHOWITEM) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::battery>>>(); } -#if defined(FEATURE_CAN) && defined(FEATURE_POWERSUPPLY) - if (SHOWITEM) { constructMenuItem, SwitchScreenAction>>(); } -#endif -#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) - if (SHOWITEM) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::bms>>>(); } -#endif - if (SHOWITEM) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::settings>>>(); } -#ifdef FEATURE_MOSFETS - if (SHOWITEM) { constructMenuItem, SwitchScreenAction>>(); } -#endif - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::demos>>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::lock>>>(); -#ifdef FEATURE_GARAGE - if (SHOWITEM) { constructMenuItem, SwitchScreenAction>>(); } -#endif -#ifdef FEATURE_OTA - if (SHOWITEM) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::update>>>(); } -#endif - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::poweroff>>>(); - constructMenuItem, RebootAction, StaticMenuItemIcon<&bobbyicons::reboot>>>(); - if (SHOWITEM) { constructMenuItem, SwitchScreenAction>>(); } -#ifdef MAINMENU_PLUGIN - GMEN1 -#endif - } + MainMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/menus/modessettingsmenu.h b/main/displays/menus/modessettingsmenu.h index b5016f2..5394071 100644 --- a/main/displays/menus/modessettingsmenu.h +++ b/main/displays/menus/modessettingsmenu.h @@ -7,15 +7,6 @@ #include "icons/back.h" #include "texts.h" -// forward declares -namespace { -class DefaultModeSettingsMenu; -class TempomatModeSettingsMenu; -class LarsmModeSettingsMenu; -class GametrakModeSettingsMenu; -class SettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/otamenu.h b/main/displays/menus/otamenu.h index f4bf45c..30dbacb 100644 --- a/main/displays/menus/otamenu.h +++ b/main/displays/menus/otamenu.h @@ -11,15 +11,6 @@ #include "texts.h" #include "buildserver.h" - -// forward declares -namespace { -class MainMenu; -class UpdateDisplay; -class SelectBuildMenu; -class SelectBuildServerMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/selectbatterytypemenu.cpp b/main/displays/menus/selectbatterytypemenu.cpp index e69de29..315fe78 100644 --- a/main/displays/menus/selectbatterytypemenu.cpp +++ b/main/displays/menus/selectbatterytypemenu.cpp @@ -0,0 +1,35 @@ +#include "selectbatterytypemenu.h" + +// local includes +#include "battery.h" +#include "globals.h" +#include "utils.h" +#include "displays/menus/batterymenu.h" + +namespace { +class CurrentBatteryTypeText : public virtual espgui::TextInterface { public: std::string text() const override { return getBatteryCellTypeString(); } }; + +template +class BatterySelectTypeAction : public virtual espgui::ActionInterface +{ +public: + void triggered() override { settings.battery.cellType = uint8_t(T); saveSettings(); } +}; +} // namespace + +using namespace espgui; + +BatteryTypeMenu::BatteryTypeMenu() +{ + constructMenuItem>(); + constructMenuItem, BatterySelectTypeAction>>(); + constructMenuItem, BatterySelectTypeAction>>(); + constructMenuItem, BatterySelectTypeAction>>(); + constructMenuItem, BatterySelectTypeAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void BatteryTypeMenu::back() +{ + espgui::switchScreen(); +} diff --git a/main/displays/menus/selectbatterytypemenu.h b/main/displays/menus/selectbatterytypemenu.h index a0033c8..00b9a56 100644 --- a/main/displays/menus/selectbatterytypemenu.h +++ b/main/displays/menus/selectbatterytypemenu.h @@ -1,48 +1,23 @@ #pragma once +// 3rdparty lib includes +#include +#include +#include +#include +#include + // Local includes -#include "menudisplay.h" -#include "utils.h" -#include "menuitem.h" -#include "icons/back.h" #include "texts.h" -#include "actions/switchscreenaction.h" #include "batterymenu.h" -#include "battery.h" -#include "actioninterface.h" +#include "displays/menus/mainmenu.h" -// Helper -class currentBatteryType : public virtual TextInterface { public: std::string text() const override { return getBatteryCellTypeString(); } }; +class BatteryTypeMenu : + public espgui::MenuDisplay, + public espgui::StaticText +{ +public: + BatteryTypeMenu(); -using namespace espgui; - -namespace { - class BatteryTypeMenu; - class BatteryMenu; - - template - class BatterySelectTypeAction : public virtual ActionInterface - { - public: - void triggered() override { settings.battery.cellType = uint8_t(T); saveSettings(); } - }; -} // namespace - -namespace { - class BatteryTypeMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> - { - public: - BatteryTypeMenu() - { - constructMenuItem>(); - constructMenuItem, BatterySelectTypeAction>>(); - constructMenuItem, BatterySelectTypeAction>>(); - constructMenuItem, BatterySelectTypeAction>>(); - constructMenuItem, BatterySelectTypeAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } - }; -} // Namespace + void back() override; +}; diff --git a/main/displays/menus/selectbuildservermenu.cpp b/main/displays/menus/selectbuildservermenu.cpp new file mode 100644 index 0000000..cc9413b --- /dev/null +++ b/main/displays/menus/selectbuildservermenu.cpp @@ -0,0 +1,71 @@ +#include "selectbuildservermenu.h" + +// esp-idf includes +#include + +// 3rdparty lib includes +#include +#include + +// local includes +#include "displays/menus/settingsmenu.h" + +namespace { +class BuildserverMenuItem : public espgui::MenuItem +{ +public: + std::string text() const override { return m_buildserver_name; } + void setBuildserverName(std::string &&buildserver_name) { m_buildserver_name = std::move(buildserver_name); } + void setBuildserverName(const std::string &buildserver_name) { m_buildserver_name = buildserver_name; } + void setBuildserverUrl(std::string &&buildserver_url) { m_buildserver_url = std::move(buildserver_url); } + void setBuildserverUrl(const std::string &buildserver_url) { m_buildserver_url = buildserver_url; } + + void triggered() override + { + stringSettings.otaServerUrl = m_buildserver_url; + if (m_buildserver_url.substr(m_buildserver_url.length() - 4) == ".bin") + { + stringSettings.otaUrl = m_buildserver_url; + } + saveSettings(); + redownload = true; + url_for_latest.clear(); + url_for_hashes.clear(); + availableVersions = {}; + } + +private: + std::string m_buildserver_url; + std::string m_buildserver_name; +}; +} // namespace + +using namespace espgui; + +SelectBuildServerMenu::SelectBuildServerMenu() +{ + for (const auto &otaServer : stringSettings.otaServers) + { + std::string url = otaServer.url; + std::string name = (otaServer.name.empty()) ? url : otaServer.name; + + if (!name.empty()) + { + auto &menuitem = constructMenuItem(); + menuitem.setBuildserverName(name); + menuitem.setBuildserverUrl(url); + } + } + + if (menuItemCount() < 1) + { + constructMenuItem, DefaultFont, StaticColor, DummyAction>>(); + } + + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void SelectBuildServerMenu::back() +{ + espgui::switchScreen(); +} diff --git a/main/displays/menus/selectbuildservermenu.h b/main/displays/menus/selectbuildservermenu.h index 0caa71b..aae8471 100644 --- a/main/displays/menus/selectbuildservermenu.h +++ b/main/displays/menus/selectbuildservermenu.h @@ -1,87 +1,22 @@ #pragma once // 3rdparty lib includes -#include +#include +#include +#include // local includes -#include "menudisplay.h" #include "utils.h" -#include "actions/dummyaction.h" -#include "icons/back.h" #include "texts.h" #include "globals.h" #include "buildserver.h" -// Debugging -#include "esp_log.h" -#include "fmt/core.h" - - -// forward declares -namespace { -class SettingsMenu; -} // namespace - -using namespace espgui; - -namespace { - -class BuildserverMenuItem : public MenuItem -{ - -public: - - std::string text() const override { return m_buildserver_name; } - void setBuildserverName(std::string &&buildserver_name) { m_buildserver_name = std::move(buildserver_name); } - void setBuildserverName(const std::string &buildserver_name) { m_buildserver_name = buildserver_name; } - void setBuildserverUrl(std::string &&buildserver_url) { m_buildserver_url = std::move(buildserver_url); } - void setBuildserverUrl(const std::string &buildserver_url) { m_buildserver_url = buildserver_url; } - - void triggered() override - { - stringSettings.otaServerUrl = m_buildserver_url; - if (m_buildserver_url.substr(m_buildserver_url.length() - 4) == ".bin") - { - stringSettings.otaUrl = m_buildserver_url; - } - saveSettings(); - redownload = true; - url_for_latest.clear(); - url_for_hashes.clear(); - availableVersions = {}; - } - -private: - std::string m_buildserver_url; - std::string m_buildserver_name; -}; - class SelectBuildServerMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - SelectBuildServerMenu() { + SelectBuildServerMenu(); - for (const auto &otaServer : stringSettings.otaServers) - { - std::string url = otaServer.url; - std::string name = (otaServer.name.empty()) ? url : otaServer.name; - - if (!name.empty()) { - auto &menuitem = constructMenuItem(); - menuitem.setBuildserverName(name); - menuitem.setBuildserverUrl(url); - } - } - - if (menuItemCount() < 1) - { - constructMenuItem, DefaultFont, StaticColor, DummyAction>>(); - } - - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + void back() override; }; -} // namespace diff --git a/main/displays/menus/settingsmenu.cpp b/main/displays/menus/settingsmenu.cpp index e69de29..db53ff4 100644 --- a/main/displays/menus/settingsmenu.cpp +++ b/main/displays/menus/settingsmenu.cpp @@ -0,0 +1,94 @@ +#include "settingsmenu.h" + +// Arduino includes +#include + +// 3rdparty lib includes +#include "actions/toggleboolaction.h" +#include "actions/switchscreenaction.h" +#include "checkboxicon.h" +#include "icons/back.h" + +// local includes +#include "utils.h" +#include "icons/wifi.h" +#if defined(FEATURE_BLUETOOTH) || defined(FEATURE_BLE) +#include "icons/bluetooth.h" +#endif +#include "icons/time.h" +#include "icons/hardware.h" +#include "icons/buzzer.h" +#include "icons/info.h" +#include "icons/demos.h" +#include "icons/update.h" +#include "globals.h" +#include "accessors/settingsaccessors.h" +#include "displays/menus/limitssettingsmenu.h" +#include "displays/menus/wifisettingsmenu.h" +#include "displays/menus/bluetoothsettingsmenu.h" +#include "displays/menus/blesettingsmenu.h" +#include "displays/menus/cloudsettingsmenu.h" +#include "displays/menus/selectbuildservermenu.h" +#include "displays/menus/timesettingsmenu.h" +#include "displays/menus/modessettingsmenu.h" +#include "displays/menus/controllerhardwaresettingsmenu.h" +#include "displays/menus/boardcomputerhardwaresettingsmenu.h" +#include "displays/menus/buzzermenu.h" +#include "displays/menus/crashmenu.h" +#include "displays/menus/aboutmenu.h" +#include "displays/menus/mainmenu.h" + +namespace { +#ifdef FEATURE_LEDBACKLIGHT +struct BacklightAccessor : public virtual espgui::AccessorInterface +{ + bool getValue() const override { return digitalRead(PINS_LEDBACKLIGHT) != ledBacklightInverted; } + void setValue(bool value) override { digitalWrite(PINS_LEDBACKLIGHT, value != ledBacklightInverted); } +}; +#endif +struct FrontLedAccessor : public espgui::RefAccessor { bool &getRef() const override { return controllers.front.command.led; } }; +struct BackLedAccessor : public espgui::RefAccessor { bool &getRef() const override { return controllers.back.command.led; } }; +} // namespace + +using namespace espgui; + +SettingsMenu::SettingsMenu() +{ +#ifdef FEATURE_LEDBACKLIGHT + constructMenuItem, ToggleBoolAction, CheckboxIcon, BacklightAccessor>>(); +#endif + if (!simplified) + constructMenuItem, SwitchScreenAction>>(); + + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::wifi>>>(); +#ifdef FEATURE_BLUETOOTH + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::bluetooth>>>(); +#endif +#ifdef FEATURE_BLE + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::bluetooth>>>(); +#endif +#ifdef FEATURE_CLOUD + constructMenuItem, SwitchScreenAction>>(); +#endif +#ifdef FEATURE_OTA + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::update>>>(); +#endif + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::time>>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::hardware>>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::hardware>>>(); +#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) + constructMenuItem, ToggleBoolAction, CheckboxIcon, AutoConnectBmsAccessor>>(); +#endif + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::buzzer>>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, FrontLedAccessor>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, BackLedAccessor>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::demos>>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::info>>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void SettingsMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/settingsmenu.h b/main/displays/menus/settingsmenu.h index bbbdfd7..346ecd5 100644 --- a/main/displays/menus/settingsmenu.h +++ b/main/displays/menus/settingsmenu.h @@ -1,98 +1,17 @@ #pragma once -// local includes +// 3rdparty lib includes #include "menudisplay.h" -#include "utils.h" -#include "actions/toggleboolaction.h" -#include "actions/switchscreenaction.h" -#include "checkboxicon.h" -#include "icons/wifi.h" -#if defined(FEATURE_BLUETOOTH) || defined(FEATURE_BLE) -#include "icons/bluetooth.h" -#endif -#include "icons/time.h" -#include "icons/hardware.h" -#include "icons/buzzer.h" -#include "icons/info.h" -#include "icons/demos.h" -#include "icons/back.h" -#include "icons/update.h" + +// local includes #include "texts.h" -#include "globals.h" -#include "accessors/settingsaccessors.h" - -// forward declares -namespace { -class LimitsSettingsMenu; -class WifiSettingsMenu; -class BluetoothSettingsMenu; -class BleSettingsMenu; -class CloudSettingsMenu; -class TimeSettingsMenu; -class ModesSettingsMenu; -class ControllerHardwareSettingsMenu; -class BoardcomputerHardwareSettingsMenu; -class BuzzerMenu; -class AboutMenu; -class MainMenu; -class CrashMenu; -class SelectBuildServerMenu; -} - -using namespace espgui; - -namespace { -#ifdef FEATURE_LEDBACKLIGHT -struct BacklightAccessor : public virtual AccessorInterface -{ - bool getValue() const override { return digitalRead(PINS_LEDBACKLIGHT) != ledBacklightInverted; } - void setValue(bool value) override { digitalWrite(PINS_LEDBACKLIGHT, value != ledBacklightInverted); } -}; -#endif -struct FrontLedAccessor : public RefAccessor { bool &getRef() const override { return controllers.front.command.led; } }; -struct BackLedAccessor : public RefAccessor { bool &getRef() const override { return controllers.back.command.led; } }; class SettingsMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - SettingsMenu() - { -#ifdef FEATURE_LEDBACKLIGHT - constructMenuItem, ToggleBoolAction, CheckboxIcon, BacklightAccessor>>(); -#endif - if (!simplified) - { - constructMenuItem, SwitchScreenAction>>(); - } - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::wifi>>>(); -#ifdef FEATURE_BLUETOOTH - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::bluetooth>>>(); -#endif -#ifdef FEATURE_BLE - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::bluetooth>>>(); -#endif -#ifdef FEATURE_CLOUD - constructMenuItem, SwitchScreenAction>>(); -#endif -#ifdef FEATURE_OTA - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::update>>>(); -#endif - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::time>>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::hardware>>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::hardware>>>(); -#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) - constructMenuItem, ToggleBoolAction, CheckboxIcon, AutoConnectBmsAccessor>>(); -#endif - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::buzzer>>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, FrontLedAccessor>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, BackLedAccessor>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::demos>>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::info>>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + SettingsMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/menus/timersmenu.h b/main/displays/menus/timersmenu.h index 1ecc470..db04c25 100644 --- a/main/displays/menus/timersmenu.h +++ b/main/displays/menus/timersmenu.h @@ -9,11 +9,6 @@ #include "texts.h" #include "accessors/settingsaccessors.h" -// forward declares -namespace { -class BoardcomputerHardwareSettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/timesettingsmenu.h b/main/displays/menus/timesettingsmenu.h index d9eafee..53c6e7e 100644 --- a/main/displays/menus/timesettingsmenu.h +++ b/main/displays/menus/timesettingsmenu.h @@ -18,12 +18,6 @@ #include "accessors/settingsaccessors.h" #include "espstrutils.h" -// forward declares -namespace { -class SettingsMenu; -class TimeSettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/wifisettingsmenu.h b/main/displays/menus/wifisettingsmenu.h index f3904e7..febf58a 100644 --- a/main/displays/menus/wifisettingsmenu.h +++ b/main/displays/menus/wifisettingsmenu.h @@ -7,14 +7,6 @@ #include "icons/back.h" #include "texts.h" -// forward declares -namespace { -class GenericWifiSettingsMenu; -class StationWifiSettingsMenu; -class AccessPointWifiSettingsMenu; -class SettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/metersdisplay.cpp b/main/displays/metersdisplay.cpp index e69de29..2dd31ff 100644 --- a/main/displays/metersdisplay.cpp +++ b/main/displays/metersdisplay.cpp @@ -0,0 +1,70 @@ +#include "metersdisplay.h" + +// 3rdparty lib includes +#include +#include + +// local includes +#include "globals.h" +#include "utils.h" +#include "displays/menus/mainmenu.h" +#include "displays/statusdisplay.h" +#include "displays/bmsdisplay.h" + +using namespace espgui; + +void MetersDisplay::initScreen() +{ + tft.fillScreen(TFT_BLACK); + + m_vuMeter.start(); + + m_dischargingBar.start(); + m_chargingBar.start(); + + m_sumCurrentLabel.start(); + + for (auto &meter : meters) + meter.start(); +} + +void MetersDisplay::redraw() +{ + m_vuMeter.redraw(avgSpeedKmh); + + m_dischargingBar.redraw(sumCurrent<0.f?(-sumCurrent):0.f); + m_chargingBar.redraw(sumCurrent>0.f?sumCurrent:0.f); + + tft.setTextColor(TFT_WHITE, TFT_BLACK); + tft.setTextFont(2); + m_sumCurrentLabel.redraw(fmt::format("{:.02f}A", sumCurrent)); + + meters[0].redraw(controllers.front.getCalibratedVoltage(), 35, 50); + meters[1].redraw(controllers.back.getCalibratedVoltage(), 35, 50); + meters[2].redraw(fixCurrent(controllers.front.feedback.left.dcLink), -10, 10); + meters[3].redraw(fixCurrent(controllers.front.feedback.right.dcLink), -10, 10); + meters[4].redraw(fixCurrent(controllers.back.feedback.left.dcLink), -10, 10); + meters[5].redraw(fixCurrent(controllers.back.feedback.right.dcLink), -10, 10); +} + +void MetersDisplay::confirm() +{ + switchScreen(); +} + +void MetersDisplay::back() +{ + switchScreen(); +} + +void MetersDisplay::rotate(int offset) +{ + if (offset < 0) + switchScreen(); + else if (offset > 0) +#ifdef FEATURE_BMS + switchScreen(); +#else + switchScreen(); +#endif +} diff --git a/main/displays/metersdisplay.h b/main/displays/metersdisplay.h index 92e621a..c9b8df4 100644 --- a/main/displays/metersdisplay.h +++ b/main/displays/metersdisplay.h @@ -1,96 +1,43 @@ #pragma once +// system includes #include -#include +// 3rdparty lib includes +#include +#include +#include +#include +#include +#include +#include -#include "display.h" -#include "actions/switchscreenaction.h" -#include "globals.h" -#include "utils.h" -#include "widgets/label.h" -#include "widgets/reverseprogressbar.h" -#include "widgets/progressbar.h" -#include "widgets/verticalmeter.h" -#include "widgets/vumeter.h" - -namespace { -class MainMenu; -class StatusDisplay; -class BmsDisplay; -} - -namespace { -class MetersDisplay : public Display, public ConfirmActionInterface>, public BackActionInterface> +class MetersDisplay : + public espgui::Display { public: void initScreen() override; void redraw() override; + void confirm() override; + void back() override; void rotate(int offset) override; private: - VuMeter m_vuMeter; + espgui::VuMeter m_vuMeter; - ReverseProgressBar m_dischargingBar{10, 135, 90, 15, 0, 40, TFT_GREEN}; - ProgressBar m_chargingBar{100, 135, 90, 15, 0, 40, TFT_RED}; + espgui::ReverseProgressBar m_dischargingBar{10, 135, 90, 15, 0, 40, TFT_GREEN}; + espgui::ProgressBar m_chargingBar{100, 135, 90, 15, 0, 40, TFT_RED}; - Label m_sumCurrentLabel{195,135}; + espgui::Label m_sumCurrentLabel{195,135}; static constexpr auto x = 40; - std::array meters{{ - VerticalMeter{"U f", "%.1f", 0*x, 160}, - VerticalMeter{"U b", "%.1f", 1*x, 160}, - VerticalMeter{"Ibl", "%.1f", 2*x, 160}, - VerticalMeter{"Ibr", "%.1f", 3*x, 160}, - VerticalMeter{"Ihl", "%.1f", 4*x, 160}, - VerticalMeter{"Ihr", "%.1f", 5*x, 160} + std::array meters{{ + espgui::VerticalMeter{"U f", "%.1f", 0*x, 160}, + espgui::VerticalMeter{"U b", "%.1f", 1*x, 160}, + espgui::VerticalMeter{"Ibl", "%.1f", 2*x, 160}, + espgui::VerticalMeter{"Ibr", "%.1f", 3*x, 160}, + espgui::VerticalMeter{"Ihl", "%.1f", 4*x, 160}, + espgui::VerticalMeter{"Ihr", "%.1f", 5*x, 160} }}; }; - -void MetersDisplay::initScreen() -{ - tft.fillScreen(TFT_BLACK); - - m_vuMeter.start(); - - m_dischargingBar.start(); - m_chargingBar.start(); - - m_sumCurrentLabel.start(); - - for (auto &meter : meters) - meter.start(); -} - -void MetersDisplay::redraw() -{ - m_vuMeter.redraw(avgSpeedKmh); - - m_dischargingBar.redraw(sumCurrent<0.f?(-sumCurrent):0.f); - m_chargingBar.redraw(sumCurrent>0.f?sumCurrent:0.f); - - tft.setTextColor(TFT_WHITE, TFT_BLACK); - tft.setTextFont(2); - m_sumCurrentLabel.redraw(std::to_string(sumCurrent) + 'A'); - - meters[0].redraw(controllers.front.getCalibratedVoltage(settings.battery.applyCalibration), 35, 50); - meters[1].redraw(controllers.back.getCalibratedVoltage(settings.battery.applyCalibration), 35, 50); - meters[2].redraw(fixCurrent(controllers.front.feedback.left.dcLink), -10, 10); - meters[3].redraw(fixCurrent(controllers.front.feedback.right.dcLink), -10, 10); - meters[4].redraw(fixCurrent(controllers.back.feedback.left.dcLink), -10, 10); - meters[5].redraw(fixCurrent(controllers.back.feedback.right.dcLink), -10, 10); -} - -void MetersDisplay::rotate(int offset) -{ - if (offset < 0) - switchScreen(); - else if (offset > 0) -#ifdef FEATURE_BMS - switchScreen(); -#else - switchScreen(); -#endif -} -} diff --git a/main/displays/powersupplydisplay.h b/main/displays/powersupplydisplay.h index ec33b82..be38517 100644 --- a/main/displays/powersupplydisplay.h +++ b/main/displays/powersupplydisplay.h @@ -9,11 +9,6 @@ #include "globals.h" #include "widgets/label.h" -namespace { -class MainMenu; -class MetersDisplay; -class StatusDisplay; -} namespace { #if defined(FEATURE_CAN) && defined(FEATURE_POWERSUPPLY) class PowerSupplyDisplay : public Display, public DummyConfirm, public BackActionInterface> diff --git a/main/displays/statusdisplay.cpp b/main/displays/statusdisplay.cpp index e69de29..d506076 100644 --- a/main/displays/statusdisplay.cpp +++ b/main/displays/statusdisplay.cpp @@ -0,0 +1,261 @@ +#include "statusdisplay.h" + +// 3rdparty lib includes +#include +#include +#include + +// local includes +#include "displays/menus/mainmenu.h" +#ifdef FEATURE_BMS +#include "displays/bmsdisplay.h" +#else +#include "displays/metersdisplay.h" +#endif + +using namespace espgui; + +void StatusDisplay::initScreen() +{ + Base::initScreen(); + + tft.setTextFont(2); + tft.setTextColor(TFT_WHITE); + + tft.drawString("gas", 0, 0); + m_labelRawGas.start(); + m_labelGas.start(); + m_progressBarGas.start(); + tft.drawString("brems", 0, 15); + m_labelRawBrems.start(); + m_labelBrems.start(); + m_progressBarBrems.start(); + + m_batterypercent.start(); + m_watthoursleft.start(); + m_kilometersleft.start(); + + m_frontStatus.start(); + m_backStatus.start(); + + tft.setTextFont(2); + tft.drawString("WiFi:", 0, bottomLines[0]); + m_labelWifiStatus.start(); + tft.drawString("Lim0:", 173, bottomLines[0]); + m_labelLimit0.start(); + tft.drawString("IP:", 0, bottomLines[1]); + m_labelIpAddress.start(); + m_labelSignal.start(); + tft.drawString("Lim1:", 173, bottomLines[1]); + m_labelLimit1.start(); + tft.drawString("Perf:", 0, bottomLines[2]); + m_labelPerformance.start(); + m_labelFreeMem.start(); + tft.drawString("Mode:", 125, bottomLines[2]); + m_labelMode.start(); + tft.drawString("Name:", 0, bottomLines[3]); + m_labelName.start(); + m_labelProfile.start(); + + tft.setTextColor(TFT_WHITE, TFT_BLACK); +} + +void StatusDisplay::redraw() +{ + Base::redraw(); + + tft.setTextFont(2); + m_labelRawGas.redraw(raw_gas ? std::to_string(*raw_gas) : "?"); + m_labelGas.redraw(gas ? fmt::format("{:.2f}", *gas) : "?"); + m_progressBarGas.redraw(gas ? *gas : 0); + m_labelRawBrems.redraw(raw_brems ? std::to_string(*raw_brems) : "?"); + m_labelBrems.redraw(brems ? fmt::format("{:.2f}", *brems) : "?"); + m_progressBarBrems.redraw(brems ? *brems : 0); + + m_batterypercent.redraw(getBatteryPercentageString()); + m_watthoursleft.redraw(getBatteryRemainingWattHoursString()); + m_kilometersleft.redraw(getRemainingRangeString()); + + m_frontStatus.redraw(controllers.front); + m_backStatus.redraw(controllers.back); + + tft.setTextFont(2); + + const auto staStatus = wifi_stack::get_sta_status(); + if (staStatus == wifi_stack::WiFiStaStatus::CONNECTED) + { + if (const auto result = wifi_stack::get_sta_ap_info(); result) + { + m_labelWifiStatus.redraw(std::string_view{reinterpret_cast(result->ssid)}); + tft.setTextColor(result->rssi < -80 ? TFT_ORANGE : TFT_WHITE, TFT_BLACK); + m_labelSignal.redraw(fmt::format("{}dB", result->rssi)); + tft.setTextColor(TFT_WHITE, TFT_BLACK); + } + else + { + ESP_LOGW("BOBBY", "get_sta_ap_info() failed with %.*s", result.error().size(), result.error().data()); + goto showStaStatus; + } + } + else + { +showStaStatus: + m_labelWifiStatus.redraw(wifi_stack::toString(staStatus)); + m_labelSignal.clear(); + } + + m_labelLimit0.redraw(fmt::format("{}A", controllers.front.command.left.iMotMax)); + + if (staStatus == wifi_stack::WiFiStaStatus::CONNECTED) + { + if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA); result) + m_labelIpAddress.redraw(wifi_stack::toString(result->ip)); + else + { + ESP_LOGW("BOBBY", "get_ip_info() failed with %.*s", result.error().size(), result.error().data()); + goto clearIp; + } + } + else + { +clearIp: + m_labelIpAddress.clear(); + } + + m_labelLimit1.redraw(fmt::format("{}A", controllers.front.command.left.iDcMax)); + + tft.setTextColor(performance.last < 35 ? TFT_ORANGE : TFT_WHITE, TFT_BLACK); + m_labelPerformance.redraw(std::to_string(performance.last)); + tft.setTextColor(TFT_WHITE, TFT_BLACK); + + { + const auto freeMem = heap_caps_get_free_size(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + tft.setTextColor(freeMem < 70000 ? TFT_ORANGE : TFT_WHITE, TFT_BLACK); + m_labelFreeMem.redraw(fmt::format("{}K", freeMem/1000)); + tft.setTextColor(TFT_WHITE, TFT_BLACK); + } + + m_labelMode.redraw(currentMode->displayName()); + m_labelName.redraw(deviceName); + const auto profile = settingsPersister.currentlyOpenProfileIndex(); + m_labelProfile.redraw(profile ? std::to_string(*profile) : "-"); +} + +void StatusDisplay::confirm() +{ + switchScreen(); +} + +void StatusDisplay::rotate(int offset) +{ + Base::rotate(offset); + + if (offset < 0) +#ifdef FEATURE_BMS + switchScreen(); +#else + switchScreen(); +#endif + else if (offset > 0) + switchScreen(); +} + +StatusDisplay::BoardStatus::BoardStatus(int y) : + m_y{y}, + m_labelLeftPwm{65, y}, // 80, 22 + m_labelRightPwm{155, y}, // 80, 22 + m_labelVoltage{30, y+25}, // 85, 22 + m_labelTemperature{150, y+25}, // 85, 22 + m_leftMotor{y+50}, + m_rightMotor{y+75} +{} + +void StatusDisplay::BoardStatus::start() +{ + tft.setTextFont(4); + tft.drawString("pwm:", 0, m_y); + m_labelLeftPwm.start(); + m_labelRightPwm.start(); + m_initialRedraw = true; +} + +void StatusDisplay::BoardStatus::redraw(const Controller &controller) +{ + tft.setTextFont(4); + + m_labelLeftPwm.redraw(std::to_string(controller.command.left.pwm)); + m_labelRightPwm.redraw(std::to_string(controller.command.right.pwm)); + + if (controller.feedbackValid != m_lastFeedbackValid || m_initialRedraw) + { + tft.fillRect(0, m_y+25, tft.width(), 75, TFT_BLACK); + + if (controller.feedbackValid) + { + tft.setTextColor(TFT_WHITE); + + tft.drawString("U=", 0, m_y+25, 4); + m_labelVoltage.start(); + tft.drawString("T=", 120, m_y+25, 4); + m_labelTemperature.start(); + tft.drawString("l:", 0, m_y+50, 4); + m_leftMotor.start(); + tft.drawString("r:", 0, m_y+75, 4); + m_rightMotor.start(); + + tft.setTextColor(TFT_WHITE, TFT_BLACK); + } + else + { + tft.setTextColor(TFT_RED); + tft.drawString("No data!", 60, m_y+50, 4); + tft.setTextColor(TFT_WHITE, TFT_BLACK); + + tft.setSwapBytes(true); + tft.pushImage(10, m_y+40, bobbyicons::alert.WIDTH, bobbyicons::alert.HEIGHT, bobbyicons::alert.buffer); + tft.setSwapBytes(false); + } + + m_lastFeedbackValid = controller.feedbackValid; + m_initialRedraw = false; + } + + if (controller.feedbackValid) + { + m_labelVoltage.redraw(fmt::format("{:.2f}V", controller.getCalibratedVoltage())); + m_labelTemperature.redraw(fmt::format("{:.2f}C", fixBoardTemp(controller.feedback.boardTemp))); + m_leftMotor.redraw(controller.feedback.left); + m_rightMotor.redraw(controller.feedback.right); + } +} + +StatusDisplay::BoardStatus::MotorStatus::MotorStatus(int y) : + m_labelError{18, y}, // 18, 22, + m_labelCurrent{40, y}, // 85, 22 + m_labelSpeed{135, y}, // 75, 22 + m_labelHallSensors{210, y} // 30, 15 +{} + +void StatusDisplay::BoardStatus::MotorStatus::start() +{ + m_labelError.start(); + m_labelCurrent.start(); + m_labelSpeed.start(); + m_labelHallSensors.start(); +} + +void StatusDisplay::BoardStatus::MotorStatus::redraw(const bobbycar::protocol::serial::MotorFeedback &motor) +{ + tft.setTextFont(4); + tft.setTextColor(motor.error?TFT_RED:TFT_GREEN, TFT_BLACK); + m_labelError.redraw(std::to_string(motor.error)); + tft.setTextColor(TFT_WHITE, TFT_BLACK); + + m_labelCurrent.redraw(fmt::format("{:.2f}A", fixCurrent(motor.dcLink))); + m_labelSpeed.redraw(fmt::format("{:.2f}", convertToKmh(motor.speed))); + + tft.setTextFont(2); + m_labelHallSensors.redraw(hallString(motor)); + + tft.setTextColor(TFT_WHITE, TFT_BLACK); +} diff --git a/main/displays/statusdisplay.h b/main/displays/statusdisplay.h index 3560ed5..e18e3b6 100644 --- a/main/displays/statusdisplay.h +++ b/main/displays/statusdisplay.h @@ -4,51 +4,36 @@ #include // 3rdparty lib includes -#include -#include +#include +#include +#include +#include // local includes -#include "display.h" -#include "actions/switchscreenaction.h" #include "modeinterface.h" #include "globals.h" #include "utils.h" -#include "widgets/label.h" -#include "widgets/progressbar.h" #include "icons/alert.h" #include "battery.h" -// forward declares -namespace { -class MainMenu; -class BmsDisplay; -class MetersDisplay; - -static uint16_t counter = 24; -} - -namespace { -class StatusDisplay : public Display, public ConfirmActionInterface>, public DummyBack +class StatusDisplay : + public espgui::Display, + public espgui::DummyBack { + using Base = espgui::Display; + public: void initScreen() override; void redraw() override; + void confirm() override; void rotate(int offset) override; private: class BoardStatus { public: - BoardStatus(int y) : - m_y{y}, - m_labelLeftPwm{65, y}, // 80, 22 - m_labelRightPwm{155, y}, // 80, 22 - m_labelVoltage{30, y+25}, // 85, 22 - m_labelTemperature{150, y+25}, // 85, 22 - m_leftMotor{y+50}, - m_rightMotor{y+75} - {} + BoardStatus(int y); void start(); void redraw(const Controller &controller); @@ -57,21 +42,16 @@ private: class MotorStatus { public: - MotorStatus(int y) : - m_labelError{18, y}, // 18, 22, - m_labelCurrent{40, y}, // 85, 22 - m_labelSpeed{135, y}, // 75, 22 - m_labelHallSensors{210, y} // 30, 15 - {} + MotorStatus(int y); void start(); void redraw(const bobbycar::protocol::serial::MotorFeedback &motor); private: - Label m_labelError; - Label m_labelCurrent; - Label m_labelSpeed; - Label m_labelHallSensors; + espgui::Label m_labelError; + espgui::Label m_labelCurrent; + espgui::Label m_labelSpeed; + espgui::Label m_labelHallSensors; }; const int m_y; @@ -79,268 +59,41 @@ private: bool m_initialRedraw; bool m_lastFeedbackValid; - Label m_labelLeftPwm; - Label m_labelRightPwm; + espgui::Label m_labelLeftPwm; + espgui::Label m_labelRightPwm; - Label m_labelVoltage; - Label m_labelTemperature; + espgui::Label m_labelVoltage; + espgui::Label m_labelTemperature; MotorStatus m_leftMotor; MotorStatus m_rightMotor; }; - Label m_labelRawGas{45, 0}; // 40, 15 - Label m_labelGas{90, 0}; // 60, 15 - ProgressBar m_progressBarGas{150, 0, 90, 15, 0, 1000}; + espgui::Label m_labelRawGas{45, 0}; // 40, 15 + espgui::Label m_labelGas{90, 0}; // 60, 15 + espgui::ProgressBar m_progressBarGas{150, 0, 90, 15, 0, 1000}; - Label m_labelRawBrems{45, 15}; // 40, 15 - Label m_labelBrems{90, 15}; // 60, 15 - ProgressBar m_progressBarBrems{150, 15, 90, 15, 0, 1000}; + espgui::Label m_labelRawBrems{45, 15}; // 40, 15 + espgui::Label m_labelBrems{90, 15}; // 60, 15 + espgui::ProgressBar m_progressBarBrems{150, 15, 90, 15, 0, 1000}; - Label m_batterypercent{0, 30}; - Label m_watthoursleft{110, 30}; - Label m_kilometersleft{175, 30}; + espgui::Label m_batterypercent{0, 30}; + espgui::Label m_watthoursleft{110, 30}; + espgui::Label m_kilometersleft{175, 30}; BoardStatus m_frontStatus{45}; BoardStatus m_backStatus{145}; - Label m_labelWifiStatus{35, bottomLines[0]}; // 120, 15 - Label m_labelLimit0{205, bottomLines[0]}; // 35, 15 - Label m_labelIpAddress{25, bottomLines[1]}; // 130, 15 - Label m_labelSignal{125, bottomLines[1]}; // 130, 15 - Label m_labelLimit1{205, bottomLines[1]}; // 35, 15 - Label m_labelPerformance{40, bottomLines[2]}; // 40, 15 - Label m_labelFreeMem{70, bottomLines[2]}; // 40, 15 - Label m_labelMode{165, bottomLines[2]}; // 75, 15 - Label m_labelName{40, bottomLines[3]}; // 40, 15 - Label m_labelProfile{205, bottomLines[3]}; // 35, 15 + espgui::Label m_labelWifiStatus{35, bottomLines[0]}; // 120, 15 + espgui::Label m_labelLimit0{205, bottomLines[0]}; // 35, 15 + espgui::Label m_labelIpAddress{25, bottomLines[1]}; // 130, 15 + espgui::Label m_labelSignal{125, bottomLines[1]}; // 130, 15 + espgui::Label m_labelLimit1{205, bottomLines[1]}; // 35, 15 + espgui::Label m_labelPerformance{40, bottomLines[2]}; // 40, 15 + espgui::Label m_labelFreeMem{70, bottomLines[2]}; // 40, 15 + espgui::Label m_labelMode{165, bottomLines[2]}; // 75, 15 + espgui::Label m_labelName{40, bottomLines[3]}; // 40, 15 + espgui::Label m_labelProfile{205, bottomLines[3]}; // 35, 15 static const constexpr int bottomLines[4] { 251, 266, 281, 296 }; }; - -void StatusDisplay::initScreen() -{ - tft.fillScreen(TFT_BLACK); - tft.setTextFont(2); - tft.setTextColor(TFT_WHITE); - - tft.drawString("gas", 0, 0); - m_labelRawGas.start(); - m_labelGas.start(); - m_progressBarGas.start(); - tft.drawString("brems", 0, 15); - m_labelRawBrems.start(); - m_labelBrems.start(); - m_progressBarBrems.start(); - - m_batterypercent.start(); - m_watthoursleft.start(); - m_kilometersleft.start(); - - m_frontStatus.start(); - m_backStatus.start(); - - tft.setTextFont(2); - tft.drawString("WiFi:", 0, bottomLines[0]); - m_labelWifiStatus.start(); - tft.drawString("Lim0:", 173, bottomLines[0]); - m_labelLimit0.start(); - tft.drawString("IP:", 0, bottomLines[1]); - m_labelIpAddress.start(); - m_labelSignal.start(); - tft.drawString("Lim1:", 173, bottomLines[1]); - m_labelLimit1.start(); - tft.drawString("Perf:", 0, bottomLines[2]); - m_labelPerformance.start(); - m_labelFreeMem.start(); - tft.drawString("Mode:", 125, bottomLines[2]); - m_labelMode.start(); - tft.drawString("Name:", 0, bottomLines[3]); - m_labelName.start(); - m_labelProfile.start(); - - tft.setTextColor(TFT_WHITE, TFT_BLACK); - counter = 0; -} - -void StatusDisplay::redraw() -{ - tft.setTextFont(2); - m_labelRawGas.redraw(raw_gas ? std::to_string(*raw_gas) : "?"); - m_labelGas.redraw(gas ? fmt::format("{:.2f}", *gas) : "?"); - m_progressBarGas.redraw(gas ? *gas : 0); - m_labelRawBrems.redraw(raw_brems ? std::to_string(*raw_brems) : "?"); - m_labelBrems.redraw(brems ? fmt::format("{:.2f}", *brems) : "?"); - m_progressBarBrems.redraw(brems ? *brems : 0); - - if (counter < 1) - { - counter = 25; - m_batterypercent.redraw(getBatteryPercentageString()); - m_watthoursleft.redraw(getBatteryRemainingWattHoursString()); - m_kilometersleft.redraw(getRemainingRangeString()); - } - else - counter--; - - m_frontStatus.redraw(controllers.front); - m_backStatus.redraw(controllers.back); - - tft.setTextFont(2); - - const auto staStatus = wifi_stack::get_sta_status(); - if (staStatus == wifi_stack::WiFiStaStatus::CONNECTED) - { - if (const auto result = wifi_stack::get_sta_ap_info(); result) - { - m_labelWifiStatus.redraw(std::string_view{reinterpret_cast(result->ssid)}); - tft.setTextColor(result->rssi < -80 ? TFT_ORANGE : TFT_WHITE, TFT_BLACK); - m_labelSignal.redraw(fmt::format("{}dB", result->rssi)); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - } - else - { - ESP_LOGW("BOBBY", "get_sta_ap_info() failed with %.*s", result.error().size(), result.error().data()); - goto showStaStatus; - } - } - else - { -showStaStatus: - m_labelWifiStatus.redraw(wifi_stack::toString(staStatus)); - m_labelSignal.clear(); - } - - m_labelLimit0.redraw(fmt::format("{}A", controllers.front.command.left.iMotMax)); - - if (staStatus == wifi_stack::WiFiStaStatus::CONNECTED) - { - if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA); result) - m_labelIpAddress.redraw(wifi_stack::toString(result->ip)); - else - { - ESP_LOGW("BOBBY", "get_ip_info() failed with %.*s", result.error().size(), result.error().data()); - goto clearIp; - } - } - else - { -clearIp: - m_labelIpAddress.clear(); - } - - m_labelLimit1.redraw(fmt::format("{}A", controllers.front.command.left.iDcMax)); - - tft.setTextColor(performance.last < 35 ? TFT_ORANGE : TFT_WHITE, TFT_BLACK); - m_labelPerformance.redraw(std::to_string(performance.last)); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - - { - const auto freeMem = heap_caps_get_free_size(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); - tft.setTextColor(freeMem < 70000 ? TFT_ORANGE : TFT_WHITE, TFT_BLACK); - m_labelFreeMem.redraw(fmt::format("{}K", freeMem/1000)); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - } - - m_labelMode.redraw(currentMode->displayName()); - m_labelName.redraw(deviceName); - const auto profile = settingsPersister.currentlyOpenProfileIndex(); - m_labelProfile.redraw(profile ? std::to_string(*profile) : "-"); -} - -void StatusDisplay::rotate(int offset) -{ - counter = 0; - if (offset < 0) -#ifdef FEATURE_BMS - switchScreen(); -#else - switchScreen(); -#endif - else if (offset > 0) - switchScreen(); -} - -void StatusDisplay::BoardStatus::start() -{ - tft.setTextFont(4); - tft.drawString("pwm:", 0, m_y); - m_labelLeftPwm.start(); - m_labelRightPwm.start(); - m_initialRedraw = true; -} - -void StatusDisplay::BoardStatus::redraw(const Controller &controller) -{ - tft.setTextFont(4); - - m_labelLeftPwm.redraw(std::to_string(controller.command.left.pwm)); - m_labelRightPwm.redraw(std::to_string(controller.command.right.pwm)); - - if (controller.feedbackValid != m_lastFeedbackValid || m_initialRedraw) - { - tft.fillRect(0, m_y+25, tft.width(), 75, TFT_BLACK); - - if (controller.feedbackValid) - { - tft.setTextColor(TFT_WHITE); - - tft.drawString("U=", 0, m_y+25, 4); - m_labelVoltage.start(); - tft.drawString("T=", 120, m_y+25, 4); - m_labelTemperature.start(); - tft.drawString("l:", 0, m_y+50, 4); - m_leftMotor.start(); - tft.drawString("r:", 0, m_y+75, 4); - m_rightMotor.start(); - - tft.setTextColor(TFT_WHITE, TFT_BLACK); - } - else - { - tft.setTextColor(TFT_RED); - tft.drawString("No data!", 60, m_y+50, 4); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - - tft.setSwapBytes(true); - tft.pushImage(10, m_y+40, bobbyicons::alert.WIDTH, bobbyicons::alert.HEIGHT, bobbyicons::alert.buffer); - tft.setSwapBytes(false); - } - - m_lastFeedbackValid = controller.feedbackValid; - m_initialRedraw = false; - } - - if (controller.feedbackValid) - { - m_labelVoltage.redraw(fmt::format("{:.2f}V", controller.getCalibratedVoltage(settings.battery.applyCalibration))); - m_labelTemperature.redraw(fmt::format("{:.2f}C", fixBoardTemp(controller.feedback.boardTemp))); - m_leftMotor.redraw(controller.feedback.left); - m_rightMotor.redraw(controller.feedback.right); - } -} - -void StatusDisplay::BoardStatus::MotorStatus::start() -{ - m_labelError.start(); - m_labelCurrent.start(); - m_labelSpeed.start(); - m_labelHallSensors.start(); -} - -void StatusDisplay::BoardStatus::MotorStatus::redraw(const bobbycar::protocol::serial::MotorFeedback &motor) -{ - tft.setTextFont(4); - tft.setTextColor(motor.error?TFT_RED:TFT_GREEN, TFT_BLACK); - m_labelError.redraw(std::to_string(motor.error)); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - - m_labelCurrent.redraw(fmt::format("{:.2f}A", fixCurrent(motor.dcLink))); - m_labelSpeed.redraw(fmt::format("{:.2f}", convertToKmh(motor.speed))); - - tft.setTextFont(2); - m_labelHallSensors.redraw(hallString(motor)); - - tft.setTextColor(TFT_WHITE, TFT_BLACK); -} -} diff --git a/main/main.cpp b/main/main.cpp index e1a5400..2199d4f 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -20,98 +20,6 @@ using namespace std::chrono_literals; #include "bobbycar-serial.h" #include "macros_bobbycar.h" #include "globals.h" -#include "modes/defaultmode.h" -#include "modes/tempomatmode.h" -#include "displays/menus/aboutmenu.h" -#include "displays/menus/accesspointwifisettingsmenu.h" -#ifdef FEATURE_BLUETOOTH -#include "displays/menus/bluetoothsettingsmenu.h" -#endif -#ifdef FEATURE_BLE -#include "displays/menus/blesettingsmenu.h" -#endif -#ifdef FEATURE_CLOUD -#include "displays/menus/cloudsettingsmenu.h" -#endif -#ifdef FEATURE_BMS -#include "displays/menus/bmsmenu.h" -#endif -#include "displays/menus/buzzermenu.h" -#include "displays/menus/commanddebugmenu.h" -#include "displays/menus/crashmenu.h" -#include "displays/menus/debugmenu.h" -#include "displays/menus/defaultmodesettingsmenu.h" -#include "displays/menus/demosmenu.h" -#include "displays/menus/dynamicdebugmenu.h" -#include "displays/menus/enablemenu.h" -#include "displays/menus/feedbackdebugmenu.h" -#ifdef FEATURE_GAMETRAK -#include "displays/menus/gametrakmodesettingsmenu.h" -#endif -#include "displays/menus/genericwifisettingsmenu.h" -#include "displays/menus/graphsmenu.h" -#include "displays/menus/controllerhardwaresettingsmenu.h" -#include "displays/menus/invertmenu.h" -#include "displays/menus/larsmmodesettingsmenu.h" -#ifdef FEATURE_LEDSTRIP -#include "displays/menus/ledstripmenu.h" -#endif -#include "displays/menus/limitssettingsmenu.h" -#include "displays/menus/lockscreensettingsmenu.h" -#include "displays/menus/mainmenu.h" -#include "displays/menus/tempomatmodesettingsmenu.h" -#include "displays/menus/modessettingsmenu.h" -#ifdef FEATURE_LEDSTRIP -#include "displays/ledstripcolorsdisplay.h" -#endif -#ifdef FEATURE_MOSFETS -#include "displays/menus/mosfetsmenu.h" -#endif -#include "displays/menus/motorfeedbackdebugmenu.h" -#include "displays/menus/motorstatedebugmenu.h" -#include "displays/menus/profilesmenu.h" -#include "displays/menus/presetsmenu.h" -#include "displays/menus/boardcomputerhardwaresettingsmenu.h" -#include "displays/menus/selectmodemenu.h" -#include "displays/menus/settingsmenu.h" -#include "displays/menus/stationwifisettingsmenu.h" -#include "displays/menus/timersmenu.h" -#include "displays/menus/timesettingsmenu.h" -#include "displays/menus/wifiscanmenu.h" -#include "displays/menus/wifisettingsmenu.h" -#ifdef FEATURE_BMS -#include "displays/bmsdisplay.h" -#endif -#include "displays/calibratedisplay.h" -#ifdef FEATURE_DPAD_5WIRESW -#include "displays/dpad5wiredebugdisplay.h" -#endif -#ifdef FEATURE_DPAD_5WIRESW_2OUT -#include "displays/dpad5wire2outdebugdisplay.h" -#endif -#ifdef FEATURE_DPAD_6WIRESW -#include "displays/dpad6wiredebugdisplay.h" -#endif -#include "displays/gameoflifedisplay.h" -#ifdef FEATURE_GARAGE -#include "displays/garagedisplay.h" -#endif -#ifdef FEATURE_LOCKSCREEN -#include "displays/gametrakcalibratedisplay.h" -#endif -#include "displays/lockscreen.h" -#include "displays/metersdisplay.h" -#include "displays/pingpongdisplay.h" -#include "displays/poweroffdisplay.h" -#include "displays/powersupplydisplay.h" -#include "displays/spirodisplay.h" -#include "displays/starfielddisplay.h" -#include "displays/statusdisplay.h" -#ifdef FEATURE_OTA -#include "displays/updatedisplay.h" -#include "displays/menus/otamenu.h" -#include "displays/menus/selectotabuildmenu.h" -#endif #include "screens.h" #include "dpad.h" #ifdef FEATURE_DPAD_3WIRESW @@ -160,6 +68,9 @@ using namespace std::chrono_literals; #ifdef FEATURE_LEDSTRIP #include "ledstrip.h" #endif +#include "modes/defaultmode.h" +#include "displays/statusdisplay.h" +#include "displays/calibratedisplay.h" namespace { std::optional lastWifiUpdate; @@ -362,9 +273,9 @@ extern "C" void app_main() #else if (!gas || !brems || *gas > 200.f || *brems > 200.f) - switchScreen(true); + espgui::switchScreen(true); else - switchScreen(); + espgui::switchScreen(); #endif while (true) diff --git a/main/screens.cpp b/main/screens.cpp index e69de29..19e6cec 100644 --- a/main/screens.cpp +++ b/main/screens.cpp @@ -0,0 +1,93 @@ +#include "screens.h" + +// 3rdparty lib includes +#include + +// local includes +#include "globals.h" +#include "utils.h" +#include "icons/logo.h" +#include "buttons.h" + +using namespace espgui; + +Label bootLabel{32, 250}; + +void initScreen() +{ + tft.init(); + tft.fillScreen(TFT_WHITE); + tft.setTextColor(TFT_BLACK, TFT_WHITE); + tft.setTextFont(4); + tft.pushImage(0, 40, bobbyicons::logo.WIDTH, bobbyicons::logo.HEIGHT, bobbyicons::logo.buffer); + tft.drawString("Bobbycar-OS", 32, 200); + tft.drawString("booting...", 32, 225); + bootLabel.start(); +} + +void updateDisplay() +{ + if (rotated) + { + const auto rotatedCopy = rotated; + rotated = 0; + + if (currentDisplay) + currentDisplay->rotate(rotatedCopy); + } + + if (requestFullRedraw) + { + requestFullRedraw = false; + + tft.init(); + + if (currentDisplay) + currentDisplay->initScreen(); + } + + if (confirmButtonPressed) + { + confirmButtonPressed = false; + + if (currentDisplay) + currentDisplay->confirm(); + } + + if (confirmButtonLongPressed) + { + confirmButtonLongPressed = false; + //Serial.println("todo: implement long press for confirm"); + } + + if (backButtonPressed) + { + backButtonPressed = false; + + if (currentDisplay) + currentDisplay->back(); + } + + if (backButtonLongPressed) + { + backButtonLongPressed = false; + //Serial.println("todo: implement long press for back"); + } + + if (currentDisplay) + currentDisplay->update(); + + if (changeScreenCallback) + { + changeScreenCallback(); + changeScreenCallback = {}; + } +} + +void redrawDisplay() +{ + if (currentDisplay) + { + currentDisplay->redraw(); + } +} diff --git a/main/screens.h b/main/screens.h index e80c462..43e8b25 100644 --- a/main/screens.h +++ b/main/screens.h @@ -3,94 +3,12 @@ // system includes #include -// local includes -#include "globals.h" -#include "utils.h" -#include "widgets/label.h" -#include "icons/logo.h" -#include "screenmanager.h" +// 3rdparty lib includes +#include +#include -using namespace espgui; +extern espgui::Label bootLabel; -namespace { -Label bootLabel{32, 250}; - -void initScreen() -{ - tft.init(); - tft.fillScreen(TFT_WHITE); - tft.setTextColor(TFT_BLACK, TFT_WHITE); - tft.setTextFont(4); - tft.pushImage(0, 40, bobbyicons::logo.WIDTH, bobbyicons::logo.HEIGHT, bobbyicons::logo.buffer); - tft.drawString("Bobbycar-OS", 32, 200); - tft.drawString("booting...", 32, 225); - bootLabel.start(); -} - -void updateDisplay() -{ - if (rotated) - { - const auto rotatedCopy = rotated; - rotated = 0; - - if (currentDisplay) - currentDisplay->rotate(rotatedCopy); - } - - if (requestFullRedraw) - { - requestFullRedraw = false; - - tft.init(); - - if (currentDisplay) - currentDisplay->initScreen(); - } - - if (confirmButtonPressed) - { - confirmButtonPressed = false; - - if (currentDisplay) - currentDisplay->confirm(); - } - - if (confirmButtonLongPressed) - { - confirmButtonLongPressed = false; - //Serial.println("todo: implement long press for confirm"); - } - - if (backButtonPressed) - { - backButtonPressed = false; - - if (currentDisplay) - currentDisplay->back(); - } - - if (backButtonLongPressed) - { - backButtonLongPressed = false; - //Serial.println("todo: implement long press for back"); - } - - if (currentDisplay) - currentDisplay->update(); - - if (changeScreenCallback) - { - changeScreenCallback(); - changeScreenCallback = {}; - } -} - -void redrawDisplay() -{ - if (currentDisplay) - { - currentDisplay->redraw(); - } -} -} +void initScreen(); +void updateDisplay(); +void redrawDisplay(); diff --git a/main/serialhandler.cpp b/main/serialhandler.cpp index e69de29..7b499d1 100644 --- a/main/serialhandler.cpp +++ b/main/serialhandler.cpp @@ -0,0 +1,121 @@ +#include "serialhandler.h" + +// Arduino includes +#include + +// 3rdparty lib includes +#include + +// local includes +#include "globals.h" +#include "utils.h" +#include "screens.h" +#include "buttons.h" + +using namespace espgui; + +//wl_status_t last_status; +//IPAddress last_ip; + +void handleSerial() +{ + //const auto status = WiFi.status(); + //if (last_status != status) + //{ + //Serial.print("Status changed to: "); + //Serial.println(to_string(status).c_str()); + //last_status = status; + //} + + //const auto ip = WiFi.localIP(); + //if (last_ip != ip) + //{ + //Serial.print("IP changed to: "); + //Serial.println(to_string(ip).c_str()); + //last_ip = ip; + //} + + while(Serial.available()) + { + const auto c = Serial.read(); + + switch (c) + { + case 'i': + case 'I': + tft.init(); + break; + case 'p': + case 'P': + { + const auto firstPower = controllers.front.command.poweroff; + for (Controller &controller : controllers) + controller.command.poweroff = !firstPower; + break; + } + case 'l': + case 'L': + { + const auto firstLed = controllers.front.command.led; + for (Controller &controller : controllers) + controller.command.led = !firstLed; + break; + } + case 'r': + case 'R': + loadSettings(); + break; + case 's': + case 'S': + saveSettings(); + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + for (Controller &controller : controllers) + controller.command.buzzer.freq = c-'0'; + break; + case 'A': + InputDispatcher::rotate(-1); + break; + case 'B': + InputDispatcher::rotate(1); + break; + case 'C': + InputDispatcher::confirmButton(true); + InputDispatcher::confirmButton(false); + break; + case 'D': + InputDispatcher::backButton(true); + InputDispatcher::backButton(false); + break; + case 'z': + case 'Z': +#ifndef LEDSTRIP_WRONG_DIRECTION + InputDispatcher::blinkLeftButton(true); + InputDispatcher::blinkLeftButton(false); +#else + InputDispatcher::blinkRightButton(true); + InputDispatcher::blinkRightButton(false); +#endif + break; + case 'u': + case 'U': +#ifndef LEDSTRIP_WRONG_DIRECTION + InputDispatcher::blinkRightButton(true); + InputDispatcher::blinkRightButton(false); +#else + InputDispatcher::blinkLeftButton(true); + InputDispatcher::blinkLeftButton(false); +#endif + break; + } + } +} diff --git a/main/serialhandler.h b/main/serialhandler.h index 266eb4a..87e8aff 100644 --- a/main/serialhandler.h +++ b/main/serialhandler.h @@ -1,115 +1,6 @@ #pragma once -#include +//extern wl_status_t last_status; +//extern IPAddress last_ip; -#include "globals.h" -#include "utils.h" -#include "screens.h" - -namespace { -//wl_status_t last_status; -//IPAddress last_ip; - -void handleSerial() -{ - //const auto status = WiFi.status(); - //if (last_status != status) - //{ - //Serial.print("Status changed to: "); - //Serial.println(to_string(status).c_str()); - //last_status = status; - //} - - //const auto ip = WiFi.localIP(); - //if (last_ip != ip) - //{ - //Serial.print("IP changed to: "); - //Serial.println(to_string(ip).c_str()); - //last_ip = ip; - //} - - while(Serial.available()) - { - const auto c = Serial.read(); - - switch (c) - { - case 'i': - case 'I': - tft.init(); - break; - case 'p': - case 'P': - { - const auto firstPower = controllers.front.command.poweroff; - for (Controller &controller : controllers) - controller.command.poweroff = !firstPower; - break; - } - case 'l': - case 'L': - { - const auto firstLed = controllers.front.command.led; - for (Controller &controller : controllers) - controller.command.led = !firstLed; - break; - } - case 'r': - case 'R': - loadSettings(); - break; - case 's': - case 'S': - saveSettings(); - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - for (Controller &controller : controllers) - controller.command.buzzer.freq = c-'0'; - break; - case 'A': - InputDispatcher::rotate(-1); - break; - case 'B': - InputDispatcher::rotate(1); - break; - case 'C': - InputDispatcher::confirmButton(true); - InputDispatcher::confirmButton(false); - break; - case 'D': - InputDispatcher::backButton(true); - InputDispatcher::backButton(false); - break; - case 'z': - case 'Z': -#ifndef LEDSTRIP_WRONG_DIRECTION - InputDispatcher::blinkLeftButton(true); - InputDispatcher::blinkLeftButton(false); -#else - InputDispatcher::blinkRightButton(true); - InputDispatcher::blinkRightButton(false); -#endif - break; - case 'u': - case 'U': -#ifndef LEDSTRIP_WRONG_DIRECTION - InputDispatcher::blinkRightButton(true); - InputDispatcher::blinkRightButton(false); -#else - InputDispatcher::blinkLeftButton(true); - InputDispatcher::blinkLeftButton(false); -#endif - break; - } - } -} -} +void handleSerial(); diff --git a/main/statistics.h b/main/statistics.h index d03d891..6090e21 100644 --- a/main/statistics.h +++ b/main/statistics.h @@ -30,13 +30,13 @@ void pushStats() statistics::sumCurrent.push_back(sumCurrent); if (controllers.front.feedbackValid) { - statistics::frontVoltage.push_back(controllers.front.getCalibratedVoltage(settings.battery.applyCalibration)); + statistics::frontVoltage.push_back(controllers.front.getCalibratedVoltage()); statistics::frontLeftCurrent.push_back(fixCurrent(controllers.front.feedback.left.dcLink)); statistics::frontRightCurrent.push_back(fixCurrent(controllers.front.feedback.right.dcLink)); } if (controllers.back.feedbackValid) { - statistics::backVoltage.push_back(controllers.back.getCalibratedVoltage(settings.battery.applyCalibration)); + statistics::backVoltage.push_back(controllers.back.getCalibratedVoltage()); statistics::backLeftCurrent.push_back(fixCurrent(controllers.back.feedback.left.dcLink)); statistics::backRightCurrent.push_back(fixCurrent(controllers.back.feedback.right.dcLink)); } diff --git a/main/texts.h b/main/texts.h index 7caa47a..7398618 100644 --- a/main/texts.h +++ b/main/texts.h @@ -1,6 +1,5 @@ #pragma once -namespace { //AboutMenu constexpr char TEXT_ABOUT[] = "About"; constexpr char TEXT_BACK[] = "Back"; @@ -498,4 +497,3 @@ constexpr char TEXT_LEDSTRIPCOLORMENU[] = "Customize Ledstrip"; #ifdef FEATURE_CAN constexpr char TEXT_POWERSUPPLY[] = "Powersupply"; #endif -} diff --git a/main/webserver_displaycontrol.h b/main/webserver_displaycontrol.h index ef5ad7e..ed4b153 100644 --- a/main/webserver_displaycontrol.h +++ b/main/webserver_displaycontrol.h @@ -17,6 +17,7 @@ #include #include #include +#include // local includes #include "buttons.h" @@ -91,20 +92,20 @@ esp_err_t webserver_root_handler(httpd_req_t *req) "Profile3 "; } - if (auto constCurrentDisplay = static_cast(currentDisplay.get())) + if (auto currentDisplay = static_cast(espgui::currentDisplay.get())) { - if (const auto *textInterface = constCurrentDisplay->asTextInterface()) + if (const auto *textInterface = currentDisplay->asTextInterface()) { HtmlTag h2Tag{"h2", body}; body += esphttpdutils::htmlentities(textInterface->text()); } - if (const auto *menuDisplay = constCurrentDisplay->asMenuDisplay()) + if (const auto *menuDisplay = currentDisplay->asMenuDisplay()) { HtmlTag ulTag{"ul", body}; int i{0}; - menuDisplay->runForEveryMenuItem([&,selectedIndex=menuDisplay->selectedIndex()](const MenuItem &menuItem){ + menuDisplay->runForEveryMenuItem([&,selectedIndex=menuDisplay->selectedIndex()](const espgui::MenuItem &menuItem){ HtmlTag liTag = i == selectedIndex ? HtmlTag{"li", "style=\"border: 1px solid black;\"", body} : HtmlTag{"li", body}; @@ -113,7 +114,7 @@ esp_err_t webserver_root_handler(httpd_req_t *req) i++; }); } - else if (const auto *changeValueDisplay = constCurrentDisplay->asChangeValueDisplayInterface()) + else if (const auto *changeValueDisplay = currentDisplay->asChangeValueDisplayInterface()) { HtmlTag formTag{"form", "action=\"/setValue\" method=\"GET\"", body}; body += fmt::format("", changeValueDisplay->shownValue()); @@ -308,17 +309,17 @@ esp_err_t webserver_triggerItem_handler(httpd_req_t *req) } } - if (!currentDisplay) + if (!espgui::currentDisplay) { - constexpr const std::string_view msg = "currentDisplay is null"; + constexpr const std::string_view msg = "espgui::currentDisplay is null"; ESP_LOGW(TAG, "%.*s", msg.size(), msg.data()); CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } - auto *menuDisplay = currentDisplay->asMenuDisplay(); + auto *menuDisplay = espgui::currentDisplay->asMenuDisplay(); if (!menuDisplay) { - constexpr const std::string_view msg = "currentDisplay is not a menu display"; + constexpr const std::string_view msg = "espgui::currentDisplay is not a menu display"; ESP_LOGW(TAG, "%.*s", msg.size(), msg.data()); CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } @@ -394,17 +395,17 @@ esp_err_t webserver_setValue_handler(httpd_req_t *req) } } - if (!currentDisplay) + if (!espgui::currentDisplay) { - constexpr const std::string_view msg = "currentDisplay is null"; + constexpr const std::string_view msg = "espgui::currentDisplay is null"; ESP_LOGW(TAG, "%.*s", msg.size(), msg.data()); CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } - auto *changeValueDisplay = currentDisplay->asChangeValueDisplayInterface(); + auto *changeValueDisplay = espgui::currentDisplay->asChangeValueDisplayInterface(); if (!changeValueDisplay) { - constexpr const std::string_view msg = "currentDisplay is not a change value display"; + constexpr const std::string_view msg = "espgui::currentDisplay is not a change value display"; ESP_LOGW(TAG, "%.*s", msg.size(), msg.data()); CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } diff --git a/main/webserver_ota.h b/main/webserver_ota.h index 732cb44..9e19ff5 100644 --- a/main/webserver_ota.h +++ b/main/webserver_ota.h @@ -5,6 +5,7 @@ #include #endif #include +#include // 3rdparty lib includes #include @@ -13,6 +14,7 @@ #include #include #include +#include // local includes #ifdef FEATURE_OTA