From 1de44c630b692cd5dfba31ce2c1041805b737acf Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Tue, 2 Nov 2021 01:43:58 +0100 Subject: [PATCH 01/10] 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 From 316f74ada8085c0f11c8129316a1f4acbb59ab01 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Tue, 2 Nov 2021 11:39:36 +0100 Subject: [PATCH 02/10] More rewrite --- main/ble_bobby.cpp | 267 ++++++++++++++++++ main/ble_bobby.h | 261 +---------------- main/cloud.cpp | 251 ++++++++++++++++ main/cloud.h | 248 +--------------- main/displays/menus/aboutmenu.cpp | 25 +- main/displays/menus/aboutmenu.h | 21 +- .../menus/accesspointwifisettingsmenu.h | 5 - .../boardcomputerhardwaresettingsmenu.cpp | 8 +- main/displays/menus/genericwifisettingsmenu.h | 6 - main/displays/menus/limitssettingsmenu.cpp | 75 +++++ main/displays/menus/limitssettingsmenu.h | 75 +---- .../displays/menus/lockscreensettingsmenu.cpp | 65 +++++ main/displays/menus/lockscreensettingsmenu.h | 65 +---- .../menus/stationwifisettingsmenu.cpp | 52 ++++ main/displays/menus/stationwifisettingsmenu.h | 59 +--- main/displays/menus/wifiscanmenu.h | 5 - main/displays/menus/wifisettingsmenu.cpp | 27 ++ main/displays/menus/wifisettingsmenu.h | 28 +- main/ledstrip.h | 2 + main/wifitexthelpers.cpp | 167 +++++++++++ main/wifitexthelpers.h | 240 +++++----------- 21 files changed, 1057 insertions(+), 895 deletions(-) diff --git a/main/ble_bobby.cpp b/main/ble_bobby.cpp index e69de29..ece99bf 100644 --- a/main/ble_bobby.cpp +++ b/main/ble_bobby.cpp @@ -0,0 +1,267 @@ +#include "ble_bobby.h" + +// esp-idf includes +#include + +namespace { +constexpr const char * const TAG = "BOBBYBLE"; +} // namespace + +#ifdef FEATURE_BLE +BLEServer *pServer{}; +BLEService *pService{}; +BLECharacteristic *livestatsCharacteristic{}; +BLECharacteristic *remotecontrolCharacteristic{}; +#ifdef FEATURE_WIRELESS_CONFIG +BLECharacteristic *wirelessConfig{}; +BLECharacteristic *getwifilist{}; +#endif + +RemoteControlCallbacks bleRemoteCallbacks; + +#ifdef FEATURE_WIRELESS_CONFIG +WirelessSettingsCallbacks bleWirelessSettingsCallbacks; +WiFiListCallbacks bleWiFiListCallbacks; +#endif + +void createBle() +{ + ESP_LOGI("BOBBY", "called"); + + BLEDevice::init(deviceName); + + const auto serviceUuid{"0335e46c-f355-4ce6-8076-017de08cee98"}; + + pServer = BLEDevice::createServer(); + + pService = pServer->createService(serviceUuid); + + livestatsCharacteristic = pService->createCharacteristic("a48321ea-329f-4eab-a401-30e247211524", NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY); + remotecontrolCharacteristic = pService->createCharacteristic("4201def0-a264-43e6-946b-6b2d9612dfed", NIMBLE_PROPERTY::WRITE); + remotecontrolCharacteristic->setCallbacks(&bleRemoteCallbacks); +#ifdef FEATURE_WIRELESS_CONFIG + wirelessConfig = pService->createCharacteristic("4201def1-a264-43e6-946b-6b2d9612dfed", NIMBLE_PROPERTY::WRITE); + wirelessConfig->setCallbacks(&bleWirelessSettingsCallbacks); + getwifilist = pService->createCharacteristic("4201def2-a264-43e6-946b-6b2d9612dfed", NIMBLE_PROPERTY::READ); + getwifilist->setCallbacks(&bleWiFiListCallbacks); +#endif + + pService->start(); + + BLEAdvertising *pAdvertising = BLEDevice::getAdvertising(); + pAdvertising->addServiceUUID(serviceUuid); + pAdvertising->setScanResponse(true); + BLEDevice::startAdvertising(); +} + +void destroyBle() +{ + ESP_LOGI("BOBBY", "called"); + + BLEDevice::deinit(true); + + pServer = {}; + pService = {}; + livestatsCharacteristic = {}; + remotecontrolCharacteristic = {}; +#ifdef FEATURE_WIRELESS_CONFIG + wirelessConfig = {}; + getwifilist = {}; +#endif +} + +void initBle() +{ + if (settings.bleSettings.bleEnabled) + createBle(); +} + + +void handleBle() +{ + if (settings.bleSettings.bleEnabled) + { + if (!pServer) + createBle(); + + if (livestatsCharacteristic->getSubscribedCount()) + { + StaticJsonDocument<1024> doc; + { + auto arr = doc.createNestedArray("v"); + if (controllers.front.feedbackValid) + arr.add(controllers.front.getCalibratedVoltage()); + else + arr.add(nullptr); + if (controllers.back.feedbackValid) + arr.add(controllers.back.getCalibratedVoltage()); + else + arr.add(nullptr); + } + + { + auto arr = doc.createNestedArray("t"); + if (controllers.front.feedbackValid) + arr.add(fixBoardTemp(controllers.front.feedback.boardTemp)); + else + arr.add(nullptr); + if (controllers.back.feedbackValid) + arr.add(fixBoardTemp(controllers.back.feedback.boardTemp)); + else + arr.add(nullptr); + } + + { + auto arr = doc.createNestedArray("e"); + if (controllers.front.feedbackValid) + { + arr.add(controllers.front.feedback.left.error); + arr.add(controllers.front.feedback.right.error); + } + else + { + arr.add(nullptr); + arr.add(nullptr); + } + if (controllers.back.feedbackValid) + { + arr.add(controllers.back.feedback.left.error); + arr.add(controllers.back.feedback.right.error); + } + else + { + arr.add(nullptr); + arr.add(nullptr); + } + } + + { + auto arr = doc.createNestedArray("s"); + if (controllers.front.feedbackValid) + { + arr.add(convertToKmh(controllers.front.feedback.left.speed * (settings.controllerHardware.invertFrontLeft ? -1 : 1))); + arr.add(convertToKmh(controllers.front.feedback.right.speed * (settings.controllerHardware.invertFrontRight ? -1 : 1))); + } + else + { + arr.add(nullptr); + arr.add(nullptr); + } + if (controllers.back.feedbackValid) + { + arr.add(convertToKmh(controllers.back.feedback.left.speed * (settings.controllerHardware.invertBackLeft ? -1 : 1))); + arr.add(convertToKmh(controllers.back.feedback.right.speed * (settings.controllerHardware.invertBackRight ? -1 : 1))); + } + else + { + arr.add(nullptr); + arr.add(nullptr); + } + } + + { + auto arr = doc.createNestedArray("a"); + if (controllers.front.feedbackValid) + { + arr.add(fixCurrent(controllers.front.feedback.left.dcLink) * 2); + arr.add(fixCurrent(controllers.front.feedback.right.dcLink) * 2); + } + else + { + arr.add(nullptr); + arr.add(nullptr); + } + if (controllers.back.feedbackValid) + { + arr.add(fixCurrent(controllers.back.feedback.left.dcLink) * 2); + arr.add(fixCurrent(controllers.back.feedback.right.dcLink) * 2); + } + else + { + arr.add(nullptr); + arr.add(nullptr); + } + } + + std::string json; + serializeJson(doc, json); + + livestatsCharacteristic->setValue(json); + livestatsCharacteristic->notify(); + } + } + else if (pServer) + { + destroyBle(); + } +} + +void RemoteControlCallbacks::onWrite(NimBLECharacteristic* pCharacteristic) +{ + const auto &val = pCharacteristic->getValue(); + + StaticJsonDocument<256> doc; + if (const auto error = deserializeJson(doc, val)) + { + ESP_LOGW(TAG, "ignoring cmd with invalid json: %.*s %s", val.size(), val.data(), error.c_str()); + return; + } + +#ifdef FEATURE_LEDSTRIP + auto newBlinkAnimation = doc["anim"].as(); + if (blinkAnimation != newBlinkAnimation) blinkAnimation = newBlinkAnimation; +#endif + + if (!simplified) + { + modes::remoteControlMode.setCommand(RemoteCommand{ + .frontLeft = doc["fl"].as(), + .frontRight = doc["fr"].as(), + .backLeft = doc["bl"].as(), + .backRight = doc["br"].as() + }); + } +} + +#ifdef FEATURE_WIRELESS_CONFIG +void WirelessSettingsCallbacks::onWrite(NimBLECharacteristic* pCharacteristic) +{ + const auto &val = pCharacteristic->getValue(); + + StaticJsonDocument<256> doc; + if (const auto error = deserializeJson(doc, val)) + { + ESP_LOGW(TAG, "ignoring cmd with invalid json: %.*s %s", val.size(), val.data(), error.c_str()); + return; + } + + auto write_type = doc["type"].as(); + + if (write_type == "wifi") { + const int index = doc["wifi_index"].as(); + ESP_LOGI(TAG, "[ble_config]: Set wifi%i: WiFi-SSID: %s, WiFi-Password: ***", doc["wifi_index"].as(), doc["wifi_ssid"].as()); + stringSettings.wifis[index].ssid = doc["wifi_ssid"].as(); + stringSettings.wifis[index].key = doc["wifi_pass"].as(); + saveSettings(); + } else { + const auto deserialized = deserializeJson(doc, val); + ESP_LOGW(TAG, "Unkown type %s -> json: %.*s %s", doc["type"].as(), val.size(), val.data(), deserialized.c_str()); + } +} + +void WiFiListCallbacks::onRead(NimBLECharacteristic *pCharacteristic) { + StaticJsonDocument<768> responseDoc; + auto wifis = stringSettings.wifis; + auto wifiArray = responseDoc.createNestedArray("wifis"); + ESP_LOGI(TAG, "[ble_wifilist] Got request for listing wifi ssids."); + for (unsigned int index = 0; index < wifis.size(); index++) { + wifiArray.add(wifis[index].ssid); + } + responseDoc["wifi_count"] = wifis.size(); + std::string json; + serializeJson(responseDoc, json); + pCharacteristic->setValue(json); +} +#endif + +#endif diff --git a/main/ble_bobby.h b/main/ble_bobby.h index 069a4d4..032f679 100644 --- a/main/ble_bobby.h +++ b/main/ble_bobby.h @@ -1,8 +1,5 @@ #pragma once -// esp-idf includes -#include - // 3rdparty lib includes #include #ifdef FEATURE_BLE @@ -21,15 +18,14 @@ //wifistack #include "wifi_bobbycar.h" -namespace { #ifdef FEATURE_BLE -BLEServer *pServer{}; -BLEService *pService{}; -BLECharacteristic *livestatsCharacteristic{}; -BLECharacteristic *remotecontrolCharacteristic{}; +extern BLEServer *pServer; +extern BLEService *pService; +extern BLECharacteristic *livestatsCharacteristic; +extern BLECharacteristic *remotecontrolCharacteristic; #ifdef FEATURE_WIRELESS_CONFIG -BLECharacteristic *wirelessConfig{}; -BLECharacteristic *getwifilist{}; +extern BLECharacteristic *wirelessConfig; +extern BLECharacteristic *getwifilist; #endif void createBle(); @@ -55,250 +51,15 @@ public: }; #endif -RemoteControlCallbacks bleRemoteCallbacks; +extern RemoteControlCallbacks bleRemoteCallbacks; #ifdef FEATURE_WIRELESS_CONFIG -WirelessSettingsCallbacks bleWirelessSettingsCallbacks; -WiFiListCallbacks bleWiFiListCallbacks; +extern WirelessSettingsCallbacks bleWirelessSettingsCallbacks; +extern WiFiListCallbacks bleWiFiListCallbacks; #endif -void initBle() -{ - if (settings.bleSettings.bleEnabled) - createBle(); -} +void initBle(); -void handleBle() -{ - if (settings.bleSettings.bleEnabled) - { - if (!pServer) - createBle(); +void handleBle(); - if (livestatsCharacteristic->getSubscribedCount()) - { - StaticJsonDocument<1024> doc; - { - auto arr = doc.createNestedArray("v"); - if (controllers.front.feedbackValid) - arr.add(controllers.front.getCalibratedVoltage()); - else - arr.add(nullptr); - if (controllers.back.feedbackValid) - arr.add(controllers.back.getCalibratedVoltage()); - else - arr.add(nullptr); - } - - { - auto arr = doc.createNestedArray("t"); - if (controllers.front.feedbackValid) - arr.add(fixBoardTemp(controllers.front.feedback.boardTemp)); - else - arr.add(nullptr); - if (controllers.back.feedbackValid) - arr.add(fixBoardTemp(controllers.back.feedback.boardTemp)); - else - arr.add(nullptr); - } - - { - auto arr = doc.createNestedArray("e"); - if (controllers.front.feedbackValid) - { - arr.add(controllers.front.feedback.left.error); - arr.add(controllers.front.feedback.right.error); - } - else - { - arr.add(nullptr); - arr.add(nullptr); - } - if (controllers.back.feedbackValid) - { - arr.add(controllers.back.feedback.left.error); - arr.add(controllers.back.feedback.right.error); - } - else - { - arr.add(nullptr); - arr.add(nullptr); - } - } - - { - auto arr = doc.createNestedArray("s"); - if (controllers.front.feedbackValid) - { - arr.add(convertToKmh(controllers.front.feedback.left.speed * (settings.controllerHardware.invertFrontLeft ? -1 : 1))); - arr.add(convertToKmh(controllers.front.feedback.right.speed * (settings.controllerHardware.invertFrontRight ? -1 : 1))); - } - else - { - arr.add(nullptr); - arr.add(nullptr); - } - if (controllers.back.feedbackValid) - { - arr.add(convertToKmh(controllers.back.feedback.left.speed * (settings.controllerHardware.invertBackLeft ? -1 : 1))); - arr.add(convertToKmh(controllers.back.feedback.right.speed * (settings.controllerHardware.invertBackRight ? -1 : 1))); - } - else - { - arr.add(nullptr); - arr.add(nullptr); - } - } - - { - auto arr = doc.createNestedArray("a"); - if (controllers.front.feedbackValid) - { - arr.add(fixCurrent(controllers.front.feedback.left.dcLink) * 2); - arr.add(fixCurrent(controllers.front.feedback.right.dcLink) * 2); - } - else - { - arr.add(nullptr); - arr.add(nullptr); - } - if (controllers.back.feedbackValid) - { - arr.add(fixCurrent(controllers.back.feedback.left.dcLink) * 2); - arr.add(fixCurrent(controllers.back.feedback.right.dcLink) * 2); - } - else - { - arr.add(nullptr); - arr.add(nullptr); - } - } - - std::string json; - serializeJson(doc, json); - - livestatsCharacteristic->setValue(json); - livestatsCharacteristic->notify(); - } - } - else if (pServer) - { - destroyBle(); - } -} - -void createBle() -{ - ESP_LOGI("BOBBY", "called"); - - BLEDevice::init(deviceName); - - const auto serviceUuid{"0335e46c-f355-4ce6-8076-017de08cee98"}; - - pServer = BLEDevice::createServer(); - - pService = pServer->createService(serviceUuid); - - livestatsCharacteristic = pService->createCharacteristic("a48321ea-329f-4eab-a401-30e247211524", NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY); - remotecontrolCharacteristic = pService->createCharacteristic("4201def0-a264-43e6-946b-6b2d9612dfed", NIMBLE_PROPERTY::WRITE); - remotecontrolCharacteristic->setCallbacks(&bleRemoteCallbacks); -#ifdef FEATURE_WIRELESS_CONFIG - wirelessConfig = pService->createCharacteristic("4201def1-a264-43e6-946b-6b2d9612dfed", NIMBLE_PROPERTY::WRITE); - wirelessConfig->setCallbacks(&bleWirelessSettingsCallbacks); - getwifilist = pService->createCharacteristic("4201def2-a264-43e6-946b-6b2d9612dfed", NIMBLE_PROPERTY::READ); - getwifilist->setCallbacks(&bleWiFiListCallbacks); #endif - - pService->start(); - - BLEAdvertising *pAdvertising = BLEDevice::getAdvertising(); - pAdvertising->addServiceUUID(serviceUuid); - pAdvertising->setScanResponse(true); - BLEDevice::startAdvertising(); -} - -void destroyBle() -{ - ESP_LOGI("BOBBY", "called"); - - BLEDevice::deinit(true); - - pServer = {}; - pService = {}; - livestatsCharacteristic = {}; - remotecontrolCharacteristic = {}; -#ifdef FEATURE_WIRELESS_CONFIG - wirelessConfig = {}; - getwifilist = {}; -#endif -} - -void RemoteControlCallbacks::onWrite(NimBLECharacteristic* pCharacteristic) -{ - const auto &val = pCharacteristic->getValue(); - - StaticJsonDocument<256> doc; - if (const auto error = deserializeJson(doc, val)) - { - ESP_LOGW(TAG, "ignoring cmd with invalid json: %.*s %s", val.size(), val.data(), error.c_str()); - return; - } - -#ifdef FEATURE_LEDSTRIP - auto newBlinkAnimation = doc["anim"].as(); - if (blinkAnimation != newBlinkAnimation) blinkAnimation = newBlinkAnimation; -#endif - - if (!simplified) - { - modes::remoteControlMode.setCommand(RemoteCommand{ - .frontLeft = doc["fl"].as(), - .frontRight = doc["fr"].as(), - .backLeft = doc["bl"].as(), - .backRight = doc["br"].as() - }); - } -} - -#ifdef FEATURE_WIRELESS_CONFIG -void WirelessSettingsCallbacks::onWrite(NimBLECharacteristic* pCharacteristic) -{ - const auto &val = pCharacteristic->getValue(); - - StaticJsonDocument<256> doc; - if (const auto error = deserializeJson(doc, val)) - { - ESP_LOGW(TAG, "ignoring cmd with invalid json: %.*s %s", val.size(), val.data(), error.c_str()); - return; - } - - auto write_type = doc["type"].as(); - - if (write_type == "wifi") { - const int index = doc["wifi_index"].as(); - ESP_LOGI(TAG, "[ble_config]: Set wifi%i: WiFi-SSID: %s, WiFi-Password: ***", doc["wifi_index"].as(), doc["wifi_ssid"].as()); - stringSettings.wifis[index].ssid = doc["wifi_ssid"].as(); - stringSettings.wifis[index].key = doc["wifi_pass"].as(); - saveSettings(); - } else { - const auto deserialized = deserializeJson(doc, val); - ESP_LOGW(TAG, "Unkown type %s -> json: %.*s %s", doc["type"].as(), val.size(), val.data(), deserialized.c_str()); - } -} - -void WiFiListCallbacks::onRead(NimBLECharacteristic *pCharacteristic) { - StaticJsonDocument<768> responseDoc; - auto wifis = stringSettings.wifis; - auto wifiArray = responseDoc.createNestedArray("wifis"); - ESP_LOGI(TAG, "[ble_wifilist] Got request for listing wifi ssids."); - for (unsigned int index = 0; index < wifis.size(); index++) { - wifiArray.add(wifis[index].ssid); - } - responseDoc["wifi_count"] = wifis.size(); - std::string json; - serializeJson(responseDoc, json); - pCharacteristic->setValue(json); -} -#endif -#endif -} diff --git a/main/cloud.cpp b/main/cloud.cpp index e69de29..b6a0eaa 100644 --- a/main/cloud.cpp +++ b/main/cloud.cpp @@ -0,0 +1,251 @@ +#include "cloud.h" + +// esp-idf includes +#include + +using namespace std::chrono_literals; + +namespace { +constexpr const char * const TAG = "BOBBYCLOUD"; +} // namespace + +#ifdef FEATURE_CLOUD + +espcpputils::websocket_client cloudClient; +bool cloudStarted{}; +espchrono::millis_clock::time_point lastCreateTry; +espchrono::millis_clock::time_point lastStartTry; +std::string cloudBuffer; + +void initCloud() +{ + if (settings.cloudSettings.cloudEnabled && + !stringSettings.cloudUrl.empty() && + esphttpdutils::urlverify(stringSettings.cloudUrl)) + { + createCloud(); + if (!cloudClient) + return; + + if (wifi_stack::get_sta_status() != wifi_stack::WiFiStaStatus::CONNECTED) + return; + + startCloud(); + } +} + +void cloudCollect() +{ + if (!cloudClient) + { + cloudBuffer.clear(); + return; + } + + if (!cloudStarted) + { + cloudBuffer.clear(); + return; + } + + if (!cloudClient.is_connected()) + { + cloudBuffer.clear(); + return; + } + + if (cloudBuffer.empty()) + cloudBuffer = '['; + else + cloudBuffer += ','; + + cloudBuffer += fmt::format("[{},{},{}", + std::chrono::milliseconds{espchrono::millis_clock::now().time_since_epoch()}.count(), + std::chrono::milliseconds{espchrono::utc_clock::now().time_since_epoch()}.count(), + heap_caps_get_free_size(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)); + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) + { + if (const auto &result = wifi_stack::get_sta_ap_info(); result) + cloudBuffer += fmt::format(",{}", result->rssi); + else + cloudBuffer += ",null"; + } + else + cloudBuffer += ",null"; + + if (raw_gas) + cloudBuffer += fmt::format(",{}", *raw_gas); + else + cloudBuffer += ",null"; + + if (raw_brems) + cloudBuffer += fmt::format(",{}", *raw_brems); + else + cloudBuffer += ",null"; + + if (gas) + cloudBuffer += fmt::format(",{:.1f}", *gas); + else + cloudBuffer += ",null"; + + if (brems) + cloudBuffer += fmt::format(",{:.1f}", *brems); + else + cloudBuffer += ",null"; + + constexpr const auto addController = [](const Controller &controller){ + if (!controller.feedbackValid) + { + cloudBuffer += ",null"; + return; + } + + cloudBuffer += fmt::format(",[{:.02f},{:.02f}", + controller.getCalibratedVoltage(), + fixBoardTemp(controller.feedback.boardTemp)); + + constexpr const auto addMotor = [](const bobbycar::protocol::serial::MotorState &command, + const bobbycar::protocol::serial::MotorFeedback &feedback, + bool invert){ + cloudBuffer += fmt::format(",[{},{:.2f},{:.2f},{}]", + command.pwm * (invert?-1:1), + convertToKmh(feedback.speed) * (invert?-1:1), + fixCurrent(feedback.dcLink), + feedback.error); + }; + + addMotor(controller.command.left, controller.feedback.left, controller.invertLeft); + addMotor(controller.command.right, controller.feedback.right, controller.invertRight); + + cloudBuffer += ']'; + }; + + addController(controllers.front); + addController(controllers.back); + + cloudBuffer += "]"; +} + +void cloudSend() +{ + if (settings.cloudSettings.cloudEnabled && + !stringSettings.cloudUrl.empty() && + esphttpdutils::urlverify(stringSettings.cloudUrl)) + { + if (!cloudClient) + { + if (espchrono::ago(lastCreateTry) < 10s) + return; + createCloud(); + } + if (!cloudClient) + return; + + if (!cloudStarted) + { + if (espchrono::ago(lastStartTry) < 10s) + return; + + if (wifi_stack::get_sta_status() != wifi_stack::WiFiStaStatus::CONNECTED) + return; + + startCloud(); + } + if (!cloudStarted) + return; + + if (!cloudClient.is_connected()) + return; + + if (cloudBuffer.empty()) + return; + + cloudBuffer += ']'; + + const auto timeout = std::chrono::ceil(espchrono::milliseconds32{settings.cloudSettings.cloudTransmitTimeout}).count(); + const auto written = cloudClient.send_text(cloudBuffer, timeout); + + if (written < 0) + { + ESP_LOGE("BOBBY", "cloudClient.send_text() failed with %i", written); + } + else if (written != cloudBuffer.size()) + { + ESP_LOGE("BOBBY", "websocket sent size mismatch, sent=%i, expected=%i", written, cloudBuffer.size()); + } + + cloudBuffer.clear(); + } + else if (cloudClient) + { + destroyCloud(); + } +} + +void createCloud() +{ + ESP_LOGI("BOBBY", "called"); + + if (cloudClient) + { + ESP_LOGE(TAG, "cloud client already created"); + return; + } + + lastCreateTry = espchrono::millis_clock::now(); + + const esp_websocket_client_config_t config = { + .uri = stringSettings.cloudUrl.c_str(), + }; + + cloudClient = espcpputils::websocket_client{&config}; + + if (!cloudClient) + { + ESP_LOGE(TAG, "websocket could not be constructed"); + return; + } + + ESP_LOGI("BOBBY", "cloud client created"); +} + +void startCloud() +{ + ESP_LOGI("BOBBY", "called"); + + if (!cloudClient) + { + ESP_LOGE(TAG, "cloud client not created"); + return; + } + + if (cloudStarted) + { + ESP_LOGE(TAG, "cloud client already started"); + return; + } + + lastStartTry = espchrono::millis_clock::now(); + + const auto result = cloudClient.start(); + ESP_LOG_LEVEL_LOCAL((result == ESP_OK ? ESP_LOG_INFO : ESP_LOG_ERROR), "BOBBY", "cloudClient.start() returned: %s", esp_err_to_name(result)); + + if (result == ESP_OK) + cloudStarted = true; +} + +void destroyCloud() +{ + ESP_LOGI("BOBBY", "called"); + + if (!cloudClient) + { + ESP_LOGE(TAG, "cloud client not created"); + return; + } + + cloudClient = {}; + cloudStarted = false; +} + +#endif diff --git a/main/cloud.h b/main/cloud.h index 61b5d13..84029f2 100644 --- a/main/cloud.h +++ b/main/cloud.h @@ -1,8 +1,5 @@ #pragma once -// esp-idf includes -#include - // 3rdparty lib includes #include #include @@ -14,247 +11,18 @@ #include "globals.h" #include "utils.h" -namespace { #ifdef FEATURE_CLOUD -espcpputils::websocket_client cloudClient; -bool cloudStarted{}; -espchrono::millis_clock::time_point lastCreateTry; -espchrono::millis_clock::time_point lastStartTry; -std::string cloudBuffer; +extern espcpputils::websocket_client cloudClient; +extern bool cloudStarted; +extern espchrono::millis_clock::time_point lastCreateTry; +extern espchrono::millis_clock::time_point lastStartTry; +extern std::string cloudBuffer; void createCloud(); void destroyCloud(); void startCloud(); -void initCloud() -{ - if (settings.cloudSettings.cloudEnabled && - !stringSettings.cloudUrl.empty() && - esphttpdutils::urlverify(stringSettings.cloudUrl)) - { - createCloud(); - if (!cloudClient) - return; - - if (wifi_stack::get_sta_status() != wifi_stack::WiFiStaStatus::CONNECTED) - return; - - startCloud(); - } -} - -void cloudCollect() -{ - if (!cloudClient) - { - cloudBuffer.clear(); - return; - } - - if (!cloudStarted) - { - cloudBuffer.clear(); - return; - } - - if (!cloudClient.is_connected()) - { - cloudBuffer.clear(); - return; - } - - if (cloudBuffer.empty()) - cloudBuffer = '['; - else - cloudBuffer += ','; - - cloudBuffer += fmt::format("[{},{},{}", - std::chrono::milliseconds{espchrono::millis_clock::now().time_since_epoch()}.count(), - std::chrono::milliseconds{espchrono::utc_clock::now().time_since_epoch()}.count(), - heap_caps_get_free_size(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)); - if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) - { - if (const auto &result = wifi_stack::get_sta_ap_info(); result) - cloudBuffer += fmt::format(",{}", result->rssi); - else - cloudBuffer += ",null"; - } - else - cloudBuffer += ",null"; - - if (raw_gas) - cloudBuffer += fmt::format(",{}", *raw_gas); - else - cloudBuffer += ",null"; - - if (raw_brems) - cloudBuffer += fmt::format(",{}", *raw_brems); - else - cloudBuffer += ",null"; - - if (gas) - cloudBuffer += fmt::format(",{:.1f}", *gas); - else - cloudBuffer += ",null"; - - if (brems) - cloudBuffer += fmt::format(",{:.1f}", *brems); - else - cloudBuffer += ",null"; - - constexpr const auto addController = [](const Controller &controller){ - if (!controller.feedbackValid) - { - cloudBuffer += ",null"; - return; - } - - cloudBuffer += fmt::format(",[{:.02f},{:.02f}", - controller.getCalibratedVoltage(), - fixBoardTemp(controller.feedback.boardTemp)); - - constexpr const auto addMotor = [](const bobbycar::protocol::serial::MotorState &command, - const bobbycar::protocol::serial::MotorFeedback &feedback, - bool invert){ - cloudBuffer += fmt::format(",[{},{:.2f},{:.2f},{}]", - command.pwm * (invert?-1:1), - convertToKmh(feedback.speed) * (invert?-1:1), - fixCurrent(feedback.dcLink), - feedback.error); - }; - - addMotor(controller.command.left, controller.feedback.left, controller.invertLeft); - addMotor(controller.command.right, controller.feedback.right, controller.invertRight); - - cloudBuffer += ']'; - }; - - addController(controllers.front); - addController(controllers.back); - - cloudBuffer += "]"; -} - -void cloudSend() -{ - if (settings.cloudSettings.cloudEnabled && - !stringSettings.cloudUrl.empty() && - esphttpdutils::urlverify(stringSettings.cloudUrl)) - { - if (!cloudClient) - { - if (espchrono::ago(lastCreateTry) < 10s) - return; - createCloud(); - } - if (!cloudClient) - return; - - if (!cloudStarted) - { - if (espchrono::ago(lastStartTry) < 10s) - return; - - if (wifi_stack::get_sta_status() != wifi_stack::WiFiStaStatus::CONNECTED) - return; - - startCloud(); - } - if (!cloudStarted) - return; - - if (!cloudClient.is_connected()) - return; - - if (cloudBuffer.empty()) - return; - - cloudBuffer += ']'; - - const auto timeout = std::chrono::ceil(espchrono::milliseconds32{settings.cloudSettings.cloudTransmitTimeout}).count(); - const auto written = cloudClient.send_text(cloudBuffer, timeout); - - if (written < 0) - { - ESP_LOGE("BOBBY", "cloudClient.send_text() failed with %i", written); - } - else if (written != cloudBuffer.size()) - { - ESP_LOGE("BOBBY", "websocket sent size mismatch, sent=%i, expected=%i", written, cloudBuffer.size()); - } - - cloudBuffer.clear(); - } - else if (cloudClient) - { - destroyCloud(); - } -} - -void createCloud() -{ - ESP_LOGI("BOBBY", "called"); - - if (cloudClient) - { - ESP_LOGE(TAG, "cloud client already created"); - return; - } - - lastCreateTry = espchrono::millis_clock::now(); - - const esp_websocket_client_config_t config = { - .uri = stringSettings.cloudUrl.c_str(), - }; - - cloudClient = espcpputils::websocket_client{&config}; - - if (!cloudClient) - { - ESP_LOGE(TAG, "websocket could not be constructed"); - return; - } - - ESP_LOGI("BOBBY", "cloud client created"); -} - -void startCloud() -{ - ESP_LOGI("BOBBY", "called"); - - if (!cloudClient) - { - ESP_LOGE(TAG, "cloud client not created"); - return; - } - - if (cloudStarted) - { - ESP_LOGE(TAG, "cloud client already started"); - return; - } - - lastStartTry = espchrono::millis_clock::now(); - - const auto result = cloudClient.start(); - ESP_LOG_LEVEL_LOCAL((result == ESP_OK ? ESP_LOG_INFO : ESP_LOG_ERROR), "BOBBY", "cloudClient.start() returned: %s", esp_err_to_name(result)); - - if (result == ESP_OK) - cloudStarted = true; -} - -void destroyCloud() -{ - ESP_LOGI("BOBBY", "called"); - - if (!cloudClient) - { - ESP_LOGE(TAG, "cloud client not created"); - return; - } - - cloudClient = {}; - cloudStarted = false; -} +void initCloud(); +void cloudCollect(); +void cloudSend(); #endif -} // namespace diff --git a/main/displays/menus/aboutmenu.cpp b/main/displays/menus/aboutmenu.cpp index 548eb41..6cf864e 100644 --- a/main/displays/menus/aboutmenu.cpp +++ b/main/displays/menus/aboutmenu.cpp @@ -6,15 +6,38 @@ #include "actions/switchscreenaction.h" #include "icons/back.h" #include "esptexthelpers.h" +#include "displays/menus/settingsmenu.h" + #ifdef FEATURE_OTA #include #include #include "fmt/core.h" #endif +namespace { +class CurrentVersionText : public virtual espgui::TextInterface +{ +public: + std::string text() const override + { +#ifdef FEATURE_OTA + if (const esp_app_desc_t *app_desc = esp_ota_get_app_description()) + { + return fmt::format("Version: {}", app_desc->version); + } +#endif + return "Version: 1.0"; + }; +}; + +constexpr char TEXT_VERSION[] = "Version: 1.0"; +} // namespace + +using namespace espgui; + AboutMenu::AboutMenu() { - constructMenuItem>(); + constructMenuItem>(); constructMenuItem, DisabledColor, DummyAction>>(); constructMenuItem, DisabledColor, DummyAction>>(); constructMenuItem, DisabledColor, DummyAction>>(); diff --git a/main/displays/menus/aboutmenu.h b/main/displays/menus/aboutmenu.h index b3a30bc..eac7dec 100644 --- a/main/displays/menus/aboutmenu.h +++ b/main/displays/menus/aboutmenu.h @@ -6,29 +6,12 @@ // local includes #include "texts.h" -using namespace espgui; - -namespace { -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()) - { - return fmt::format("Version: {}", app_desc->version); - } -#endif - return "Version: 1.0"; - }; -}; - -constexpr char TEXT_VERSION[] = "Version: 1.0"; - class AboutMenu : - public MenuDisplay, - public StaticText + public espgui::MenuDisplay, + public espgui::StaticText { public: AboutMenu(); void back() override; }; -} // namespace diff --git a/main/displays/menus/accesspointwifisettingsmenu.h b/main/displays/menus/accesspointwifisettingsmenu.h index 71b4a2a..11be9f9 100644 --- a/main/displays/menus/accesspointwifisettingsmenu.h +++ b/main/displays/menus/accesspointwifisettingsmenu.h @@ -12,11 +12,6 @@ #include "accessors/settingsaccessors.h" #include "texts.h" -// forward declares -namespace { -class WifiSettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/boardcomputerhardwaresettingsmenu.cpp b/main/displays/menus/boardcomputerhardwaresettingsmenu.cpp index afe098a..b5d71f8 100644 --- a/main/displays/menus/boardcomputerhardwaresettingsmenu.cpp +++ b/main/displays/menus/boardcomputerhardwaresettingsmenu.cpp @@ -15,9 +15,12 @@ #include "accessors/settingsaccessors.h" #include "displays/menus/lockscreensettingsmenu.h" #include "displays/calibratedisplay.h" +#include "displays/menus/timersmenu.h" +#include "displays/menus/settingsmenu.h" namespace { -struct GasText : public virtual espgui::TextInterface { +struct GasText : public virtual espgui::TextInterface +{ public: std::string text() const override { @@ -27,7 +30,8 @@ public: gas ? fmt::format("{:.02f}", *gas) : "?"); } }; -struct BremsText : public virtual espgui::TextInterface { +struct BremsText : public virtual espgui::TextInterface +{ public: std::string text() const override { diff --git a/main/displays/menus/genericwifisettingsmenu.h b/main/displays/menus/genericwifisettingsmenu.h index c8cc09d..6ebc436 100644 --- a/main/displays/menus/genericwifisettingsmenu.h +++ b/main/displays/menus/genericwifisettingsmenu.h @@ -13,12 +13,6 @@ #include "accessors/wifiaccessors.h" #include "texts.h" -// forward declares -namespace { -class GenericWifiSettingsMenu; -class WifiSettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/limitssettingsmenu.cpp b/main/displays/menus/limitssettingsmenu.cpp index e69de29..9f8ad91 100644 --- a/main/displays/menus/limitssettingsmenu.cpp +++ b/main/displays/menus/limitssettingsmenu.cpp @@ -0,0 +1,75 @@ +#include "limitssettingsmenu.h" + +// 3rdparty lib includes +#include "changevaluedisplay.h" +#include "menuitem.h" +#include "actions/switchscreenaction.h" +#include "icons/back.h" + +// local includes +#include "utils.h" +#include "accessors/settingsaccessors.h" +#include "displays/menus/settingsmenu.h" + +namespace { +using IMotMaxChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + IMotMaxAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using IDcMaxChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + IDcMaxAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using NMotMaxKmhChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + NMotMaxKmhAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using NMotMaxRpmChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + NMotMaxRpmAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using FieldWeakMaxChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + FieldWeakMaxAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using PhaseAdvMaxChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + PhaseAdvMaxAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +} // namespace + +using namespace espgui; + +LimitsSettingsMenu::LimitsSettingsMenu() +{ + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void LimitsSettingsMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/limitssettingsmenu.h b/main/displays/menus/limitssettingsmenu.h index a40417c..25c0d63 100644 --- a/main/displays/menus/limitssettingsmenu.h +++ b/main/displays/menus/limitssettingsmenu.h @@ -1,76 +1,17 @@ #pragma once -// local includes +// 3rdparty lib includes #include "menudisplay.h" -#include "utils.h" -#include "changevaluedisplay.h" -#include "menuitem.h" -#include "actions/switchscreenaction.h" -#include "icons/back.h" + +// local includes #include "texts.h" -#include "accessors/settingsaccessors.h" - -using namespace espgui; - -namespace { -using IMotMaxChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - IMotMaxAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using IDcMaxChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - IDcMaxAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using NMotMaxKmhChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - NMotMaxKmhAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using NMotMaxRpmChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - NMotMaxRpmAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using FieldWeakMaxChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - FieldWeakMaxAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using PhaseAdvMaxChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - PhaseAdvMaxAccessor, - BackActionInterface>, - SwitchScreenAction ->; class LimitsSettingsMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - LimitsSettingsMenu() - { - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + LimitsSettingsMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/menus/lockscreensettingsmenu.cpp b/main/displays/menus/lockscreensettingsmenu.cpp index e69de29..57b9a08 100644 --- a/main/displays/menus/lockscreensettingsmenu.cpp +++ b/main/displays/menus/lockscreensettingsmenu.cpp @@ -0,0 +1,65 @@ +#include "lockscreensettingsmenu.h" + +// 3rdparty lib includes +#include "menuitem.h" +#include "actions/toggleboolaction.h" +#include "actions/switchscreenaction.h" +#include "icons/back.h" +#include "checkboxicon.h" +#include "changevaluedisplay.h" + +// local includes +#include "globals.h" +#include "accessors/settingsaccessors.h" +#include "displays/menus/boardcomputerhardwaresettingsmenu.h" + +namespace { +using LockscreenPinDigit0ChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + LockscreenPinDigitAccessor<0>, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +using LockscreenPinDigit1ChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + LockscreenPinDigitAccessor<1>, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +using LockscreenPinDigit2ChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + LockscreenPinDigitAccessor<2>, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +using LockscreenPinDigit3ChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + LockscreenPinDigitAccessor<3>, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +} // namespace + +using namespace espgui; + +LockscreenSettingsMenu::LockscreenSettingsMenu() +{ + constructMenuItem, ToggleBoolAction, CheckboxIcon, LockscreenAllowPresetSwitchAccessor>>(); + constructMenuItem>, SwitchScreenAction>>(); + constructMenuItem>, SwitchScreenAction>>(); + constructMenuItem>, SwitchScreenAction>>(); + constructMenuItem>, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void LockscreenSettingsMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/lockscreensettingsmenu.h b/main/displays/menus/lockscreensettingsmenu.h index d1a2d2b..82cf322 100644 --- a/main/displays/menus/lockscreensettingsmenu.h +++ b/main/displays/menus/lockscreensettingsmenu.h @@ -1,66 +1,17 @@ #pragma once -// local includes +// 3rdparty lib includes #include "menudisplay.h" -#include "menuitem.h" -#include "actions/toggleboolaction.h" -#include "actions/switchscreenaction.h" + +// local includes #include "texts.h" -#include "icons/back.h" -#include "checkboxicon.h" -#include "globals.h" -#include "accessors/settingsaccessors.h" -#include "changevaluedisplay.h" - -using namespace espgui; - -namespace { -using LockscreenPinDigit0ChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - LockscreenPinDigitAccessor<0>, - BackActionInterface>, - SwitchScreenAction ->; - -using LockscreenPinDigit1ChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - LockscreenPinDigitAccessor<1>, - BackActionInterface>, - SwitchScreenAction ->; - -using LockscreenPinDigit2ChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - LockscreenPinDigitAccessor<2>, - BackActionInterface>, - SwitchScreenAction ->; - -using LockscreenPinDigit3ChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - LockscreenPinDigitAccessor<3>, - BackActionInterface>, - SwitchScreenAction ->; class LockscreenSettingsMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - LockscreenSettingsMenu() - { - constructMenuItem, ToggleBoolAction, CheckboxIcon, LockscreenAllowPresetSwitchAccessor>>(); - constructMenuItem>, SwitchScreenAction>>(); - constructMenuItem>, SwitchScreenAction>>(); - constructMenuItem>, SwitchScreenAction>>(); - constructMenuItem>, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + LockscreenSettingsMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/menus/stationwifisettingsmenu.cpp b/main/displays/menus/stationwifisettingsmenu.cpp index e69de29..29e850f 100644 --- a/main/displays/menus/stationwifisettingsmenu.cpp +++ b/main/displays/menus/stationwifisettingsmenu.cpp @@ -0,0 +1,52 @@ +#include "stationwifisettingsmenu.h" + +// 3rdparty lib includes +#include "menuitem.h" +#include "actions/dummyaction.h" +#include "actions/switchscreenaction.h" +#include "actions/toggleboolaction.h" +#include "checkboxicon.h" +#include "icons/back.h" + +// local includes +#include "utils.h" +#include "actions/wifiscanaction.h" +#include "icons/scan.h" +#include "wifitexthelpers.h" +#include "accessors/wifiaccessors.h" +#include "accessors/settingsaccessors.h" +#include "displays/menus/wifiscanmenu.h" +#include "displays/menus/wifisettingsmenu.h" + +using namespace espgui; + +StationWifiSettingsMenu::StationWifiSettingsMenu() +{ + constructMenuItem, ToggleBoolAction, CheckboxIcon, WifiStaEnabledAccessor>>(); + constructMenuItem, WifiScanAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::scan>>>(); + 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, 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 StationWifiSettingsMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/stationwifisettingsmenu.h b/main/displays/menus/stationwifisettingsmenu.h index 8046255..84cc9ea 100644 --- a/main/displays/menus/stationwifisettingsmenu.h +++ b/main/displays/menus/stationwifisettingsmenu.h @@ -1,60 +1,17 @@ #pragma once -// local includes +// 3rdparty lib includes #include "menudisplay.h" -#include "utils.h" -#include "menuitem.h" -#include "actions/dummyaction.h" -#include "actions/switchscreenaction.h" -#include "actions/wifiscanaction.h" -#include "actions/toggleboolaction.h" -#include "checkboxicon.h" -#include "icons/scan.h" -#include "icons/back.h" -#include "wifitexthelpers.h" -#include "accessors/wifiaccessors.h" -#include "accessors/settingsaccessors.h" + +// local includes #include "texts.h" -// forward declares -namespace { -class WifiScanMenu; -class WifiSettingsMenu; -} // namespace - -using namespace espgui; - -namespace { class StationWifiSettingsMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - StationWifiSettingsMenu() - { - constructMenuItem, ToggleBoolAction, CheckboxIcon, WifiStaEnabledAccessor>>(); - constructMenuItem, WifiScanAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::scan>>>(); - 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, 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>>>(); - } + StationWifiSettingsMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/menus/wifiscanmenu.h b/main/displays/menus/wifiscanmenu.h index 3fa2c10..ec6d2dc 100644 --- a/main/displays/menus/wifiscanmenu.h +++ b/main/displays/menus/wifiscanmenu.h @@ -21,11 +21,6 @@ #include "texts.h" #include "wifi_bobbycar.h" -// forward declares -namespace { -class StationWifiSettingsMenu; -} // namespace - using namespace std::chrono_literals; using namespace espgui; diff --git a/main/displays/menus/wifisettingsmenu.cpp b/main/displays/menus/wifisettingsmenu.cpp index e69de29..613de4b 100644 --- a/main/displays/menus/wifisettingsmenu.cpp +++ b/main/displays/menus/wifisettingsmenu.cpp @@ -0,0 +1,27 @@ +#include "wifisettingsmenu.h" + +// 3rdparty lib includes +#include "actions/switchscreenaction.h" +#include "icons/back.h" + +// local includes +#include "utils.h" +#include "displays/menus/genericwifisettingsmenu.h" +#include "displays/menus/stationwifisettingsmenu.h" +#include "displays/menus/accesspointwifisettingsmenu.h" +#include "displays/menus/settingsmenu.h" + +using namespace espgui; + +WifiSettingsMenu::WifiSettingsMenu() +{ + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void WifiSettingsMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/wifisettingsmenu.h b/main/displays/menus/wifisettingsmenu.h index febf58a..c9350d3 100644 --- a/main/displays/menus/wifisettingsmenu.h +++ b/main/displays/menus/wifisettingsmenu.h @@ -1,29 +1,17 @@ #pragma once -// local includes +// 3rdparty lib includes #include "menudisplay.h" -#include "utils.h" -#include "actions/switchscreenaction.h" -#include "icons/back.h" + +// local includes #include "texts.h" -using namespace espgui; - -namespace { -class WifiSettingsMenu; - class WifiSettingsMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - WifiSettingsMenu() - { - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + WifiSettingsMenu(); + + void back() override; }; -} // namespace diff --git a/main/ledstrip.h b/main/ledstrip.h index 205c257..25f84ef 100644 --- a/main/ledstrip.h +++ b/main/ledstrip.h @@ -9,6 +9,8 @@ #include "espchrono.h" #include "ledstripdefines.h" +using namespace std::chrono_literals; + namespace { enum Bobbycar_Side { diff --git a/main/wifitexthelpers.cpp b/main/wifitexthelpers.cpp index e69de29..a8afbe8 100644 --- a/main/wifitexthelpers.cpp +++ b/main/wifitexthelpers.cpp @@ -0,0 +1,167 @@ +#include "wifitexthelpers.h" + +// 3rdparty lib includes +#include +#include +#include +#include + +std::string WifiStatusText::text() const +{ + return fmt::format("Status: {}", wifi_stack::toString(wifi_stack::get_sta_status())); +} + +std::string WifiScanStatusText::text() const +{ + return fmt::format("ScanStatus: {}", wifi_stack::toString(wifi_stack::get_scan_status())); +} + +std::string WifiHostnameText::text() const +{ + std::string text = "Hostname: "; + const char *hostname{}; + if (const auto result = esp_netif_get_hostname(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &hostname); result == ESP_OK) + if (hostname) + text += hostname; + return text; +} + +std::string WifiMacText::text() const +{ + std::string text = "MAC: "; + if (const auto result = wifi_stack::get_base_mac_addr()) + text += wifi_stack::toString(*result); + return text; +} + +std::string WifiSsidText::text() const +{ + std::string text = "SSID: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) + if (const auto &result = wifi_stack::get_sta_ap_info(); result) + text += std::string_view{reinterpret_cast(result->ssid)}; + return text; +} + +std::string WifiBssidText::text() const +{ + std::string text = "BSSID: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) + if (const auto &result = wifi_stack::get_sta_ap_info(); result) + text += wifi_stack::toString(wifi_stack::mac_t{result->bssid}); + return text; +} + +std::string WifiRssiText::text() const +{ + std::string text = "RSSI: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) + if (const auto &result = wifi_stack::get_sta_ap_info(); result) + text += fmt::format("{}dB", result->rssi); + return text; +} + +std::string WifiEncryptionTypeText::text() const +{ + std::string text = "encryptionType: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) + if (const auto &result = wifi_stack::get_sta_ap_info(); result) + text += wifi_stack::toString(result->authmode); + return text; +} + +std::string WifiPairwiseCipherText::text() const +{ + std::string text = "pairwiseCipher: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) + if (const auto &result = wifi_stack::get_sta_ap_info(); result) + text += wifi_stack::toString(result->pairwise_cipher); + return text; +} + +std::string WifiGroupCipherText::text() const +{ + std::string text = "groupCipher: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) + if (const auto &result = wifi_stack::get_sta_ap_info(); result) + text += wifi_stack::toString(result->group_cipher); + return text; +} + +std::string WifiIpText::text() const +{ + std::string text = "ip: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) + if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA); result) + text += wifi_stack::toString(result->ip); + return text; +} + +std::string WifiNetmaskText::text() const +{ + std::string text = "netmask: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) + if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA); result) + text += wifi_stack::toString(result->netmask); + return text; +} + +std::string WifiGatewayText::text() const +{ + std::string text = "gateway: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) + if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA); result) + text += wifi_stack::toString(result->gw); + return text; +} + +std::string WifiIpv6LinklocalText::text() const +{ + std::string text = "ipv6: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) + { + esp_ip6_addr_t addr; + if (const auto result = esp_netif_get_ip6_linklocal(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &addr); result == ESP_OK) + text += wifi_stack::toString(addr); + } + return text; +} + +std::string WifiIpv6GlobalText::text() const +{ + std::string text = "ipv6: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) + { + esp_ip6_addr_t addr; + if (const auto result = esp_netif_get_ip6_global(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &addr); result == ESP_OK) + text += wifi_stack::toString(addr); + } + return text; +} + +std::string WifiDns0Text::text() const +{ + std::string text = "dns0: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) + if (const ip_addr_t *dns_ip = dns_getserver(0)) + text += wifi_stack::toString(*dns_ip); + return text; +} + +std::string WifiDns1Text::text() const +{ + std::string text = "dns1: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) + if (const ip_addr_t *dns_ip = dns_getserver(1)) + text += wifi_stack::toString(*dns_ip); + return text; +} + +std::string WifiDns2Text::text() const +{ + std::string text = "dns2: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) + if (const ip_addr_t *dns_ip = dns_getserver(2)) + text += wifi_stack::toString(*dns_ip); + return text; +} diff --git a/main/wifitexthelpers.h b/main/wifitexthelpers.h index 82f592a..c6f2872 100644 --- a/main/wifitexthelpers.h +++ b/main/wifitexthelpers.h @@ -1,233 +1,129 @@ #pragma once -// 3rdparty lib includes -#include -#include -#include -#include - // local includes #include "textinterface.h" -namespace { -class WifiStatusText : public virtual TextInterface { public: std::string text() const override { - return fmt::format("Status: {}", wifi_stack::toString(wifi_stack::get_sta_status())); }}; - -class WifiScanStatusText : public virtual TextInterface { public: std::string text() const override { - return fmt::format("ScanStatus: {}", wifi_stack::toString(wifi_stack::get_scan_status())); }}; - -class WifiHostnameText : public virtual TextInterface { +class WifiStatusText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "Hostname: "; - const char *hostname{}; - if (const auto result = esp_netif_get_hostname(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &hostname); result == ESP_OK) - if (hostname) - text += hostname; - return text; - } + std::string text() const override; }; -class WifiMacText : public virtual TextInterface { +class WifiScanStatusText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "MAC: "; - if (const auto result = wifi_stack::get_base_mac_addr()) - text += wifi_stack::toString(*result); - return text; - } + std::string text() const override; }; -class WifiSsidText : public virtual TextInterface { +class WifiHostnameText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "SSID: "; - if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) - if (const auto &result = wifi_stack::get_sta_ap_info(); result) - text += std::string_view{reinterpret_cast(result->ssid)}; - return text; - } + std::string text() const override; }; -class WifiBssidText : public virtual TextInterface { +class WifiMacText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "BSSID: "; - if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) - if (const auto &result = wifi_stack::get_sta_ap_info(); result) - text += wifi_stack::toString(wifi_stack::mac_t{result->bssid}); - return text; - } + std::string text() const override; }; -class WifiRssiText : public virtual TextInterface { +class WifiSsidText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "RSSI: "; - if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) - if (const auto &result = wifi_stack::get_sta_ap_info(); result) - text += fmt::format("{}dB", result->rssi); - return text; - } + std::string text() const override; }; -class WifiEncryptionTypeText : public virtual TextInterface { +class WifiBssidText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "encryptionType: "; - if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) - if (const auto &result = wifi_stack::get_sta_ap_info(); result) - text += wifi_stack::toString(result->authmode); - return text; - } + std::string text() const override; }; -class WifiPairwiseCipherText : public virtual TextInterface { +class WifiRssiText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "pairwiseCipher: "; - if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) - if (const auto &result = wifi_stack::get_sta_ap_info(); result) - text += wifi_stack::toString(result->pairwise_cipher); - return text; - } + std::string text() const override; }; -class WifiGroupCipherText : public virtual TextInterface { +class WifiEncryptionTypeText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "groupCipher: "; - if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) - if (const auto &result = wifi_stack::get_sta_ap_info(); result) - text += wifi_stack::toString(result->group_cipher); - return text; - } + std::string text() const override; }; -class WifiIpText : public virtual TextInterface { +class WifiPairwiseCipherText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "ip: "; - if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) - if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA); result) - text += wifi_stack::toString(result->ip); - return text; - } + std::string text() const override; }; -class WifiNetmaskText : public virtual TextInterface { +class WifiGroupCipherText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "netmask: "; - if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) - if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA); result) - text += wifi_stack::toString(result->netmask); - return text; - } + std::string text() const override; }; -class WifiGatewayText : public virtual TextInterface { +class WifiIpText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "gateway: "; - if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) - if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA); result) - text += wifi_stack::toString(result->gw); - return text; - } + std::string text() const override; }; -class WifiIpv6LinklocalText : public virtual TextInterface { +class WifiNetmaskText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "ipv6: "; - if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) - { - esp_ip6_addr_t addr; - if (const auto result = esp_netif_get_ip6_linklocal(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &addr); result == ESP_OK) - text += wifi_stack::toString(addr); - } - return text; - } + std::string text() const override; }; -class WifiIpv6GlobalText : public virtual TextInterface { +class WifiGatewayText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "ipv6: "; - if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) - { - esp_ip6_addr_t addr; - if (const auto result = esp_netif_get_ip6_global(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &addr); result == ESP_OK) - text += wifi_stack::toString(addr); - } - return text; - } + std::string text() const override; }; -class WifiDns0Text : public virtual TextInterface { +class WifiIpv6LinklocalText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "dns0: "; - if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) - if (const ip_addr_t *dns_ip = dns_getserver(0)) - text += wifi_stack::toString(*dns_ip); - return text; - } + std::string text() const override; }; -class WifiDns1Text : public virtual TextInterface { +class WifiIpv6GlobalText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "dns1: "; - if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) - if (const ip_addr_t *dns_ip = dns_getserver(1)) - text += wifi_stack::toString(*dns_ip); - return text; - } + std::string text() const override; }; -class WifiDns2Text : public virtual TextInterface { +class WifiDns0Text : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "dns2: "; - if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) - if (const ip_addr_t *dns_ip = dns_getserver(2)) - text += wifi_stack::toString(*dns_ip); - return text; - } + std::string text() const override; +}; + +class WifiDns1Text : public virtual espgui::TextInterface +{ +public: + std::string text() const override; +}; + +class WifiDns2Text : public virtual espgui::TextInterface +{ +public: + std::string text() const override; }; constexpr char TEXT_SOFTAPGETSTATIONNUM[] = "softAPgetStationNum: "; -using WifiSoftApGetStationNumText = StaticText; //StatusTextHelper +using WifiSoftApGetStationNumText = espgui::StaticText; //StatusTextHelper constexpr char TEXT_SOFTAPIP[] = "softAPIP: "; -using WifiSoftApIpText = StaticText; //StatusTextHelper +using WifiSoftApIpText = espgui::StaticText; //StatusTextHelper constexpr char TEXT_SOFTAPBROADCASTIP[] = "softAPBroadcastIP: "; -using WifiSoftApBroadcastIpText = StaticText; //StatusTextHelper +using WifiSoftApBroadcastIpText = espgui::StaticText; //StatusTextHelper constexpr char TEXT_SOFTAPNETWORKID[] = "softAPNetworkID: "; -using WifiSoftApNetworkIdText = StaticText; //StatusTextHelper +using WifiSoftApNetworkIdText = espgui::StaticText; //StatusTextHelper constexpr char TEXT_SOFTAPSUBNETCIDR[] = "softAPSubnetCIDR: "; -using WifiSoftApSubnetCidrText = StaticText; //StatusTextHelper +using WifiSoftApSubnetCidrText = espgui::StaticText; //StatusTextHelper constexpr char TEXT_SOFTAPIPV6[] = "softAPIPv6: "; -using WifiSoftApIpV6Text = StaticText; //StatusTextHelper +using WifiSoftApIpV6Text = espgui::StaticText; //StatusTextHelper constexpr char TEXT_SOFTAPGETHOSTNAME[] = "softAPgetHostname: "; -using WifiSoftApHostnameText = StaticText; //StatusTextHelper +using WifiSoftApHostnameText = espgui::StaticText; //StatusTextHelper constexpr char TEXT_SOFTAPMACADDRESS[] = "softAPmacAddress: "; -using WifiSoftApMacAddressText = StaticText; //StatusTextHelper -} +using WifiSoftApMacAddressText = espgui::StaticText; //StatusTextHelper From 55fe233ee7b6916fa2d8fc2e33351856987d5ce7 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Tue, 2 Nov 2021 14:18:28 +0100 Subject: [PATCH 03/10] Again more refactorings --- main/cloudtexthelpers.cpp | 30 ++++ main/cloudtexthelpers.h | 37 ++--- main/displays/garagedisplay.h | 4 - main/displays/lockscreen.h | 4 - main/displays/menus/bmsmenu.h | 5 - main/displays/menus/cloudsettingsmenu.cpp | 72 +++++++++ main/displays/menus/cloudsettingsmenu.h | 69 +------- main/displays/menus/debugmenu.h | 20 --- .../menus/defaultmodesettingsmenu.cpp | 144 +++++++++++++++++ main/displays/menus/defaultmodesettingsmenu.h | 150 +----------------- main/displays/menus/demosmenu.h | 9 -- .../displays/menus/gametrakmodesettingsmenu.h | 5 - main/displays/menus/graphsmenu.h | 6 - main/displays/menus/larsmmodesettingsmenu.h | 6 - main/displays/menus/modessettingsmenu.cpp | 31 ++++ main/displays/menus/modessettingsmenu.h | 27 +--- main/displays/menus/mosfetsmenu.h | 5 - main/displays/menus/presetsmenu.h | 5 - main/displays/menus/profilesmenu.h | 5 - main/displays/menus/selectmodemenu.h | 5 - .../menus/tempomatmodesettingsmenu.cpp | 48 ++++++ .../displays/menus/tempomatmodesettingsmenu.h | 54 +------ main/displays/menus/timesettingsmenu.cpp | 103 ++++++++++++ main/displays/menus/timesettingsmenu.h | 84 +--------- main/displays/poweroffdisplay.h | 4 - 25 files changed, 474 insertions(+), 458 deletions(-) diff --git a/main/cloudtexthelpers.cpp b/main/cloudtexthelpers.cpp index e69de29..a103caa 100644 --- a/main/cloudtexthelpers.cpp +++ b/main/cloudtexthelpers.cpp @@ -0,0 +1,30 @@ +#include "cloudtexthelpers.h" + +// 3rdparty lib includes +#include + +// local includes +#include "cloud.h" + +#ifdef FEATURE_CLOUD +std::string CloudCreatedText::text() const +{ + return fmt::format("created: {}", cloudClient ? "true" : "false"); +} + +std::string CloudStartedText::text() const +{ + std::string text = "started: "; + if (cloudClient) + text += cloudStarted ? "true" : "false"; + return text; +} + +std::string CloudConnectedText::text() const +{ + std::string text = "connected: "; + if (cloudClient) + text += cloudClient.is_connected() ? "true" : "false"; + return text; +} +#endif diff --git a/main/cloudtexthelpers.h b/main/cloudtexthelpers.h index 3fc6522..ceeb687 100644 --- a/main/cloudtexthelpers.h +++ b/main/cloudtexthelpers.h @@ -1,37 +1,24 @@ #pragma once -// 3rdparty lib includes -#include - // local includes #include "textinterface.h" -#include "cloud.h" -namespace { #ifdef FEATURE_CLOUD -struct CloudCreatedText : public virtual TextInterface { public: std::string text() const override { - return fmt::format("created: {}", cloudClient ? "true" : "false"); }}; - -struct CloudStartedText : public virtual TextInterface { +struct CloudCreatedText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "started: "; - if (cloudClient) - text += cloudStarted ? "true" : "false"; - return text; - } + std::string text() const override; }; -struct CloudConnectedText : public virtual TextInterface { +struct CloudStartedText : public virtual espgui::TextInterface +{ public: - std::string text() const override - { - std::string text = "connected: "; - if (cloudClient) - text += cloudClient.is_connected() ? "true" : "false"; - return text; - } + std::string text() const override; +}; + +struct CloudConnectedText : public virtual espgui::TextInterface +{ +public: + std::string text() const override; }; #endif -} diff --git a/main/displays/garagedisplay.h b/main/displays/garagedisplay.h index c447627..2b53af2 100644 --- a/main/displays/garagedisplay.h +++ b/main/displays/garagedisplay.h @@ -15,10 +15,6 @@ #include "texts.h" #include "widgets/label.h" -namespace { -class MainMenu; -} - namespace { #ifdef FEATURE_GARAGE class GarageDisplay : public Display, public BackActionInterface> diff --git a/main/displays/lockscreen.h b/main/displays/lockscreen.h index 05a3cb8..934f36f 100644 --- a/main/displays/lockscreen.h +++ b/main/displays/lockscreen.h @@ -16,10 +16,6 @@ #include "ledstrip.h" #endif -namespace { -class MainMenu; -} - namespace { class Lockscreen : public Display, public DummyBack { diff --git a/main/displays/menus/bmsmenu.h b/main/displays/menus/bmsmenu.h index e4905cb..7fe4ab5 100644 --- a/main/displays/menus/bmsmenu.h +++ b/main/displays/menus/bmsmenu.h @@ -18,11 +18,6 @@ #include "icons/back.h" #include "texts.h" -//forward declares -namespace { -class MainMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/cloudsettingsmenu.cpp b/main/displays/menus/cloudsettingsmenu.cpp index e69de29..ec4dd36 100644 --- a/main/displays/menus/cloudsettingsmenu.cpp +++ b/main/displays/menus/cloudsettingsmenu.cpp @@ -0,0 +1,72 @@ +#include "cloudsettingsmenu.h" + +// 3rdparty lib includes +#include +#include "menuitem.h" +#include "changevaluedisplay.h" +#include "actions/switchscreenaction.h" +#include "actions/toggleboolaction.h" +#include "actions/dummyaction.h" +#include "checkboxicon.h" +#include "icons/back.h" + +// local includes +#include "cloudtexthelpers.h" +#include "accessors/settingsaccessors.h" +#include "cloud.h" +#include "displays/menus/settingsmenu.h" + +namespace { +using CloudTransmitTimeoutChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + CloudTransmitTimeoutAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +struct CloudBufferLengthText : public virtual espgui::TextInterface +{ +public: + std::string text() const override + { + return fmt::format("buffer: {}", cloudBuffer.size()); + } +}; + +using CloudCollectRateChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + CloudCollectRateAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +using CloudSendRateChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + CloudSendRateAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +} // namespace + +using namespace espgui; + +CloudSettingsMenu::CloudSettingsMenu() +{ + constructMenuItem, ToggleBoolAction, CheckboxIcon, CloudEnabledAccessor>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem>(); + constructMenuItem>(); + constructMenuItem>(); + constructMenuItem>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void CloudSettingsMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/cloudsettingsmenu.h b/main/displays/menus/cloudsettingsmenu.h index 42b8ad8..037beaf 100644 --- a/main/displays/menus/cloudsettingsmenu.h +++ b/main/displays/menus/cloudsettingsmenu.h @@ -1,76 +1,19 @@ #pragma once // 3rdparty lib includes -#include +#include "menudisplay.h" // local includes -#include "menudisplay.h" -#include "menuitem.h" -#include "changevaluedisplay.h" -#include "actions/switchscreenaction.h" -#include "actions/toggleboolaction.h" -#include "checkboxicon.h" -#include "cloudtexthelpers.h" -#include "accessors/settingsaccessors.h" -#include "icons/back.h" #include "texts.h" -#include "accessors/settingsaccessors.h" -#include "cloud.h" -namespace { -using CloudTransmitTimeoutChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - CloudTransmitTimeoutAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -struct CloudBufferLengthText : public virtual TextInterface { -public: - std::string text() const override - { - return fmt::format("buffer: {}", cloudBuffer.size()); - } -}; - -using CloudCollectRateChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - CloudCollectRateAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -using CloudSendRateChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - CloudSendRateAccessor, - BackActionInterface>, - SwitchScreenAction ->; -} // namespace - -namespace { #ifdef FEATURE_CLOUD class CloudSettingsMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - CloudSettingsMenu() - { - constructMenuItem, ToggleBoolAction, CheckboxIcon, CloudEnabledAccessor>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem>(); - constructMenuItem>(); - constructMenuItem>(); - constructMenuItem>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + CloudSettingsMenu(); + + void back() override; }; #endif -} // namespace diff --git a/main/displays/menus/debugmenu.h b/main/displays/menus/debugmenu.h index 6a079fe..2ae7392 100644 --- a/main/displays/menus/debugmenu.h +++ b/main/displays/menus/debugmenu.h @@ -18,26 +18,6 @@ using namespace espgui; -// forward declares -namespace { -class MainMenu; -class FrontCommandDebugMenu; -class BackCommandDebugMenu; -class FrontLeftMotorStateDebugMenu; -class FrontRightMotorStateDebugMenu; -class BackLeftMotorStateDebugMenu; -class BackRightMotorStateDebugMenu; -class FrontFeedbackDebugMenu; -class BackFeedbackDebugMenu; -class FrontLeftMotorFeedbackDebugMenu; -class FrontRightMotorFeedbackDebugMenu; -class BackLeftMotorFeedbackDebugMenu; -class BackRightMotorFeedbackDebugMenu; -class DynamicDebugMenu; -} // namespace - -using namespace espgui; - namespace { class DebugMenu : public MenuDisplay, diff --git a/main/displays/menus/defaultmodesettingsmenu.cpp b/main/displays/menus/defaultmodesettingsmenu.cpp index e69de29..532b3ea 100644 --- a/main/displays/menus/defaultmodesettingsmenu.cpp +++ b/main/displays/menus/defaultmodesettingsmenu.cpp @@ -0,0 +1,144 @@ +#include "defaultmodesettingsmenu.h" + +// 3rdparty lib includes +#include "changevaluedisplay.h" +#include "menuitem.h" +#include "actions/toggleboolaction.h" +#include "actions/switchscreenaction.h" +#include "actions/dummyaction.h" +#include "checkboxicon.h" +#include "icons/back.h" + +// local includes +#include "utils.h" +#include "changevaluedisplay_unifiedmodelmode.h" +#include "accessors/settingsaccessors.h" +#include "displays/menus/modessettingsmenu.h" + +namespace { +using DefaultModeModelModeChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + DefaultModeModelModeAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using DefaultModeHybridModelModeChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + DefaultModeHybridModelModeAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using DefaultModeSmoothingChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + DefaultModeSmoothingAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using DefaultModeFwSmoothingLowerLimitChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + DefaultModeEnableFieldWeakSmoothingLowerLimitAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using DefaultModeFrontPercentageChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + DefaultModeFrontPercentageAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using DefaultModeBackPercentageChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + DefaultModeBackPercentageAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using DefaultModeAddSchwelleChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + DefaultModeAddSchwelleAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using DefaultModeGas1WertChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + DefaultModeGas1WertAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using DefaultModeGas2WertChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + DefaultModeGas2WertAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using DefaultModeBrems1WertChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + DefaultModeBrems1WertAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using DefaultModeBrems2WertChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + DefaultModeBrems2WertAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using DefaultModeHybridActivationLimitChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + DefaultModeHybridActivationLimitAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using DefaultModeHybridDeactivationLimitChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + DefaultModeHybridDeactivationLimitAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +} // namespace + +using namespace espgui; + +DefaultModeSettingsMenu::DefaultModeSettingsMenu() +{ + auto diff = std::abs(settings.hybrid.activationLimit - settings.hybrid.deactivationLimit); + if (diff < 20) { constructMenuItem, StaticFont<2>, StaticColor, DummyAction>>(); } + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, DefaultModeSquareGasAccessor>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, DefaultModeSquareBremsAccessor>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, DefaultModeEnableSmoothingUpAccessor>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, DefaultModeEnableSmoothingDownAccessor>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, DefaultModeEnableFieldWeakSmoothingUpAccessor>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, DefaultModeEnableFieldWeakSmoothingDownAccessor>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, DefaultModeEnableHybridAccessor>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void DefaultModeSettingsMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/defaultmodesettingsmenu.h b/main/displays/menus/defaultmodesettingsmenu.h index 13a6c4a..895f7a6 100644 --- a/main/displays/menus/defaultmodesettingsmenu.h +++ b/main/displays/menus/defaultmodesettingsmenu.h @@ -1,153 +1,17 @@ #pragma once -#include +// 3rdparty lib includes +#include "menudisplay.h" // local includes -#include "menudisplay.h" -#include "utils.h" -#include "changevaluedisplay.h" -#include "changevaluedisplay_unifiedmodelmode.h" -#include "menuitem.h" -#include "actions/toggleboolaction.h" -#include "actions/switchscreenaction.h" -#include "actions/dummyaction.h" -#include "checkboxicon.h" -#include "icons/back.h" #include "texts.h" -#include "accessors/settingsaccessors.h" - -// forward declares -namespace { -class DefaultModeSettingsMenu; -class ModesSettingsMenu; -} // namespace - -using namespace espgui; - -namespace { -using DefaultModeModelModeChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - DefaultModeModelModeAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using DefaultModeHybridModelModeChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - DefaultModeHybridModelModeAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using DefaultModeSmoothingChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - DefaultModeSmoothingAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using DefaultModeFwSmoothingLowerLimitChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - DefaultModeEnableFieldWeakSmoothingLowerLimitAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using DefaultModeFrontPercentageChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - DefaultModeFrontPercentageAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using DefaultModeBackPercentageChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - DefaultModeBackPercentageAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using DefaultModeAddSchwelleChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - DefaultModeAddSchwelleAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using DefaultModeGas1WertChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - DefaultModeGas1WertAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using DefaultModeGas2WertChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - DefaultModeGas2WertAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using DefaultModeBrems1WertChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - DefaultModeBrems1WertAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using DefaultModeBrems2WertChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - DefaultModeBrems2WertAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using DefaultModeHybridActivationLimitChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - DefaultModeHybridActivationLimitAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using DefaultModeHybridDeactivationLimitChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - DefaultModeHybridDeactivationLimitAccessor, - BackActionInterface>, - SwitchScreenAction ->; class DefaultModeSettingsMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - DefaultModeSettingsMenu() - { - auto diff = std::abs(settings.hybrid.activationLimit - settings.hybrid.deactivationLimit); - if (diff < 20) { constructMenuItem, StaticFont<2>, StaticColor, DummyAction>>(); } - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, DefaultModeSquareGasAccessor>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, DefaultModeSquareBremsAccessor>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, DefaultModeEnableSmoothingUpAccessor>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, DefaultModeEnableSmoothingDownAccessor>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, DefaultModeEnableFieldWeakSmoothingUpAccessor>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, DefaultModeEnableFieldWeakSmoothingDownAccessor>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, DefaultModeEnableHybridAccessor>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + DefaultModeSettingsMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/menus/demosmenu.h b/main/displays/menus/demosmenu.h index ad5dc88..ec8588d 100644 --- a/main/displays/menus/demosmenu.h +++ b/main/displays/menus/demosmenu.h @@ -8,15 +8,6 @@ #include "icons/back.h" #include "texts.h" -// forward declares -namespace { -class StarfieldDisplay; -class PingPongDisplay; -class SpiroDisplay; -class GameOfLifeDisplay; -class MainMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/gametrakmodesettingsmenu.h b/main/displays/menus/gametrakmodesettingsmenu.h index 6a5a869..74e6719 100644 --- a/main/displays/menus/gametrakmodesettingsmenu.h +++ b/main/displays/menus/gametrakmodesettingsmenu.h @@ -8,11 +8,6 @@ #include "icons/back.h" #include "texts.h" -// forward declares -namespace { -class ModesSettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/graphsmenu.h b/main/displays/menus/graphsmenu.h index a32dc3d..d594b36 100644 --- a/main/displays/menus/graphsmenu.h +++ b/main/displays/menus/graphsmenu.h @@ -10,12 +10,6 @@ #include "displays/splitgraphdisplay.h" #include "statistics.h" -// forward declares -namespace { -class MainMenu; -class GraphsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/larsmmodesettingsmenu.h b/main/displays/menus/larsmmodesettingsmenu.h index a1d4203..73ac84e 100644 --- a/main/displays/menus/larsmmodesettingsmenu.h +++ b/main/displays/menus/larsmmodesettingsmenu.h @@ -12,12 +12,6 @@ #include "texts.h" #include "accessors/settingsaccessors.h" -// forward declares -namespace { -class LarsmModeSettingsMenu; -class ModesSettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/modessettingsmenu.cpp b/main/displays/menus/modessettingsmenu.cpp index e69de29..4460ffb 100644 --- a/main/displays/menus/modessettingsmenu.cpp +++ b/main/displays/menus/modessettingsmenu.cpp @@ -0,0 +1,31 @@ +#include "modessettingsmenu.h" + +// 3rdparty lib includes +#include "menuitem.h" +#include "actions/switchscreenaction.h" +#include "icons/back.h" + +// local includes +#include "displays/menus/defaultmodesettingsmenu.h" +#include "displays/menus/tempomatmodesettingsmenu.h" +#include "displays/menus/larsmmodesettingsmenu.h" +#include "displays/menus/gametrakmodesettingsmenu.h" +#include "displays/menus/settingsmenu.h" + +using namespace espgui; + +ModesSettingsMenu::ModesSettingsMenu() +{ + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); +#ifdef FEATURE_GAMETRAK + constructMenuItem, SwitchScreenAction>>(); +#endif + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void ModesSettingsMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/modessettingsmenu.h b/main/displays/menus/modessettingsmenu.h index 5394071..ae07c74 100644 --- a/main/displays/menus/modessettingsmenu.h +++ b/main/displays/menus/modessettingsmenu.h @@ -2,29 +2,16 @@ // local includes #include "menudisplay.h" -#include "menuitem.h" -#include "actions/switchscreenaction.h" -#include "icons/back.h" + +// local includes #include "texts.h" -using namespace espgui; - -namespace { class ModesSettingsMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - ModesSettingsMenu() - { - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); -#ifdef FEATURE_GAMETRAK - constructMenuItem, SwitchScreenAction>>(); -#endif - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + ModesSettingsMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/menus/mosfetsmenu.h b/main/displays/menus/mosfetsmenu.h index 2036100..92e7587 100644 --- a/main/displays/menus/mosfetsmenu.h +++ b/main/displays/menus/mosfetsmenu.h @@ -11,11 +11,6 @@ #include "texts.h" #include "types.h" -// forward declares -namespace { -class MainMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/presetsmenu.h b/main/displays/menus/presetsmenu.h index 85d2b88..3313135 100644 --- a/main/displays/menus/presetsmenu.h +++ b/main/displays/menus/presetsmenu.h @@ -12,11 +12,6 @@ #include "presets.h" #include "globals.h" -// forward declares -namespace { -class MainMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/profilesmenu.h b/main/displays/menus/profilesmenu.h index 9061ba5..4e184d9 100644 --- a/main/displays/menus/profilesmenu.h +++ b/main/displays/menus/profilesmenu.h @@ -7,11 +7,6 @@ #include "icons/back.h" #include "texts.h" -// forward declares -namespace { -class MainMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/selectmodemenu.h b/main/displays/menus/selectmodemenu.h index 800eb53..1709c53 100644 --- a/main/displays/menus/selectmodemenu.h +++ b/main/displays/menus/selectmodemenu.h @@ -15,11 +15,6 @@ #include "modes/remotecontrolmode.h" #include "modes/gametrakmode.h" -// forward declares -namespace { -class MainMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/tempomatmodesettingsmenu.cpp b/main/displays/menus/tempomatmodesettingsmenu.cpp index e69de29..d94e4a6 100644 --- a/main/displays/menus/tempomatmodesettingsmenu.cpp +++ b/main/displays/menus/tempomatmodesettingsmenu.cpp @@ -0,0 +1,48 @@ +#include "tempomatmodesettingsmenu.h" + +// 3rdparty lib includes +#include "changevaluedisplay.h" +#include "menuitem.h" +#include "actions/switchscreenaction.h" +#include "icons/back.h" + +// local includes +#include "utils.h" +#include "changevaluedisplay_unifiedmodelmode.h" +#include "accessors/settingsaccessors.h" +#include "accessors/globalaccessors.h" +#include "actions/tempomatmodeapplycurrentpeedaction.h" +#include "displays/menus/modessettingsmenu.h" + +namespace { +using TempomatModeCruiseMotTgtChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + TempomatModeCruiseMotTgtAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +using TempomatModeModelModeChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + TempomatModeModelModeAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +} // namespace + +using namespace espgui; + +TempomatModeSettingsMenu::TempomatModeSettingsMenu() +{ + constructMenuItem, TempomatModeApplyCurrentSpeedAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void TempomatModeSettingsMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/tempomatmodesettingsmenu.h b/main/displays/menus/tempomatmodesettingsmenu.h index 2e5ce97..e10cdaa 100644 --- a/main/displays/menus/tempomatmodesettingsmenu.h +++ b/main/displays/menus/tempomatmodesettingsmenu.h @@ -1,55 +1,17 @@ #pragma once -// local includes +// 3rdparty lib includes #include "menudisplay.h" -#include "utils.h" -#include "changevaluedisplay.h" -#include "changevaluedisplay_unifiedmodelmode.h" -#include "menuitem.h" -#include "actions/switchscreenaction.h" -#include "icons/back.h" + +// local includes #include "texts.h" -#include "accessors/settingsaccessors.h" -#include "accessors/globalaccessors.h" -#include "actions/tempomatmodeapplycurrentpeedaction.h" - -// forward declares -namespace { -class TempomatModeSettingsMenu; -class ModesSettingsMenu; -} // namespace - -using namespace espgui; - -namespace { -using DefaultModeCruiseMotTgtChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - TempomatModeCruiseMotTgtAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -using TempomatModeModelModeChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - TempomatModeModelModeAccessor, - BackActionInterface>, - SwitchScreenAction ->; class TempomatModeSettingsMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - TempomatModeSettingsMenu() - { - constructMenuItem, TempomatModeApplyCurrentSpeedAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + TempomatModeSettingsMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/menus/timesettingsmenu.cpp b/main/displays/menus/timesettingsmenu.cpp index e69de29..cdeddc2 100644 --- a/main/displays/menus/timesettingsmenu.cpp +++ b/main/displays/menus/timesettingsmenu.cpp @@ -0,0 +1,103 @@ +#include "timesettingsmenu.h" + +// 3rdparty lib includes +#include +#include +#include "changevaluedisplay.h" +#include "changevaluedisplay_daylightsavingmode.h" +#include "changevaluedisplay_sntp_sync_mode_t.h" +#include "actions/toggleboolaction.h" +#include "actions/switchscreenaction.h" +#include "actions/dummyaction.h" +#include "checkboxicon.h" +#include "icons/back.h" +#include "espstrutils.h" + +// local includes +#include "utils.h" +#include "accessors/settingsaccessors.h" +#include "displays/menus/settingsmenu.h" + +class CurrentUtcDateTimeText : public virtual espgui::TextInterface +{ +public: + std::string text() const override + { + return fmt::format("utc: {}", espchrono::toString(espchrono::toDateTime(espchrono::utc_clock::now()))); + } +}; + +class CurrentLocalDateTimeText : public virtual espgui::TextInterface +{ +public: + std::string text() const override + { + return fmt::format("local: {}", espchrono::toString(espchrono::toDateTime(espchrono::local_clock::now()))); + } +}; + +using TimezoneOffsetChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + TimezoneOffsetAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +using DaylightSavingModeChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + DaylightSavingModeAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +#ifdef FEATURE_NTP +using TimeSyncModeChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + TimeSyncModeAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +using TimeSyncIntervalChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + TimeSyncIntervalAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +class NtpSyncStatusText : public virtual espgui::TextInterface +{ +public: + std::string text() const override + { + return fmt::format("Status: {}", espcpputils::toString(sntp_get_sync_status())); + } +}; +#endif + +using namespace espgui; + +TimeSettingsMenu::TimeSettingsMenu() +{ + constructMenuItem, DummyAction>>(); + constructMenuItem, DummyAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); +#ifdef FEATURE_NTP + constructMenuItem, ToggleBoolAction, CheckboxIcon, TimeServerEnabledAccessor>>(); + constructMenuItem, DummyAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem>(); +#endif + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void TimeSettingsMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/timesettingsmenu.h b/main/displays/menus/timesettingsmenu.h index 53c6e7e..b8b238c 100644 --- a/main/displays/menus/timesettingsmenu.h +++ b/main/displays/menus/timesettingsmenu.h @@ -1,89 +1,17 @@ #pragma once // 3rdparty lib includes -#include -#include +#include "menudisplay.h" // local includes -#include "changevaluedisplay.h" -#include "changevaluedisplay_daylightsavingmode.h" -#include "changevaluedisplay_sntp_sync_mode_t.h" -#include "menudisplay.h" -#include "utils.h" -#include "actions/toggleboolaction.h" -#include "actions/switchscreenaction.h" -#include "checkboxicon.h" -#include "icons/back.h" #include "texts.h" -#include "accessors/settingsaccessors.h" -#include "espstrutils.h" - -using namespace espgui; - -namespace { -class CurrentUtcDateTimeText : public virtual TextInterface { public: - std::string text() const override { return fmt::format("utc: {}", espchrono::toString(espchrono::toDateTime(espchrono::utc_clock::now()))); }}; - -class CurrentLocalDateTimeText : public virtual TextInterface { public: - std::string text() const override { return fmt::format("local: {}", espchrono::toString(espchrono::toDateTime(espchrono::local_clock::now()))); }}; - -using TimezoneOffsetChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - TimezoneOffsetAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -using DaylightSavingModeChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - DaylightSavingModeAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -#ifdef FEATURE_NTP -using TimeSyncModeChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - TimeSyncModeAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -using TimeSyncIntervalChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - TimeSyncIntervalAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -class NtpSyncStatusText : public virtual TextInterface { public: - std::string text() const override { return fmt::format("Status: {}", espcpputils::toString(sntp_get_sync_status())); }}; -#endif class TimeSettingsMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - TimeSettingsMenu() - { - constructMenuItem, DummyAction>>(); - constructMenuItem, DummyAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); -#ifdef FEATURE_NTP - constructMenuItem, ToggleBoolAction, CheckboxIcon, TimeServerEnabledAccessor>>(); - constructMenuItem, DummyAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem>(); -#endif - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + TimeSettingsMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/poweroffdisplay.h b/main/displays/poweroffdisplay.h index 97acc22..6735450 100644 --- a/main/displays/poweroffdisplay.h +++ b/main/displays/poweroffdisplay.h @@ -9,10 +9,6 @@ #include "globals.h" #include "texts.h" -namespace { -class MainMenu; -} - namespace { class PoweroffDisplay : public Display, public DummyConfirm, public DummyBack { From 8dcc898244697fad8af4eb04d877bd3f68c20077 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Tue, 2 Nov 2021 16:11:57 +0100 Subject: [PATCH 04/10] Even more refactorings --- components/esp-gui-lib | 2 +- main/CMakeLists.txt | 4 - main/displays/gameoflifedisplay.h | 4 - main/displays/graphdisplay.cpp | 0 main/displays/graphdisplay.h | 77 -------- main/displays/menus/buzzermenu.cpp | 103 ++++++++++ main/displays/menus/buzzermenu.h | 103 +--------- .../menus/controllerhardwaresettingsmenu.cpp | 84 ++++++++ .../menus/controllerhardwaresettingsmenu.h | 79 +------- main/displays/menus/demosmenu.cpp | 30 +++ main/displays/menus/demosmenu.h | 28 +-- main/displays/menus/enablemenu.h | 5 - main/displays/menus/graphsmenu.cpp | 183 ++++++++++++++++++ main/displays/menus/graphsmenu.h | 178 +---------------- main/displays/menus/invertmenu.h | 5 - main/displays/menus/larsmmodesettingsmenu.cpp | 53 +++++ main/displays/menus/larsmmodesettingsmenu.h | 51 +---- main/displays/menus/selectmodemenu.cpp | 67 +++++++ main/displays/menus/selectmodemenu.h | 70 +------ main/displays/pingpongdisplay.h | 4 - main/displays/spirodisplay.h | 4 - main/displays/splitgraphdisplay.cpp | 0 main/displays/splitgraphdisplay.h | 85 -------- main/displays/starfielddisplay.cpp | 84 ++++++++ main/displays/starfielddisplay.h | 92 +-------- main/statistics.h | 2 +- 26 files changed, 653 insertions(+), 744 deletions(-) delete mode 100644 main/displays/graphdisplay.cpp delete mode 100644 main/displays/graphdisplay.h delete mode 100644 main/displays/splitgraphdisplay.cpp delete mode 100644 main/displays/splitgraphdisplay.h diff --git a/components/esp-gui-lib b/components/esp-gui-lib index aad3fce..db06696 160000 --- a/components/esp-gui-lib +++ b/components/esp-gui-lib @@ -1 +1 @@ -Subproject commit aad3fcedcbe6bbc591021c79ba92d332f09bcc7f +Subproject commit db066968d2eda57a3aea3cf44f3718a6bda0c371 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 2578d9d..8bba364 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -93,7 +93,6 @@ set(headers displays/gameoflifedisplay.h displays/gametrakcalibratedisplay.h displays/garagedisplay.h - displays/graphdisplay.h displays/ledstripcolorsdisplay.h displays/lockscreen.h displays/menus/aboutmenu.h @@ -148,7 +147,6 @@ set(headers displays/poweroffdisplay.h displays/powersupplydisplay.h displays/spirodisplay.h - displays/splitgraphdisplay.h displays/starfielddisplay.h displays/statusdisplay.h displays/updatedisplay.h @@ -278,7 +276,6 @@ set(sources displays/gameoflifedisplay.cpp displays/gametrakcalibratedisplay.cpp displays/garagedisplay.cpp - displays/graphdisplay.cpp displays/ledstripcolorsdisplay.cpp displays/lockscreen.cpp displays/menus/aboutmenu.cpp @@ -331,7 +328,6 @@ set(sources displays/poweroffdisplay.cpp displays/powersupplydisplay.cpp displays/spirodisplay.cpp - displays/splitgraphdisplay.cpp displays/starfielddisplay.cpp displays/statusdisplay.cpp displays/updatedisplay.cpp diff --git a/main/displays/gameoflifedisplay.h b/main/displays/gameoflifedisplay.h index 51d22c6..62b0be4 100644 --- a/main/displays/gameoflifedisplay.h +++ b/main/displays/gameoflifedisplay.h @@ -12,10 +12,6 @@ #include "display.h" #include "actions/switchscreenaction.h" -namespace { -class DemosMenu; -} - namespace { class GameOfLifeDisplay : public Display, public ConfirmActionInterface>, public BackActionInterface> { diff --git a/main/displays/graphdisplay.cpp b/main/displays/graphdisplay.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/main/displays/graphdisplay.h b/main/displays/graphdisplay.h deleted file mode 100644 index c5ee2db..0000000 --- a/main/displays/graphdisplay.h +++ /dev/null @@ -1,77 +0,0 @@ -#pragma once - -#include "display.h" -#include "textinterface.h" -#include "widgets/label.h" -#include "widgets/graph.h" -#include "globals.h" -#include "statistics.h" - -namespace { -template -class GraphAccessorInterface -{ -public: - virtual std::array, COUNT> getBuffers() const = 0; -}; - -template -class SingleGraphAccessor : public virtual GraphAccessorInterface<1> -{ -public: - Graph<200, 1>::Container getBuffers() const - { - return {T{}.getBuffer()}; - } -}; - -template -class DualGraphAccessor : public virtual GraphAccessorInterface<2> -{ -public: - Graph<200, 2>::Container getBuffers() const - { - return {T1{}.getBuffer(), T2{}.getBuffer()}; - } -}; - -template -class GraphDisplay : - public Display, - public virtual TextInterface, - public virtual GraphAccessorInterface -{ -public: - void initScreen() override; - void redraw() override; - -private: - static constexpr int screenHeight = 320, topMargin = 40, bottomMargin = 10, labelOffset = -5; - static constexpr int graphHeight = screenHeight-topMargin-bottomMargin; - - Label m_titleLabel{5, 5}; // 230, 25 - - Graph<200, COUNT> m_graph{0, 40, 270}; -}; - -template -void GraphDisplay::initScreen() -{ - tft.fillScreen(TFT_BLACK); - - m_titleLabel.start(); - tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE); - - m_graph.start(static_cast &>(*this).getBuffers()); -} - -template -void GraphDisplay::redraw() -{ - tft.setTextFont(4); - tft.setTextColor(TFT_YELLOW, TFT_BLACK); - m_titleLabel.redraw(text()); - - m_graph.redraw(static_cast &>(*this).getBuffers()); -} -} diff --git a/main/displays/menus/buzzermenu.cpp b/main/displays/menus/buzzermenu.cpp index e69de29..b050698 100644 --- a/main/displays/menus/buzzermenu.cpp +++ b/main/displays/menus/buzzermenu.cpp @@ -0,0 +1,103 @@ +#include "buzzermenu.h" + +// 3rdparty lib includes +#include "changevaluedisplay.h" +#include "menuitem.h" +#include "actions/switchscreenaction.h" +#include "actions/toggleboolaction.h" +#include "checkboxicon.h" +#include "icons/back.h" + +// local includes +#include "utils.h" +#include "globals.h" +#include "accessors/settingsaccessors.h" +#include "displays/menus/settingsmenu.h" + +namespace { +struct FrontFreqAccessor : public espgui::RefAccessor { uint8_t &getRef() const override { return controllers.front.command.buzzer.freq; } }; +using FrontFreqChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + FrontFreqAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +struct FrontPatternAccessor : public espgui::RefAccessor { uint8_t &getRef() const override { return controllers.front.command.buzzer.pattern; } }; +using FrontPatternChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + FrontPatternAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +struct BackFreqAccessor : public espgui::RefAccessor { uint8_t &getRef() const override { return controllers.back.command.buzzer.freq; } }; +using BackFreqChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + BackFreqAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +struct BackPatternAccessor : public espgui::RefAccessor { uint8_t &getRef() const override { return controllers.back.command.buzzer.pattern; } }; +using BackPatternChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + BackPatternAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; + +using ReverseBeepFreq0ChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + ReverseBeepFreq0Accessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using ReverseBeepFreq1ChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + ReverseBeepFreq1Accessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using ReverseBeepDuration0ChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + ReverseBeepDuration0Accessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using ReverseBeepDuration1ChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + ReverseBeepDuration1Accessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +} // namespace + +using namespace espgui; + +BuzzerMenu::BuzzerMenu() +{ + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, ReverseBeepAccessor>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void BuzzerMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/buzzermenu.h b/main/displays/menus/buzzermenu.h index c3505d6..6d4cf9a 100644 --- a/main/displays/menus/buzzermenu.h +++ b/main/displays/menus/buzzermenu.h @@ -1,104 +1,17 @@ #pragma once -// local includes +// 3rdparty lib includes #include "menudisplay.h" -#include "utils.h" -#include "changevaluedisplay.h" -#include "menuitem.h" -#include "actions/switchscreenaction.h" -#include "actions/toggleboolaction.h" -#include "checkboxicon.h" -#include "icons/back.h" + +// local includes #include "texts.h" -#include "globals.h" -#include "accessors/settingsaccessors.h" - -using namespace espgui; - -namespace { -struct FrontFreqAccessor : public RefAccessor { uint8_t &getRef() const override { return controllers.front.command.buzzer.freq; } }; -using FrontFreqChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - FrontFreqAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -struct FrontPatternAccessor : public RefAccessor { uint8_t &getRef() const override { return controllers.front.command.buzzer.pattern; } }; -using FrontPatternChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - FrontPatternAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -struct BackFreqAccessor : public RefAccessor { uint8_t &getRef() const override { return controllers.back.command.buzzer.freq; } }; -using BackFreqChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - BackFreqAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -struct BackPatternAccessor : public RefAccessor { uint8_t &getRef() const override { return controllers.back.command.buzzer.pattern; } }; -using BackPatternChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - BackPatternAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -using ReverseBeepFreq0ChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - ReverseBeepFreq0Accessor, - BackActionInterface>, - SwitchScreenAction ->; -using ReverseBeepFreq1ChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - ReverseBeepFreq1Accessor, - BackActionInterface>, - SwitchScreenAction ->; -using ReverseBeepDuration0ChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - ReverseBeepDuration0Accessor, - BackActionInterface>, - SwitchScreenAction ->; -using ReverseBeepDuration1ChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - ReverseBeepDuration1Accessor, - BackActionInterface>, - SwitchScreenAction ->; class BuzzerMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - BuzzerMenu() - { - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, ReverseBeepAccessor>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + BuzzerMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/menus/controllerhardwaresettingsmenu.cpp b/main/displays/menus/controllerhardwaresettingsmenu.cpp index e69de29..752f6d9 100644 --- a/main/displays/menus/controllerhardwaresettingsmenu.cpp +++ b/main/displays/menus/controllerhardwaresettingsmenu.cpp @@ -0,0 +1,84 @@ +#include "controllerhardwaresettingsmenu.h" + +// system includes +#include + +// 3rdparty lib includes +#include "changevaluedisplay.h" +#include "actions/toggleboolaction.h" +#include "actions/switchscreenaction.h" +#include "checkboxicon.h" +#include "icons/back.h" + +// local includes +#include "utils.h" +#include "globals.h" +#include "accessors/settingsaccessors.h" +#include "displays/menus/enablemenu.h" +#include "displays/menus/invertmenu.h" +#include "displays/menus/settingsmenu.h" + +namespace { +using WheelDiameterMmChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + WheelDiameterMmAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using WheelDiameterInchChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + WheelDiameterInchAccessor, + espgui::RatioNumberStep>, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using NumMagnetPolesChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + NumMagnetPolesAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +#ifdef FEATURE_CAN +using CanTransmitTimeoutChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + CanTransmitTimeoutAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using CanReceiveTimeoutChangeScreen = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + CanReceiveTimeoutAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +#endif +} // namespace + +using namespace espgui; + +ControllerHardwareSettingsMenu::ControllerHardwareSettingsMenu() +{ + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, SwapFrontBackAccessor>>(); +#ifdef FEATURE_CAN + constructMenuItem, ToggleBoolAction, CheckboxIcon, SendFrontCanCmdAccessor>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, SendBackCanCmdAccessor>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); +#endif + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void ControllerHardwareSettingsMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/controllerhardwaresettingsmenu.h b/main/displays/menus/controllerhardwaresettingsmenu.h index cff93df..7ffea17 100644 --- a/main/displays/menus/controllerhardwaresettingsmenu.h +++ b/main/displays/menus/controllerhardwaresettingsmenu.h @@ -1,82 +1,17 @@ #pragma once -#include +// 3rdparty lib includes +#include "menudisplay.h" // local includes -#include "menudisplay.h" -#include "utils.h" -#include "changevaluedisplay.h" -#include "actions/toggleboolaction.h" -#include "actions/switchscreenaction.h" -#include "checkboxicon.h" -#include "icons/back.h" #include "texts.h" -#include "globals.h" -#include "accessors/settingsaccessors.h" - -using namespace espgui; - -namespace { -using WheelDiameterMmChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - WheelDiameterMmAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using WheelDiameterInchChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - WheelDiameterInchAccessor, - RatioNumberStep>, - BackActionInterface>, - SwitchScreenAction ->; -using NumMagnetPolesChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - NumMagnetPolesAccessor, - BackActionInterface>, - SwitchScreenAction ->; -#ifdef FEATURE_CAN -using CanTransmitTimeoutChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - CanTransmitTimeoutAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using CanReceiveTimeoutChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - CanReceiveTimeoutAccessor, - BackActionInterface>, - SwitchScreenAction ->; -#endif class ControllerHardwareSettingsMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - ControllerHardwareSettingsMenu() - { - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, SwapFrontBackAccessor>>(); -#ifdef FEATURE_CAN - constructMenuItem, ToggleBoolAction, CheckboxIcon, SendFrontCanCmdAccessor>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, SendBackCanCmdAccessor>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); -#endif - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + ControllerHardwareSettingsMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/menus/demosmenu.cpp b/main/displays/menus/demosmenu.cpp index e69de29..6d7c910 100644 --- a/main/displays/menus/demosmenu.cpp +++ b/main/displays/menus/demosmenu.cpp @@ -0,0 +1,30 @@ +#include "demosmenu.h" + +// 3rdparty lib includes +#include "menuitem.h" +#include "actions/switchscreenaction.h" +#include "icons/back.h" +#include "displays/starfielddisplay.h" +#include "displays/pingpongdisplay.h" +#include "displays/spirodisplay.h" +#include "displays/gameoflifedisplay.h" +#include "displays/menus/mainmenu.h" + +// local includes +#include "utils.h" + +using namespace espgui; + +DemosMenu::DemosMenu() +{ + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void DemosMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/demosmenu.h b/main/displays/menus/demosmenu.h index ec8588d..0feb869 100644 --- a/main/displays/menus/demosmenu.h +++ b/main/displays/menus/demosmenu.h @@ -1,29 +1,17 @@ #pragma once -// local includes +// 3rdparty lib includes #include "menudisplay.h" -#include "utils.h" -#include "menuitem.h" -#include "actions/switchscreenaction.h" -#include "icons/back.h" + +// local includes #include "texts.h" -using namespace espgui; - -namespace { class DemosMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - DemosMenu() - { - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + DemosMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/menus/enablemenu.h b/main/displays/menus/enablemenu.h index 2b38107..d14c9ff 100644 --- a/main/displays/menus/enablemenu.h +++ b/main/displays/menus/enablemenu.h @@ -11,11 +11,6 @@ #include "texts.h" #include "accessors/settingsaccessors.h" -// forward declares -namespace { -class ControllerHardwareSettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/graphsmenu.cpp b/main/displays/menus/graphsmenu.cpp index e69de29..030af91 100644 --- a/main/displays/menus/graphsmenu.cpp +++ b/main/displays/menus/graphsmenu.cpp @@ -0,0 +1,183 @@ +#include "graphsmenu.h" + +// 3rdparty lib includes +#include "actions/switchscreenaction.h" +#include "icons/back.h" +#include "graphdisplay.h" +#include "splitgraphdisplay.h" + +// local includes +#include "utils.h" +#include "statistics.h" +#include "displays/menus/mainmenu.h" + +namespace { +using GasGraphDisplay = espgui::makeComponent< + espgui::GraphDisplay<1>, + espgui::StaticText, + espgui::SingleGraphAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; +using BremsGraphDisplay = espgui::makeComponent< + espgui::GraphDisplay<1>, + espgui::StaticText, + espgui::SingleGraphAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; +using PotisGraphDisplay = espgui::makeComponent< + espgui::GraphDisplay<2>, + espgui::StaticText, + espgui::DualGraphAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; +using PotisSplitGraphDisplay = espgui::makeComponent< + espgui::SplitGraphDisplay<1, 1>, + espgui::StaticText, + espgui::SingleTopGraphAccessor, + espgui::SingleBottomGraphAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; + +using AvgSpeedGraphDisplay = espgui::makeComponent< + espgui::GraphDisplay<1>, + espgui::StaticText, + espgui::SingleGraphAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; +using AvgSpeedKmhGraphDisplay = espgui::makeComponent< + espgui::GraphDisplay<1>, + espgui::StaticText, + espgui::SingleGraphAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; + +using SumCurrentGraphDisplay = espgui::makeComponent< + espgui::GraphDisplay<1>, + espgui::StaticText, + espgui::SingleGraphAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; + +using FrontVoltageGraphDisplay = espgui::makeComponent< + espgui::GraphDisplay<1>, + espgui::StaticText, + espgui::SingleGraphAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; +using BackVoltageGraphDisplay = espgui::makeComponent< + espgui::GraphDisplay<1>, + espgui::StaticText, + espgui::SingleGraphAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; +using VoltagesGraphDisplay = espgui::makeComponent< + espgui::GraphDisplay<2>, + espgui::StaticText, + espgui::DualGraphAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; +using VoltagesSplitGraphDisplay = espgui::makeComponent< + espgui::SplitGraphDisplay<1, 1>, + espgui::StaticText, + espgui::SingleTopGraphAccessor, + espgui::SingleBottomGraphAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; + +#ifdef FEATURE_BMS +using BmsVoltageGraphDisplay = espgui::makeComponent< + espgui::GraphDisplay<1>, + espgui::StaticText, + espgui::SingleGraphAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; +using BmsCurrentGraphDisplay = espgui::makeComponent< + espgui::GraphDisplay<1>, + espgui::StaticText, + espgui::SingleGraphAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; +using BmsPowerGraphDisplay = espgui::makeComponent< + espgui::GraphDisplay<1>, + espgui::StaticText, + espgui::SingleGraphAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; +using SumCurrentsComparisonGraphDisplay = espgui::makeComponent< + espgui::GraphDisplay<2>, + espgui::StaticText, + DualGraphAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; +#endif + +class MotorCurrentsStatistics : public virtual espgui::GraphAccessorInterface<4> +{ + std::array, 4> getBuffers() const override + { + return {FrontLeftCurrentStatistics{}.getBuffer(), FrontRightCurrentStatistics{}.getBuffer(), BackLeftCurrentStatistics{}.getBuffer(), BackRightCurrentStatistics{}.getBuffer()}; + } +}; +using MotorCurrentsGraphDisplay = espgui::makeComponent< + espgui::GraphDisplay<4>, + espgui::StaticText, + MotorCurrentsStatistics, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; + +using RssiGraphDisplay = espgui::makeComponent< + espgui::GraphDisplay<1>, + espgui::StaticText, + espgui::SingleGraphAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; +} // namespace + +using namespace espgui; + + +GraphsMenu::GraphsMenu() +{ + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); +#ifdef FEATURE_BMS + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); +#endif + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void GraphsMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/graphsmenu.h b/main/displays/menus/graphsmenu.h index d594b36..a6e9828 100644 --- a/main/displays/menus/graphsmenu.h +++ b/main/displays/menus/graphsmenu.h @@ -2,182 +2,14 @@ // local includes #include "menudisplay.h" -#include "utils.h" -#include "actions/switchscreenaction.h" -#include "icons/back.h" #include "texts.h" -#include "displays/graphdisplay.h" -#include "displays/splitgraphdisplay.h" -#include "statistics.h" - -using namespace espgui; - -namespace { -using GasGraphDisplay = makeComponent< - GraphDisplay<1>, - StaticText, - SingleGraphAccessor, - ConfirmActionInterface>, - BackActionInterface> ->; -using BremsGraphDisplay = makeComponent< - GraphDisplay<1>, - StaticText, - SingleGraphAccessor, - ConfirmActionInterface>, - BackActionInterface> ->; -using PotisGraphDisplay = makeComponent< - GraphDisplay<2>, - StaticText, - DualGraphAccessor, - ConfirmActionInterface>, - BackActionInterface> ->; -using PotisSplitGraphDisplay = makeComponent< - SplitGraphDisplay<1, 1>, - StaticText, - SingleTopGraphAccessor, - SingleBottomGraphAccessor, - ConfirmActionInterface>, - BackActionInterface> ->; - -using AvgSpeedGraphDisplay = makeComponent< - GraphDisplay<1>, - StaticText, - SingleGraphAccessor, - ConfirmActionInterface>, - BackActionInterface> ->; -using AvgSpeedKmhGraphDisplay = makeComponent< - GraphDisplay<1>, - StaticText, - SingleGraphAccessor, - ConfirmActionInterface>, - BackActionInterface> ->; - -using SumCurrentGraphDisplay = makeComponent< - GraphDisplay<1>, - StaticText, - SingleGraphAccessor, - ConfirmActionInterface>, - BackActionInterface> ->; - -using FrontVoltageGraphDisplay = makeComponent< - GraphDisplay<1>, - StaticText, - SingleGraphAccessor, - ConfirmActionInterface>, - BackActionInterface> ->; -using BackVoltageGraphDisplay = makeComponent< - GraphDisplay<1>, - StaticText, - SingleGraphAccessor, - ConfirmActionInterface>, - BackActionInterface> ->; -using VoltagesGraphDisplay = makeComponent< - GraphDisplay<2>, - StaticText, - DualGraphAccessor, - ConfirmActionInterface>, - BackActionInterface> ->; -using VoltagesSplitGraphDisplay = makeComponent< - SplitGraphDisplay<1, 1>, - StaticText, - SingleTopGraphAccessor, - SingleBottomGraphAccessor, - ConfirmActionInterface>, - BackActionInterface> ->; - -#ifdef FEATURE_BMS -using BmsVoltageGraphDisplay = makeComponent< - GraphDisplay<1>, - StaticText, - SingleGraphAccessor, - ConfirmActionInterface>, - BackActionInterface> ->; -using BmsCurrentGraphDisplay = makeComponent< - GraphDisplay<1>, - StaticText, - SingleGraphAccessor, - ConfirmActionInterface>, - BackActionInterface> ->; -using BmsPowerGraphDisplay = makeComponent< - GraphDisplay<1>, - StaticText, - SingleGraphAccessor, - ConfirmActionInterface>, - BackActionInterface> ->; -using SumCurrentsComparisonGraphDisplay = makeComponent< - GraphDisplay<2>, - StaticText, - DualGraphAccessor, - ConfirmActionInterface>, - BackActionInterface> ->; -#endif - -class MotorCurrentsStatistics : public virtual GraphAccessorInterface<4> -{ - std::array, 4> getBuffers() const override - { - return {FrontLeftCurrentStatistics{}.getBuffer(), FrontRightCurrentStatistics{}.getBuffer(), BackLeftCurrentStatistics{}.getBuffer(), BackRightCurrentStatistics{}.getBuffer()}; - } -}; -using MotorCurrentsGraphDisplay = makeComponent< - GraphDisplay<4>, - StaticText, - MotorCurrentsStatistics, - ConfirmActionInterface>, - BackActionInterface> ->; - -using RssiGraphDisplay = makeComponent< - GraphDisplay<1>, - StaticText, - SingleGraphAccessor, - ConfirmActionInterface>, - BackActionInterface> ->; class GraphsMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - GraphsMenu() - { - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); -#ifdef FEATURE_BMS - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); -#endif - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + GraphsMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/menus/invertmenu.h b/main/displays/menus/invertmenu.h index ce125c1..3ac4b65 100644 --- a/main/displays/menus/invertmenu.h +++ b/main/displays/menus/invertmenu.h @@ -11,11 +11,6 @@ #include "texts.h" #include "accessors/settingsaccessors.h" -// forward declares -namespace { -class ControllerHardwareSettingsMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/larsmmodesettingsmenu.cpp b/main/displays/menus/larsmmodesettingsmenu.cpp index e69de29..8c09124 100644 --- a/main/displays/menus/larsmmodesettingsmenu.cpp +++ b/main/displays/menus/larsmmodesettingsmenu.cpp @@ -0,0 +1,53 @@ +#include "larsmmodesettingsmenu.h" + +// 3rdparty lib includes +#include "changevaluedisplay.h" +#include "menuitem.h" +#include "actions/switchscreenaction.h" +#include "icons/back.h" + +// local includes +#include "utils.h" +#include "changevaluedisplay_larsmmode_mode.h" +#include "changevaluedisplay_unifiedmodelmode.h" +#include "accessors/settingsaccessors.h" +#include "displays/menus/modessettingsmenu.h" + +namespace { +using LarsmModeModelModeChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + LarsmModeModelModeAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using LarsmModeModeChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + LarsmModeModeAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +using LarsmModeIterationsChangeDisplay = espgui::makeComponent< + espgui::ChangeValueDisplay, + espgui::StaticText, + LarsmModeIterationsAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; +} // namespace + +using namespace espgui; + +LarsmModeSettingsMenu::LarsmModeSettingsMenu() +{ + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void LarsmModeSettingsMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/larsmmodesettingsmenu.h b/main/displays/menus/larsmmodesettingsmenu.h index 73ac84e..61a60d6 100644 --- a/main/displays/menus/larsmmodesettingsmenu.h +++ b/main/displays/menus/larsmmodesettingsmenu.h @@ -1,54 +1,17 @@ #pragma once +// 3rdparty lib includes + // local includes #include "menudisplay.h" -#include "utils.h" -#include "changevaluedisplay.h" -#include "changevaluedisplay_larsmmode_mode.h" -#include "changevaluedisplay_unifiedmodelmode.h" -#include "menuitem.h" -#include "actions/switchscreenaction.h" -#include "icons/back.h" #include "texts.h" -#include "accessors/settingsaccessors.h" - -using namespace espgui; - -namespace { -using LarsmModeModelModeChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - LarsmModeModelModeAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using LarsmModeModeChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - LarsmModeModeAccessor, - BackActionInterface>, - SwitchScreenAction ->; -using LarsmModeIterationsChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - LarsmModeIterationsAccessor, - BackActionInterface>, - SwitchScreenAction ->; class LarsmModeSettingsMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - LarsmModeSettingsMenu() - { - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + LarsmModeSettingsMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/menus/selectmodemenu.cpp b/main/displays/menus/selectmodemenu.cpp index e69de29..db96c9f 100644 --- a/main/displays/menus/selectmodemenu.cpp +++ b/main/displays/menus/selectmodemenu.cpp @@ -0,0 +1,67 @@ +#include "selectmodemenu.h" + +// local includes +#include "utils.h" +#include "actions/multiaction.h" +#include "actions/switchscreenaction.h" +#include "icons/back.h" +#include "globals.h" +#include "modes/defaultmode.h" +#include "modes/tempomatmode.h" +#include "modes/larsmmode.h" +#include "modes/remotecontrolmode.h" +#include "modes/gametrakmode.h" +#include "accessors/globalaccessors.h" +#include "displays/menus/mainmenu.h" + +namespace { +template +class SetterAction : public espgui::ActionInterface +{ +public: + void triggered() override { target = value; } +}; +using SetDefaultModeAction = SetterAction; +using SetTempomatModeAction = SetterAction; +using SetLarsmModeAction = SetterAction; +using SetRemoteControlModeAction = SetterAction; +#ifdef FEATURE_GAMETRAK +using SetGametrakModeAction = SetterAction; +#endif +} // namespace + +using namespace espgui; + +SelectModeMenu::SelectModeMenu() +{ + constructMenuItem, MultiAction>>>(); + if (!simplified) { constructMenuItem, MultiAction>>>(); } + constructMenuItem, MultiAction>>>(); + if (!simplified) { constructMenuItem, MultiAction>>>(); } +#ifdef FEATURE_GAMETRAK + constructMenuItem, MultiAction>>>(); +#endif + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void SelectModeMenu::start() +{ + Base::start(); + + if (currentMode == &modes::defaultMode) + setSelectedIndex(0); + else if (currentMode == &modes::tempomatMode) + setSelectedIndex(1); + else if (currentMode == &modes::larsmMode) + setSelectedIndex(2); + else + { + //Serial.printf("Unknown mode: %s", currentMode?currentMode->displayName():""); + setSelectedIndex(3); + } +} + +void SelectModeMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/selectmodemenu.h b/main/displays/menus/selectmodemenu.h index 1709c53..1536a86 100644 --- a/main/displays/menus/selectmodemenu.h +++ b/main/displays/menus/selectmodemenu.h @@ -1,74 +1,20 @@ #pragma once -// local includes +// 3rdparty lib includes #include "menudisplay.h" -#include "utils.h" -#include "actions/multiaction.h" -#include "actions/switchscreenaction.h" -#include "icons/back.h" + +// local includes #include "texts.h" -#include "globals.h" - -#include "modes/defaultmode.h" -#include "modes/tempomatmode.h" -#include "modes/larsmmode.h" -#include "modes/remotecontrolmode.h" -#include "modes/gametrakmode.h" - -using namespace espgui; - -namespace { -template -class SetterAction : public ActionInterface -{ -public: - void triggered() override { target = value; } -}; -using SetDefaultModeAction = SetterAction; -using SetTempomatModeAction = SetterAction; -using SetLarsmModeAction = SetterAction; -using SetRemoteControlModeAction = SetterAction; -#ifdef FEATURE_GAMETRAK -using SetGametrakModeAction = SetterAction; -#endif class SelectModeMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { - using Base = MenuDisplay; + using Base = espgui::MenuDisplay; public: - SelectModeMenu() - { - constructMenuItem, MultiAction>>>(); - if (!simplified) { constructMenuItem, MultiAction>>>(); } - constructMenuItem, MultiAction>>>(); - if (!simplified) { constructMenuItem, MultiAction>>>(); } -#ifdef FEATURE_GAMETRAK - constructMenuItem, MultiAction>>>(); -#endif - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + SelectModeMenu(); void start() override; + void back() override; }; - -void SelectModeMenu::start() -{ - Base::start(); - - if (currentMode == &modes::defaultMode) - setSelectedIndex(0); - else if (currentMode == &modes::tempomatMode) - setSelectedIndex(1); - else if (currentMode == &modes::larsmMode) - setSelectedIndex(2); - else - { - //Serial.printf("Unknown mode: %s", currentMode?currentMode->displayName():""); - setSelectedIndex(3); - } -} -} // namespace diff --git a/main/displays/pingpongdisplay.h b/main/displays/pingpongdisplay.h index 9285dd9..9fc412d 100644 --- a/main/displays/pingpongdisplay.h +++ b/main/displays/pingpongdisplay.h @@ -11,10 +11,6 @@ #include "display.h" #include "actions/switchscreenaction.h" -namespace { -class DemosMenu; -} - namespace { class PingPongDisplay : public Display, public ConfirmActionInterface>, public BackActionInterface> { diff --git a/main/displays/spirodisplay.h b/main/displays/spirodisplay.h index b13b0b7..95019ac 100644 --- a/main/displays/spirodisplay.h +++ b/main/displays/spirodisplay.h @@ -11,10 +11,6 @@ #include "display.h" #include "actions/switchscreenaction.h" -namespace { -class DemosMenu; -} - namespace { class SpiroDisplay : public Display, public DummyConfirm, public BackActionInterface> { diff --git a/main/displays/splitgraphdisplay.cpp b/main/displays/splitgraphdisplay.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/main/displays/splitgraphdisplay.h b/main/displays/splitgraphdisplay.h deleted file mode 100644 index 32a5a4c..0000000 --- a/main/displays/splitgraphdisplay.h +++ /dev/null @@ -1,85 +0,0 @@ -#pragma once - -#include "display.h" -#include "textinterface.h" -#include "widgets/label.h" -#include "widgets/graph.h" -#include "globals.h" -#include "statistics.h" - -namespace { -template -class TopGraphAccessorInterface -{ -public: - virtual typename Graph<200, COUNT>::Container getTopBuffers() const = 0; -}; - -template -class SingleTopGraphAccessor : public virtual TopGraphAccessorInterface<1> -{ -public: - typename Graph<200, 1>::Container getTopBuffers() const override - { - return {T{}.getBuffer()}; - } -}; - -template -class BottomGraphAccessorInterface -{ -public: - virtual typename Graph<200, COUNT>::Container getBottomBuffers() const = 0; -}; - -template -class SingleBottomGraphAccessor : public virtual BottomGraphAccessorInterface<1> -{ -public: - typename Graph<200, 1>::Container getBottomBuffers() const override - { - return {T{}.getBuffer()}; - } -}; - -template -class SplitGraphDisplay : - public Display, - public virtual TextInterface, - public virtual TopGraphAccessorInterface, - public virtual BottomGraphAccessorInterface -{ -public: - void initScreen() override; - void redraw() override; - -private: - Label m_titleLabel{5, 5}; // 230, 25 - - Graph<200, COUNT0> m_graph0{0, 40, 133}; - Graph<200, COUNT1> m_graph1{0, 179, 133}; -}; - -template -void SplitGraphDisplay::initScreen() -{ - tft.fillScreen(TFT_BLACK); - - m_titleLabel.start(); - tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE); - - m_graph0.start(static_cast&>(*this).getTopBuffers()); - m_graph1.start(static_cast&>(*this).getBottomBuffers()); -} - -template -void SplitGraphDisplay::redraw() -{ - tft.setTextFont(4); - tft.setTextColor(TFT_YELLOW, TFT_BLACK); - m_titleLabel.redraw(text()); - - m_graph0.redraw(static_cast&>(*this).getTopBuffers()); - m_graph1.redraw(static_cast&>(*this).getBottomBuffers()); -} -} diff --git a/main/displays/starfielddisplay.cpp b/main/displays/starfielddisplay.cpp index e69de29..7ddaa0c 100644 --- a/main/displays/starfielddisplay.cpp +++ b/main/displays/starfielddisplay.cpp @@ -0,0 +1,84 @@ +#include "starfielddisplay.h" + +// 3rdparty lib includes +#include +#include +#include +#include + +// local includes +#include "globals.h" +#include "displays/menus/demosmenu.h" + +StarfieldDisplay::StarfieldDisplay() : + za(cpputils::randomNumber(espcpputils::esp_random_device{})), + zb(cpputils::randomNumber(espcpputils::esp_random_device{})), + zc(cpputils::randomNumber(espcpputils::esp_random_device{})), + zx(cpputils::randomNumber(espcpputils::esp_random_device{})) +{ +} + +void StarfieldDisplay::confirm() +{ + espgui::switchScreen(); +} + +void StarfieldDisplay::back() +{ + espgui::switchScreen(); +} + +void StarfieldDisplay::initScreen() +{ + espgui::tft.fillScreen(TFT_BLACK); + espgui::tft.setRotation(1); + + // fastSetup() must be used immediately before fastPixel() to prepare screen + // It must be called after any other graphics drawing function call if fastPixel() + // is to be called again + //tft.fastSetup(); // Prepare plot window range for fast pixel plotting +} + +void StarfieldDisplay::redraw() +{ + uint8_t spawnDepthVariation = 255; + + for(int i = 0; i < NSTARS; ++i) + { + if (sz[i] <= 1) + { + sx[i] = 160 - 120 + cpputils::randomNumber(espcpputils::esp_random_device{}); + sy[i] = cpputils::randomNumber(espcpputils::esp_random_device{}); + sz[i] = spawnDepthVariation--; + } + else + { + int old_screen_x = ((int)sx[i] - 160) * 256 / sz[i] + 160; + int old_screen_y = ((int)sy[i] - 120) * 256 / sz[i] + 120; + + // This is a faster pixel drawing function for occassions where many single pixels must be drawn + espgui::tft.drawPixel(old_screen_x, old_screen_y,TFT_BLACK); + + sz[i] -= 2; + if (sz[i] > 1) + { + int screen_x = ((int)sx[i] - 160) * 256 / sz[i] + 160; + int screen_y = ((int)sy[i] - 120) * 256 / sz[i] + 120; + + if (screen_x >= 0 && screen_y >= 0 && screen_x < 320 && screen_y < 240) + { + uint8_t r, g, b; + r = g = b = 255 - sz[i]; + espgui::tft.drawPixel(screen_x, screen_y, espgui::tft.color565(r,g,b)); + } + else + sz[i] = 0; // Out of screen, die. + } + } + } +} + +void StarfieldDisplay::stop() +{ + espgui::tft.setRotation(0); +} diff --git a/main/displays/starfielddisplay.h b/main/displays/starfielddisplay.h index 328b80e..f650e55 100644 --- a/main/displays/starfielddisplay.h +++ b/main/displays/starfielddisplay.h @@ -3,33 +3,22 @@ // system includes #include -// 3rdparty lib includes -#include -#include - // local includes #include "display.h" -#include "actions/switchscreenaction.h" -#include "globals.h" -namespace { -class DemosMenu; -} - -namespace { -class StarfieldDisplay : public Display, public ConfirmActionInterface>, public BackActionInterface> +class StarfieldDisplay : public espgui::Display { public: StarfieldDisplay(); + void confirm() override; + void back() override; + void initScreen() override; void redraw() override; void stop() override; private: - // Fast 0-255 random number generator from http://eternityforest.com/Projects/rng.php: - uint8_t rng(); - static constexpr auto NSTARS = 1024; uint8_t sx[NSTARS] = {}; @@ -38,76 +27,3 @@ private: uint8_t za, zb, zc, zx; }; - -StarfieldDisplay::StarfieldDisplay() : - za(cpputils::randomNumber(espcpputils::esp_random_device{})), - zb(cpputils::randomNumber(espcpputils::esp_random_device{})), - zc(cpputils::randomNumber(espcpputils::esp_random_device{})), - zx(cpputils::randomNumber(espcpputils::esp_random_device{})) -{ -} - -void StarfieldDisplay::initScreen() -{ - tft.fillScreen(TFT_BLACK); - tft.setRotation(1); - - // fastSetup() must be used immediately before fastPixel() to prepare screen - // It must be called after any other graphics drawing function call if fastPixel() - // is to be called again - //tft.fastSetup(); // Prepare plot window range for fast pixel plotting -} - -void StarfieldDisplay::redraw() -{ - uint8_t spawnDepthVariation = 255; - - for(int i = 0; i < NSTARS; ++i) - { - if (sz[i] <= 1) - { - sx[i] = 160 - 120 + rng(); - sy[i] = rng(); - sz[i] = spawnDepthVariation--; - } - else - { - int old_screen_x = ((int)sx[i] - 160) * 256 / sz[i] + 160; - int old_screen_y = ((int)sy[i] - 120) * 256 / sz[i] + 120; - - // This is a faster pixel drawing function for occassions where many single pixels must be drawn - tft.drawPixel(old_screen_x, old_screen_y,TFT_BLACK); - - sz[i] -= 2; - if (sz[i] > 1) - { - int screen_x = ((int)sx[i] - 160) * 256 / sz[i] + 160; - int screen_y = ((int)sy[i] - 120) * 256 / sz[i] + 120; - - if (screen_x >= 0 && screen_y >= 0 && screen_x < 320 && screen_y < 240) - { - uint8_t r, g, b; - r = g = b = 255 - sz[i]; - tft.drawPixel(screen_x, screen_y, tft.color565(r,g,b)); - } - else - sz[i] = 0; // Out of screen, die. - } - } - } -} - -void StarfieldDisplay::stop() -{ - tft.setRotation(0); -} - -uint8_t StarfieldDisplay::rng() -{ - zx++; - za = (za^zc^zx); - zb = (zb+za); - zc = (zc+(zb>>1))^za; - return zc; -} -} diff --git a/main/statistics.h b/main/statistics.h index 6090e21..6cb6173 100644 --- a/main/statistics.h +++ b/main/statistics.h @@ -1,7 +1,7 @@ #pragma once // 3rdparty lib includes -#include +#include "graphdisplay.h" #include // local includes From 86a7ef66eedba432651f20f617ecd4831b918431 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Tue, 2 Nov 2021 18:33:55 +0100 Subject: [PATCH 05/10] More refactorings again --- main/CMakeLists.txt | 2 + main/displays/gameoflifedisplay.cpp | 126 +++++++++++++++ main/displays/gameoflifedisplay.h | 124 +-------------- main/displays/menus/otamenu.cpp | 46 ++++++ main/displays/menus/otamenu.h | 39 +---- main/displays/menus/selectotabuildmenu.cpp | 0 main/displays/menus/selectotabuildmenu.h | 5 - main/displays/pingpongdisplay.cpp | 175 +++++++++++++++++++++ main/displays/pingpongdisplay.h | 168 +------------------- main/displays/spirodisplay.cpp | 120 ++++++++++++++ main/displays/spirodisplay.h | 113 +------------ main/displays/updatedisplay.cpp | 114 ++++++++++++++ main/displays/updatedisplay.h | 124 ++------------- main/ota.cpp | 52 ++++++ main/ota.h | 40 +---- 15 files changed, 671 insertions(+), 577 deletions(-) create mode 100644 main/displays/menus/otamenu.cpp create mode 100644 main/displays/menus/selectotabuildmenu.cpp diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 8bba364..1d64070 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -311,6 +311,8 @@ set(sources displays/menus/mosfetsmenu.cpp displays/menus/motorfeedbackdebugmenu.cpp displays/menus/motorstatedebugmenu.cpp + displays/menus/otamenu.cpp + displays/menus/selectotabuildmenu.cpp displays/menus/presetsmenu.cpp displays/menus/profilesmenu.cpp displays/menus/selectbatterytypemenu.cpp diff --git a/main/displays/gameoflifedisplay.cpp b/main/displays/gameoflifedisplay.cpp index e69de29..72b771b 100644 --- a/main/displays/gameoflifedisplay.cpp +++ b/main/displays/gameoflifedisplay.cpp @@ -0,0 +1,126 @@ +#include "gameoflifedisplay.h" + +// 3rdparty lib includes +#include +#include +#include +#include + +void GameOfLifeDisplay::start() +{ + m_grid = std::make_unique>(); + m_newgrid = std::make_unique>(); +} + +void GameOfLifeDisplay::initScreen() +{ + espgui::tft.setRotation(3); + espgui::tft.fillScreen(TFT_BLACK); +} + +void GameOfLifeDisplay::redraw() +{ + if (gen == 0) + { + espgui::tft.fillScreen(TFT_BLACK); + initGrid(); + } + + computeCA(); + drawGrid(); + + *m_grid = *m_newgrid; + + if (++gen == 500) + gen = 0; +} + +void GameOfLifeDisplay::stop() +{ + espgui::tft.setRotation(0); + m_grid = nullptr; + m_newgrid = nullptr; +} + +void GameOfLifeDisplay::confirm() +{ + +} + +void GameOfLifeDisplay::back() +{ + +} + +void GameOfLifeDisplay::drawGrid() +{ + uint16_t color = TFT_WHITE; + for (int16_t x = 1; x < GRIDX - 1; x++) { + for (int16_t y = 1; y < GRIDY - 1; y++) { + if (((*m_grid)[index(x,y)]) != ((*m_newgrid)[index(x,y)])) { + if ((*m_newgrid)[index(x,y)] == 1) + color = 0xFFFF; //random(0xFFFF); + else + color = 0; + espgui::tft.fillRect(CELLXY * x, CELLXY * y, CELLXY, CELLXY, color); + } + } + } +} + +void GameOfLifeDisplay::initGrid() +{ + for (int16_t x = 0; x < GRIDX; x++) { + for (int16_t y = 0; y < GRIDY; y++) { + (*m_newgrid)[index(x,y)] = 0; + + if (x == 0 || x == GRIDX - 1 || y == 0 || y == GRIDY - 1) + (*m_grid)[index(x,y)] = 0; + else + { + if (cpputils::randomNumber(4, espcpputils::esp_random_device{}) == 1) + (*m_grid)[index(x,y)] = 1; + else + (*m_grid)[index(x,y)] = 0; + } + + } + } +} + +int GameOfLifeDisplay::getNumberOfNeighbors(int x, int y) +{ + int n{}; + for (auto xOffset : {-1,0,1}) + for (auto yOffset : {-1,0,1}) + { + if (xOffset == 0 && yOffset == 0) + continue; + + const auto new_x = x+xOffset; + const auto new_y = y+yOffset; + + if (new_x >= 0 && new_y >= 0 && + new_x < GRIDX && new_y < GRIDY) + n += (*m_grid)[index(new_x, new_y)]; + } + + return n; +} + +void GameOfLifeDisplay::computeCA() +{ + for (int16_t x = 1; x < GRIDX; x++) { + for (int16_t y = 1; y < GRIDY; y++) { + int neighbors = getNumberOfNeighbors(x, y); + if ((*m_grid)[index(x,y)] == true && (neighbors == 2 || neighbors == 3 )) + (*m_newgrid)[index(x,y)] = true; + else if ((*m_grid)[index(x,y)] == 1) + (*m_newgrid)[index(x,y)] = false; + if ((*m_grid)[index(x,y)] == false && (neighbors == 3)) + (*m_newgrid)[index(x,y)] = true; + else if ((*m_grid)[index(x,y)] == 0) + (*m_newgrid)[index(x,y)] = false; + } + } +} diff --git a/main/displays/gameoflifedisplay.h b/main/displays/gameoflifedisplay.h index 62b0be4..fe627f9 100644 --- a/main/displays/gameoflifedisplay.h +++ b/main/displays/gameoflifedisplay.h @@ -4,23 +4,22 @@ #include #include -// 3rdparty lib includes -#include -#include - // local includes #include "display.h" -#include "actions/switchscreenaction.h" -namespace { -class GameOfLifeDisplay : public Display, public ConfirmActionInterface>, public BackActionInterface> +class GameOfLifeDisplay : public espgui::Display { + using Base = espgui::Display; + public: void start() override; void initScreen() override; void redraw() override; void stop() override; + void confirm() override; + void back() override; + private: //Draws the grid on the display @@ -71,114 +70,3 @@ private: int gen = 0; }; - -void GameOfLifeDisplay::start() -{ - m_grid = std::make_unique>(); - m_newgrid = std::make_unique>(); -} - -void GameOfLifeDisplay::initScreen() -{ - tft.setRotation(3); - tft.fillScreen(TFT_BLACK); -} - -void GameOfLifeDisplay::redraw() -{ - if (gen == 0) - { - tft.fillScreen(TFT_BLACK); - initGrid(); - } - - computeCA(); - drawGrid(); - - *m_grid = *m_newgrid; - - if (++gen == 500) - gen = 0; -} - -void GameOfLifeDisplay::stop() -{ - tft.setRotation(0); - m_grid = nullptr; - m_newgrid = nullptr; -} - -void GameOfLifeDisplay::drawGrid() -{ - uint16_t color = TFT_WHITE; - for (int16_t x = 1; x < GRIDX - 1; x++) { - for (int16_t y = 1; y < GRIDY - 1; y++) { - if (((*m_grid)[index(x,y)]) != ((*m_newgrid)[index(x,y)])) { - if ((*m_newgrid)[index(x,y)] == 1) - color = 0xFFFF; //random(0xFFFF); - else - color = 0; - tft.fillRect(CELLXY * x, CELLXY * y, CELLXY, CELLXY, color); - } - } - } -} - -void GameOfLifeDisplay::initGrid() -{ - for (int16_t x = 0; x < GRIDX; x++) { - for (int16_t y = 0; y < GRIDY; y++) { - (*m_newgrid)[index(x,y)] = 0; - - if (x == 0 || x == GRIDX - 1 || y == 0 || y == GRIDY - 1) - (*m_grid)[index(x,y)] = 0; - else - { - if (cpputils::randomNumber(4, espcpputils::esp_random_device{}) == 1) - (*m_grid)[index(x,y)] = 1; - else - (*m_grid)[index(x,y)] = 0; - } - - } - } -} - -int GameOfLifeDisplay::getNumberOfNeighbors(int x, int y) -{ - int n{}; - for (auto xOffset : {-1,0,1}) - for (auto yOffset : {-1,0,1}) - { - if (xOffset == 0 && yOffset == 0) - continue; - - const auto new_x = x+xOffset; - const auto new_y = y+yOffset; - - if (new_x >= 0 && new_y >= 0 && - new_x < GRIDX && new_y < GRIDY) - n += (*m_grid)[index(new_x, new_y)]; - } - - return n; -} - -void GameOfLifeDisplay::computeCA() -{ - for (int16_t x = 1; x < GRIDX; x++) { - for (int16_t y = 1; y < GRIDY; y++) { - int neighbors = getNumberOfNeighbors(x, y); - if ((*m_grid)[index(x,y)] == true && (neighbors == 2 || neighbors == 3 )) - (*m_newgrid)[index(x,y)] = true; - else if ((*m_grid)[index(x,y)] == 1) - (*m_newgrid)[index(x,y)] = false; - if ((*m_grid)[index(x,y)] == false && (neighbors == 3)) - (*m_newgrid)[index(x,y)] = true; - else if ((*m_grid)[index(x,y)] == 0) - (*m_newgrid)[index(x,y)] = false; - } - } -} - -} diff --git a/main/displays/menus/otamenu.cpp b/main/displays/menus/otamenu.cpp new file mode 100644 index 0000000..422fafc --- /dev/null +++ b/main/displays/menus/otamenu.cpp @@ -0,0 +1,46 @@ +#include "otamenu.h" + +// 3rdparty lib includes +#include "actioninterface.h" +#include "actions/dummyaction.h" +#include "actions/switchscreenaction.h" +#include "icons/back.h" + +// local includes +#include "utils.h" +#include "icons/update.h" +#include "icons/presets.h" +#include "buildserver.h" +#include "displays/menus/selectotabuildmenu.h" +#include "displays/updatedisplay.h" +#include "displays/menus/selectbuildservermenu.h" +#include "displays/menus/mainmenu.h" + +namespace { + +class RedownloadJsonAction : public virtual espgui::ActionInterface +{ +public: + void triggered() override + { + redownload = true; + } +}; + +} // namespace + +using namespace espgui; + +OtaMenu::OtaMenu() +{ + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::presets>>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::update>>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, RedownloadJsonAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void OtaMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/otamenu.h b/main/displays/menus/otamenu.h index 30dbacb..1e07b27 100644 --- a/main/displays/menus/otamenu.h +++ b/main/displays/menus/otamenu.h @@ -1,40 +1,17 @@ #pragma once -// local includes +// 3rdparty lib includes #include "menudisplay.h" -#include "actioninterface.h" -#include "utils.h" -#include "actions/dummyaction.h" -#include "icons/back.h" -#include "icons/update.h" -#include "icons/presets.h" + +// local includes #include "texts.h" -#include "buildserver.h" - -using namespace espgui; - -namespace { - -class RedownloadJsonAction : public virtual ActionInterface { -public: - void triggered() override { - redownload = true; - } -}; class OtaMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - OtaMenu() - { - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::presets>>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::update>>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, RedownloadJsonAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + OtaMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/menus/selectotabuildmenu.cpp b/main/displays/menus/selectotabuildmenu.cpp new file mode 100644 index 0000000..e69de29 diff --git a/main/displays/menus/selectotabuildmenu.h b/main/displays/menus/selectotabuildmenu.h index 5398579..3c9c051 100644 --- a/main/displays/menus/selectotabuildmenu.h +++ b/main/displays/menus/selectotabuildmenu.h @@ -18,11 +18,6 @@ #define MESSAGE(text) constructMenuItem, DefaultFont, StaticColor, DummyAction>>() -// forward declares -namespace { -class OtaMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/pingpongdisplay.cpp b/main/displays/pingpongdisplay.cpp index e69de29..abd76a7 100644 --- a/main/displays/pingpongdisplay.cpp +++ b/main/displays/pingpongdisplay.cpp @@ -0,0 +1,175 @@ +#include "pingpongdisplay.h" + +// 3rdparty lib includes +#include +#include +#include +#include + +// local includes +#include "displays/menus/demosmenu.h" + +PingPongDisplay::PingPongDisplay() : + lpaddle_y(cpputils::randomNumber(0, h - paddle_h, espcpputils::esp_random_device{})), + rpaddle_y(cpputils::randomNumber(0, h - paddle_h, espcpputils::esp_random_device{})), + // ball is placed on the center of the left paddle + ball_y(lpaddle_y + (paddle_h / 2)) +{ + calc_target_y(); +} + +void PingPongDisplay::initScreen() +{ + espgui::tft.fillScreen(TFT_BLACK); + espgui::tft.setRotation(1); + + midline(); +} + +void PingPongDisplay::redraw() +{ + lpaddle(); + rpaddle(); + + midline(); + + ball(); +} + +void PingPongDisplay::stop() +{ + espgui::tft.setRotation(0); +} + +void PingPongDisplay::confirm() +{ + espgui::switchScreen(); +} + +void PingPongDisplay::back() +{ + espgui::switchScreen(); +} + +void PingPongDisplay::midline() +{ + // If the ball is not on the line then don't redraw the line + if ((ball_x dashline_x+dashline_w)) return; + + espgui::tft.startWrite(); + + // Quick way to draw a dashed line + espgui::tft.setAddrWindow(dashline_x, 0, dashline_w, h); + + for (int16_t i = 0; i < dashline_n; i+=2) + { + espgui::tft.pushColor(WHITE, dashline_w*dashline_h); // push dash pixels + espgui::tft.pushColor(BLACK, dashline_w*dashline_h); // push gap pixels + } + + espgui::tft.endWrite(); +} + +void PingPongDisplay::lpaddle() +{ + if (lpaddle_d == 1) + { + espgui::tft.fillRect(lpaddle_x, lpaddle_y, paddle_w, 1, BLACK); + } + else if (lpaddle_d == -1) + { + espgui::tft.fillRect(lpaddle_x, lpaddle_y + paddle_h - 1, paddle_w, 1, BLACK); + } + + lpaddle_y = lpaddle_y + lpaddle_d; + + if (ball_dx == 1) + lpaddle_d = 0; + else + { + if (lpaddle_y + paddle_h / 2 == target_y) lpaddle_d = 0; + else if (lpaddle_y + paddle_h / 2 > target_y) lpaddle_d = -1; + else lpaddle_d = 1; + } + + if (lpaddle_y + paddle_h >= h && lpaddle_d == 1) lpaddle_d = 0; + else if (lpaddle_y <= 0 && lpaddle_d == -1) lpaddle_d = 0; + + espgui::tft.fillRect(lpaddle_x, lpaddle_y, paddle_w, paddle_h, WHITE); +} + +void PingPongDisplay::rpaddle() +{ + if (rpaddle_d == 1) + espgui::tft.fillRect(rpaddle_x, rpaddle_y, paddle_w, 1, BLACK); + else if (rpaddle_d == -1) + espgui::tft.fillRect(rpaddle_x, rpaddle_y + paddle_h - 1, paddle_w, 1, BLACK); + + rpaddle_y = rpaddle_y + rpaddle_d; + + if (ball_dx == -1) + rpaddle_d = 0; + else + { + if (rpaddle_y + paddle_h / 2 == target_y) rpaddle_d = 0; + else if (rpaddle_y + paddle_h / 2 > target_y) rpaddle_d = -1; + else rpaddle_d = 1; + } + + if (rpaddle_y + paddle_h >= h && rpaddle_d == 1) + rpaddle_d = 0; + else if (rpaddle_y <= 0 && rpaddle_d == -1) + rpaddle_d = 0; + + espgui::tft.fillRect(rpaddle_x, rpaddle_y, paddle_w, paddle_h, WHITE); +} + +void PingPongDisplay::calc_target_y() +{ + int16_t target_x; + int16_t reflections; + int16_t y; + + if (ball_dx == 1) + target_x = w - ball_w; + else + target_x = -1 * (w - ball_w); + + y = abs(target_x * (ball_dy / ball_dx) + ball_y); + + reflections = floor(y / h); + + if (reflections % 2 == 0) + target_y = y % h; + else + target_y = h - (y % h); +} + +void PingPongDisplay::ball() +{ + ball_x = ball_x + ball_dx; + ball_y = ball_y + ball_dy; + + if (ball_dx == -1 && ball_x == paddle_w && ball_y + ball_h >= lpaddle_y && ball_y <= lpaddle_y + paddle_h) { + ball_dx = ball_dx * -1; + dly = cpputils::randomNumber(5, espcpputils::esp_random_device{}); // change speed of ball after paddle contact + calc_target_y(); + } else if (ball_dx == 1 && ball_x + ball_w == w - paddle_w && ball_y + ball_h >= rpaddle_y && ball_y <= rpaddle_y + paddle_h) { + ball_dx = ball_dx * -1; + dly = cpputils::randomNumber(5, espcpputils::esp_random_device{}); // change speed of ball after paddle contact + calc_target_y(); + } else if ((ball_dx == 1 && ball_x >= w) || (ball_dx == -1 && ball_x + ball_w < 0)) { + dly = 5; + } + + if (ball_y > h - ball_w || ball_y < 0) { + ball_dy = ball_dy * -1; + ball_y += ball_dy; // Keep in bounds + } + + //tft.fillRect(oldball_x, oldball_y, ball_w, ball_h, BLACK); + espgui::tft.drawRect(oldball_x, oldball_y, ball_w, ball_h, BLACK); // Less TFT refresh aliasing than line above for large balls + espgui::tft.fillRect( ball_x, ball_y, ball_w, ball_h, WHITE); + oldball_x = ball_x; + oldball_y = ball_y; +} diff --git a/main/displays/pingpongdisplay.h b/main/displays/pingpongdisplay.h index 9fc412d..2fd554e 100644 --- a/main/displays/pingpongdisplay.h +++ b/main/displays/pingpongdisplay.h @@ -4,15 +4,9 @@ #include // 3rdparty lib includes -#include -#include - -// local includes #include "display.h" -#include "actions/switchscreenaction.h" -namespace { -class PingPongDisplay : public Display, public ConfirmActionInterface>, public BackActionInterface> +class PingPongDisplay : public espgui::Display { public: PingPongDisplay(); @@ -21,6 +15,9 @@ public: void redraw() override; void stop() override; + void confirm() override; + void back() override; + private: void midline(); void lpaddle(); @@ -74,160 +71,3 @@ private: static const constexpr auto WHITE = 0xFFFF; static const constexpr auto GREY = 0x5AEB; }; - -PingPongDisplay::PingPongDisplay() : - lpaddle_y(cpputils::randomNumber(0, h - paddle_h, espcpputils::esp_random_device{})), - rpaddle_y(cpputils::randomNumber(0, h - paddle_h, espcpputils::esp_random_device{})), - // ball is placed on the center of the left paddle - ball_y(lpaddle_y + (paddle_h / 2)) -{ - calc_target_y(); -} - -void PingPongDisplay::initScreen() -{ - tft.fillScreen(TFT_BLACK); - tft.setRotation(1); - - midline(); -} - -void PingPongDisplay::redraw() -{ - lpaddle(); - rpaddle(); - - midline(); - - ball(); -} - -void PingPongDisplay::stop() -{ - tft.setRotation(0); -} - -void PingPongDisplay::midline() -{ - // If the ball is not on the line then don't redraw the line - if ((ball_x dashline_x+dashline_w)) return; - - tft.startWrite(); - - // Quick way to draw a dashed line - tft.setAddrWindow(dashline_x, 0, dashline_w, h); - - for(int16_t i = 0; i < dashline_n; i+=2) { - tft.pushColor(WHITE, dashline_w*dashline_h); // push dash pixels - tft.pushColor(BLACK, dashline_w*dashline_h); // push gap pixels - } - - tft.endWrite(); -} - -void PingPongDisplay::lpaddle() -{ - if (lpaddle_d == 1) - { - tft.fillRect(lpaddle_x, lpaddle_y, paddle_w, 1, BLACK); - } - else if (lpaddle_d == -1) - { - tft.fillRect(lpaddle_x, lpaddle_y + paddle_h - 1, paddle_w, 1, BLACK); - } - - lpaddle_y = lpaddle_y + lpaddle_d; - - if (ball_dx == 1) - lpaddle_d = 0; - else - { - if (lpaddle_y + paddle_h / 2 == target_y) lpaddle_d = 0; - else if (lpaddle_y + paddle_h / 2 > target_y) lpaddle_d = -1; - else lpaddle_d = 1; - } - - if (lpaddle_y + paddle_h >= h && lpaddle_d == 1) lpaddle_d = 0; - else if (lpaddle_y <= 0 && lpaddle_d == -1) lpaddle_d = 0; - - tft.fillRect(lpaddle_x, lpaddle_y, paddle_w, paddle_h, WHITE); -} - -void PingPongDisplay::rpaddle() -{ - if (rpaddle_d == 1) { - tft.fillRect(rpaddle_x, rpaddle_y, paddle_w, 1, BLACK); - } - else if (rpaddle_d == -1) { - tft.fillRect(rpaddle_x, rpaddle_y + paddle_h - 1, paddle_w, 1, BLACK); - } - - rpaddle_y = rpaddle_y + rpaddle_d; - - if (ball_dx == -1) rpaddle_d = 0; - else { - if (rpaddle_y + paddle_h / 2 == target_y) rpaddle_d = 0; - else if (rpaddle_y + paddle_h / 2 > target_y) rpaddle_d = -1; - else rpaddle_d = 1; - } - - if (rpaddle_y + paddle_h >= h && rpaddle_d == 1) rpaddle_d = 0; - else if (rpaddle_y <= 0 && rpaddle_d == -1) rpaddle_d = 0; - - tft.fillRect(rpaddle_x, rpaddle_y, paddle_w, paddle_h, WHITE); -} - -void PingPongDisplay::calc_target_y() -{ - int16_t target_x; - int16_t reflections; - int16_t y; - - if (ball_dx == 1) { - target_x = w - ball_w; - } - else { - target_x = -1 * (w - ball_w); - } - - y = abs(target_x * (ball_dy / ball_dx) + ball_y); - - reflections = floor(y / h); - - if (reflections % 2 == 0) { - target_y = y % h; - } - else { - target_y = h - (y % h); - } -} - -void PingPongDisplay::ball() -{ - ball_x = ball_x + ball_dx; - ball_y = ball_y + ball_dy; - - if (ball_dx == -1 && ball_x == paddle_w && ball_y + ball_h >= lpaddle_y && ball_y <= lpaddle_y + paddle_h) { - ball_dx = ball_dx * -1; - dly = cpputils::randomNumber(5, espcpputils::esp_random_device{}); // change speed of ball after paddle contact - calc_target_y(); - } else if (ball_dx == 1 && ball_x + ball_w == w - paddle_w && ball_y + ball_h >= rpaddle_y && ball_y <= rpaddle_y + paddle_h) { - ball_dx = ball_dx * -1; - dly = cpputils::randomNumber(5, espcpputils::esp_random_device{}); // change speed of ball after paddle contact - calc_target_y(); - } else if ((ball_dx == 1 && ball_x >= w) || (ball_dx == -1 && ball_x + ball_w < 0)) { - dly = 5; - } - - if (ball_y > h - ball_w || ball_y < 0) { - ball_dy = ball_dy * -1; - ball_y += ball_dy; // Keep in bounds - } - - //tft.fillRect(oldball_x, oldball_y, ball_w, ball_h, BLACK); - tft.drawRect(oldball_x, oldball_y, ball_w, ball_h, BLACK); // Less TFT refresh aliasing than line above for large balls - tft.fillRect( ball_x, ball_y, ball_w, ball_h, WHITE); - oldball_x = ball_x; - oldball_y = ball_y; -} -} diff --git a/main/displays/spirodisplay.cpp b/main/displays/spirodisplay.cpp index e69de29..7475771 100644 --- a/main/displays/spirodisplay.cpp +++ b/main/displays/spirodisplay.cpp @@ -0,0 +1,120 @@ +#include "spirodisplay.h" + +// 3rdparty lib includes +#include +#include +#include +#include + +// local includes +#include "displays/menus/demosmenu.h" + +void SpiroDisplay::initScreen() +{ + Base::initScreen(); + espgui::tft.setRotation(3); +} + +void SpiroDisplay::redraw() +{ + for (int j = 0; j < std::max(1, n); j++) + { + if (i == 0) + { + espgui::tft.fillScreen(TFT_BLACK); + n = cpputils::randomNumber(2, 23, espcpputils::esp_random_device{}); + r = cpputils::randomNumber(20, 100, espcpputils::esp_random_device{}); + colour = 0; //rainbow(); + } + + if (i < (360 * n)) + { + sx = std::cos((i / n - 90) * DEG2RAD); + sy = std::sin((i / n - 90) * DEG2RAD); + x0 = sx * (120 - r) + 159; + yy0 = sy * (120 - r) + 119; + + + sy = std::cos(((i % 360) - 90) * DEG2RAD); + sx = std::sin(((i % 360) - 90) * DEG2RAD); + x1 = sx * r + x0; + yy1 = sy * r + yy0; + espgui::tft.drawPixel(x1, yy1, rainbow(map(i%360,0,360,0,127))); //colour); + } + + if (i == (360 * n)) + { + r = cpputils::randomNumber(20, 100, espcpputils::esp_random_device{});//r = r / random(2,4); + } + + if (i >= (360 * n)) + { + auto new_i = i - (360 * n); + + sx = std::cos((new_i / n - 90) * DEG2RAD); + sy = std::sin((new_i / n - 90) * DEG2RAD); + x0 = sx * (120 - r) + 159; + yy0 = sy * (120 - r) + 119; + + + sy = std::cos(((new_i % 360) - 90) * DEG2RAD); + sx = std::sin(((new_i % 360) - 90) * DEG2RAD); + x1 = sx * r + x0; + yy1 = sy * r + yy0; + espgui::tft.drawPixel(x1, yy1, rainbow(map(new_i%360,0,360,0,127))); //colour); + } + + i++; + if (i == 2* (360 * n)) + i = 0; + } +} + +void SpiroDisplay::stop() +{ + espgui::tft.setRotation(0); +} + +unsigned int SpiroDisplay::rainbow(int value) +{ + // Value is expected to be in range 0-127 + // The value is converted to a spectrum colour from 0 = blue through to red = blue + //int value = random (128); + byte red = 0; // Red is the top 5 bits of a 16 bit colour value + byte green = 0;// Green is the middle 6 bits + byte blue = 0; // Blue is the bottom 5 bits + + byte quadrant = value / 32; + + if (quadrant == 0) { + blue = 31; + green = 2 * (value % 32); + red = 0; + } + if (quadrant == 1) { + blue = 31 - (value % 32); + green = 63; + red = 0; + } + if (quadrant == 2) { + blue = 0; + green = 63; + red = value % 32; + } + if (quadrant == 3) { + blue = 0; + green = 63 - 2 * (value % 32); + red = 31; + } + return (red << 11) + (green << 5) + blue; +} + +void SpiroDisplay::confirm() +{ + espgui::switchScreen(); +} + +void SpiroDisplay::back() +{ + espgui::switchScreen(); +} diff --git a/main/displays/spirodisplay.h b/main/displays/spirodisplay.h index 95019ac..67dd2b6 100644 --- a/main/displays/spirodisplay.h +++ b/main/displays/spirodisplay.h @@ -3,22 +3,22 @@ // system includes #include -// 3rdparty lib includes -#include -#include - // local includes #include "display.h" #include "actions/switchscreenaction.h" -namespace { -class SpiroDisplay : public Display, public DummyConfirm, public BackActionInterface> +class SpiroDisplay : public espgui::Display { + using Base = espgui::Display; + public: void initScreen() override; void redraw() override; void stop() override; + void confirm() override; + void back() override; + private: constexpr static auto DEG2RAD = 0.0174532925; @@ -30,104 +30,3 @@ private: long i{0}; int n{}, r{}, colour{}; }; - -void SpiroDisplay::initScreen() -{ - tft.fillScreen(TFT_BLACK); - tft.setRotation(3); -} - -void SpiroDisplay::redraw() -{ - for (int j = 0; j < std::max(1, n); j++) - { - if (i == 0) - { - tft.fillScreen(TFT_BLACK); - n = cpputils::randomNumber(2, 23, espcpputils::esp_random_device{}); - r = cpputils::randomNumber(20, 100, espcpputils::esp_random_device{}); - colour = 0; //rainbow(); - } - - if (i < (360 * n)) - { - sx = std::cos((i / n - 90) * DEG2RAD); - sy = std::sin((i / n - 90) * DEG2RAD); - x0 = sx * (120 - r) + 159; - yy0 = sy * (120 - r) + 119; - - - sy = std::cos(((i % 360) - 90) * DEG2RAD); - sx = std::sin(((i % 360) - 90) * DEG2RAD); - x1 = sx * r + x0; - yy1 = sy * r + yy0; - tft.drawPixel(x1, yy1, rainbow(map(i%360,0,360,0,127))); //colour); - } - - if (i == (360 * n)) - { - r = cpputils::randomNumber(20, 100, espcpputils::esp_random_device{});//r = r / random(2,4); - } - - if (i >= (360 * n)) - { - auto new_i = i - (360 * n); - - sx = std::cos((new_i / n - 90) * DEG2RAD); - sy = std::sin((new_i / n - 90) * DEG2RAD); - x0 = sx * (120 - r) + 159; - yy0 = sy * (120 - r) + 119; - - - sy = std::cos(((new_i % 360) - 90) * DEG2RAD); - sx = std::sin(((new_i % 360) - 90) * DEG2RAD); - x1 = sx * r + x0; - yy1 = sy * r + yy0; - tft.drawPixel(x1, yy1, rainbow(map(new_i%360,0,360,0,127))); //colour); - } - - i++; - if (i == 2* (360 * n)) - i = 0; - } -} - -void SpiroDisplay::stop() -{ - tft.setRotation(0); -} - -unsigned int SpiroDisplay::rainbow(int value) -{ - // Value is expected to be in range 0-127 - // The value is converted to a spectrum colour from 0 = blue through to red = blue - //int value = random (128); - byte red = 0; // Red is the top 5 bits of a 16 bit colour value - byte green = 0;// Green is the middle 6 bits - byte blue = 0; // Blue is the bottom 5 bits - - byte quadrant = value / 32; - - if (quadrant == 0) { - blue = 31; - green = 2 * (value % 32); - red = 0; - } - if (quadrant == 1) { - blue = 31 - (value % 32); - green = 63; - red = 0; - } - if (quadrant == 2) { - blue = 0; - green = 63; - red = value % 32; - } - if (quadrant == 3) { - blue = 0; - green = 63 - 2 * (value % 32); - red = 31; - } - return (red << 11) + (green << 5) + blue; -} -} diff --git a/main/displays/updatedisplay.cpp b/main/displays/updatedisplay.cpp index e69de29..f4015ae 100644 --- a/main/displays/updatedisplay.cpp +++ b/main/displays/updatedisplay.cpp @@ -0,0 +1,114 @@ +#include "updatedisplay.h" + +// system includes +#include +#include + +// esp-idf includes +#include + +// 3rdparty lib includes +#include +#include +#ifdef FEATURE_OTA +#include +#include +#endif + +// local includes +#include "globals.h" +#include "texts.h" +#include "ota.h" +#include "displays/menus/otamenu.h" + +#ifdef FEATURE_OTA +void UpdateDisplay::initScreen() +{ + Base::initScreen(); + + espgui::tft.setTextFont(4); + espgui::tft.setTextColor(TFT_YELLOW); + + espgui::tft.drawString(TEXT_UPDATE, 5, 5, 4); + + espgui::tft.fillRect(0, 34, espgui::tft.width(), 3, TFT_WHITE); + + espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK); + + espgui::tft.drawString("Status:", 20, m_statusLabel.y()); + m_statusLabel.start(); + + espgui::tft.drawString("Progress:", 20, m_progressLabel.y()); + m_progressLabel.start(); + + espgui::tft.drawString("Total:", 20, m_totalLabel.y()); + m_totalLabel.start(); + + m_messageLabel.start(); + + m_progressBar.start(); + + if (const esp_app_desc_t *app_desc = esp_ota_get_app_description()) + { + espgui::tft.setTextColor(TFT_ORANGE, TFT_BLACK); + espgui::tft.drawString(app_desc->version, 20, 250); + espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK); + } + + m_newVersionLabel.start(); +} + +void UpdateDisplay::redraw() +{ + Base::redraw(); + + if (asyncOta) + { + m_statusLabel.redraw(toString(asyncOta->status())); + const auto progress = asyncOta->progress(); + m_progressLabel.redraw(std::to_string(progress)); + if (const auto totalSize = asyncOta->totalSize(); totalSize && *totalSize > 0) + { + m_totalLabel.redraw(std::to_string(*totalSize)); + m_progressBar.redraw(float(progress) / *totalSize * 100); + } + else + { + m_totalLabel.clear(); + m_progressBar.redraw(0); + } + m_messageLabel.redraw(asyncOta->message()); + + if (const auto &appDesc = asyncOta->appDesc()) + { + espgui::tft.setTextColor(TFT_GREEN, TFT_BLACK); + m_newVersionLabel.redraw(appDesc->version); + espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK); + } + else + m_newVersionLabel.clear(); + } + else + { + m_statusLabel.clear(); + m_progressLabel.clear(); + m_totalLabel.clear(); + m_messageLabel.clear(); + + m_progressBar.redraw(0); + + m_newVersionLabel.clear(); + } +} + +void UpdateDisplay::confirm() +{ + if (const auto result = triggerOta(stringSettings.otaUrl); !result) + ESP_LOGE("BOBBY", "triggerOta() failed with %.*s", result.error().size(), result.error().data()); +} + +void UpdateDisplay::back() +{ + espgui::switchScreen(); +} +#endif diff --git a/main/displays/updatedisplay.h b/main/displays/updatedisplay.h index 6e0a60c..087381f 100644 --- a/main/displays/updatedisplay.h +++ b/main/displays/updatedisplay.h @@ -1,136 +1,30 @@ #pragma once -// system includes -#include -#include - -// esp-idf includes -#include - // 3rdparty lib includes -#ifdef FEATURE_OTA -#include -#include -#endif // local includes #include "display.h" -#include "actions/switchscreenaction.h" -#include "globals.h" -#include "texts.h" #include "widgets/label.h" #include "widgets/progressbar.h" -#include "ota.h" -namespace { -class OtaMenu; -} - -namespace { #ifdef FEATURE_OTA -class UpdateDisplay : public Display, public BackActionInterface> +class UpdateDisplay : public espgui::Display { + using Base = espgui::Display; public: - void start() override; void initScreen() override; void redraw() override; void confirm() override; + void back() override; private: - Label m_statusLabel{120, 75}; - Label m_progressLabel{120, 100}; - Label m_totalLabel{120, 125}; - Label m_messageLabel{20, 150}; + espgui::Label m_statusLabel{120, 75}; + espgui::Label m_progressLabel{120, 100}; + espgui::Label m_totalLabel{120, 125}; + espgui::Label m_messageLabel{20, 150}; - ProgressBar m_progressBar{20, 200, 200, 10, 0, 100}; + espgui::ProgressBar m_progressBar{20, 200, 200, 10, 0, 100}; - Label m_newVersionLabel{20, 275}; + espgui::Label m_newVersionLabel{20, 275}; }; - -void UpdateDisplay::start() -{ -} - -void UpdateDisplay::initScreen() -{ - tft.fillScreen(TFT_BLACK); - tft.setTextFont(4); - tft.setTextColor(TFT_YELLOW); - - tft.drawString(TEXT_UPDATE, 5, 5, 4); - - tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE); - - tft.setTextColor(TFT_WHITE, TFT_BLACK); - - tft.drawString("Status:", 20, m_statusLabel.y()); - m_statusLabel.start(); - - tft.drawString("Progress:", 20, m_progressLabel.y()); - m_progressLabel.start(); - - tft.drawString("Total:", 20, m_totalLabel.y()); - m_totalLabel.start(); - - m_messageLabel.start(); - - m_progressBar.start(); - - if (const esp_app_desc_t *app_desc = esp_ota_get_app_description()) - { - tft.setTextColor(TFT_ORANGE, TFT_BLACK); - tft.drawString(app_desc->version, 20, 250); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - } - - m_newVersionLabel.start(); -} - -void UpdateDisplay::redraw() -{ - if (asyncOta) - { - m_statusLabel.redraw(toString(asyncOta->status())); - const auto progress = asyncOta->progress(); - m_progressLabel.redraw(std::to_string(progress)); - if (const auto totalSize = asyncOta->totalSize(); totalSize && *totalSize > 0) - { - m_totalLabel.redraw(std::to_string(*totalSize)); - m_progressBar.redraw(float(progress) / *totalSize * 100); - } - else - { - m_totalLabel.clear(); - m_progressBar.redraw(0); - } - m_messageLabel.redraw(asyncOta->message()); - - if (const auto &appDesc = asyncOta->appDesc()) - { - tft.setTextColor(TFT_GREEN, TFT_BLACK); - m_newVersionLabel.redraw(appDesc->version); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - } - else - m_newVersionLabel.clear(); - } - else - { - m_statusLabel.clear(); - m_progressLabel.clear(); - m_totalLabel.clear(); - m_messageLabel.clear(); - - m_progressBar.redraw(0); - - m_newVersionLabel.clear(); - } -} - -void UpdateDisplay::confirm() -{ - if (const auto result = triggerOta(stringSettings.otaUrl); !result) - ESP_LOGE("BOBBY", "triggerOta() failed with %.*s", result.error().size(), result.error().data()); -} #endif -} diff --git a/main/ota.cpp b/main/ota.cpp index e69de29..1ec404d 100644 --- a/main/ota.cpp +++ b/main/ota.cpp @@ -0,0 +1,52 @@ +#include "ota.h" + +// esp-idf includes +#include + +// 3rdparty lib includes +#include + +#ifdef FEATURE_OTA +extern cpputils::DelayedConstruction asyncOta; +extern bool asyncOtaTaskStarted; + +namespace { +constexpr const char * const TAG = "BOBBYOTA"; +} // namespace + +void initOta() +{ +} + +void handleOta() +{ + if (asyncOta) + asyncOta->update(); +} + +tl::expected triggerOta(std::string_view url) +{ + ESP_LOGI(TAG, "%.*s", url.size(), url.data()); + + if (!asyncOta) + asyncOta.construct(); + + if (!asyncOtaTaskStarted) + { + if (const auto result = asyncOta->startTask(); !result) + { + ESP_LOGE(TAG, "starting OTA task failed: %.*s", result.error().size(), result.error().data()); + return tl::make_unexpected(fmt::format("starting OTA task failed: {}", result.error())); + } + + asyncOtaTaskStarted = true; + } + + if (const auto result = asyncOta->trigger(url, {}, {}, {}); !result) + return tl::make_unexpected(std::move(result).error()); + + wifi_stack::delete_scan_result(); + + return {}; +} +#endif diff --git a/main/ota.h b/main/ota.h index 233fca5..8ad7c47 100644 --- a/main/ota.h +++ b/main/ota.h @@ -8,45 +8,11 @@ // local includes -namespace { #ifdef FEATURE_OTA cpputils::DelayedConstruction asyncOta; bool asyncOtaTaskStarted{}; -void initOta() -{ -} - -void handleOta() -{ - if (asyncOta) - asyncOta->update(); -} - -tl::expected triggerOta(std::string_view url) -{ - ESP_LOGI(TAG, "%.*s", url.size(), url.data()); - - if (!asyncOta) - asyncOta.construct(); - - if (!asyncOtaTaskStarted) - { - if (const auto result = asyncOta->startTask(); !result) - { - ESP_LOGE(TAG, "starting OTA task failed: %.*s", result.error().size(), result.error().data()); - return tl::make_unexpected(fmt::format("starting OTA task failed: {}", result.error())); - } - - asyncOtaTaskStarted = true; - } - - if (const auto result = asyncOta->trigger(url, {}, {}, {}); !result) - return tl::make_unexpected(std::move(result).error()); - - wifi_stack::delete_scan_result(); - - return {}; -} +void initOta(); +void handleOta(); +tl::expected triggerOta(std::string_view url); #endif -} From d70a3aa73f56eae6b0cf77d41e29f2f3b2d286db Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Tue, 2 Nov 2021 22:47:46 +0100 Subject: [PATCH 06/10] Again refactorings more --- main/displays/ledstripcolorsdisplay.cpp | 240 ++++++++++++++++ main/displays/ledstripcolorsdisplay.h | 244 +--------------- main/displays/menus/commanddebugmenu.h | 5 - main/displays/menus/debugmenu.cpp | 59 ++++ main/displays/menus/debugmenu.h | 55 +--- main/displays/menus/dynamicdebugmenu.h | 5 - main/displays/menus/feedbackdebugmenu.h | 5 - main/displays/menus/ledstripmenu.cpp | 143 ++++++++++ main/displays/menus/ledstripmenu.h | 147 +--------- .../menus/ledstripselectanimationmenu.h | 4 - main/displays/menus/ledstripselectblinkmenu.h | 6 +- main/displays/menus/motorfeedbackdebugmenu.h | 5 - main/displays/menus/motorstatedebugmenu.h | 5 - main/displays/powersupplydisplay.cpp | 46 +++ main/displays/powersupplydisplay.h | 48 +--- main/esptexthelpers.h | 42 +-- main/ledstrip.cpp | 259 +++++++++++++++++ main/ledstrip.h | 264 +----------------- 18 files changed, 795 insertions(+), 787 deletions(-) diff --git a/main/displays/ledstripcolorsdisplay.cpp b/main/displays/ledstripcolorsdisplay.cpp index e69de29..87bdbbe 100644 --- a/main/displays/ledstripcolorsdisplay.cpp +++ b/main/displays/ledstripcolorsdisplay.cpp @@ -0,0 +1,240 @@ +#include "ledstripcolorsdisplay.h" + +// esp-idf includes +#include + +// 3rdparty lib includes +#include +#include +#include +#include +#include +#include +#include + +// local includes +#include "menudisplay.h" +#include "utils.h" +#include "icons/back.h" +#include "icons/bobbycar.h" +#include "texts.h" +#include "actions/dummyaction.h" +#include "globals.h" +#include "displays/menus/ledstripmenu.h" + +int8_t selected_side = 7; +int8_t selected_color; +bool state_select_color{false}; +bool last_state = {false}; + +const std::array Colors = { + CRGB{0,0,0}, + CRGB{255,255,255}, + CRGB{255,0,0}, + CRGB{255,255,0}, + CRGB{0,255,0}, + CRGB{0,255,255}, + CRGB{0,0,255}, + CRGB{255,0,255} +}; + +const std::array tft_colors = { + TFT_BLACK, + TFT_WHITE, + TFT_RED, + TFT_YELLOW, + TFT_GREEN, + TFT_CYAN, + TFT_BLUE, + TFT_MAGENTA +}; + +std::string LedstripColorsDisplay::text() const +{ + return TEXT_LEDSTRIPCOLORMENU; +} + +void LedstripColorsDisplay::back() +{ + if(!state_select_color) + { + espgui::switchScreen(); + } + else + { + state_select_color = false; + espgui::tft.fillRect(0, 228, espgui::tft.width(), ((espgui::tft.width() - 40) / 8) + 4, TFT_BLACK); + } +} + +void LedstripColorsDisplay::initScreen() +{ + Base::initScreen(); + + espgui::tft.setSwapBytes(true); + espgui::tft.pushImage(70, 60, bobbyicons::bobbycar.WIDTH, bobbyicons::bobbycar.HEIGHT, bobbyicons::bobbycar.buffer); + espgui::tft.setSwapBytes(false); +} + +void LedstripColorsDisplay::redraw() +{ + Base::redraw(); + + auto y_pos = ((espgui::tft.width() - 40) / 8 + 4) + 240; + if (last_state != state_select_color) + { + espgui::tft.fillRect(0,y_pos - 1, espgui::tft.width(), 20, TFT_BLACK); + last_state = state_select_color; + } + + espgui::tft.setTextFont(2); + espgui::tft.setTextColor(TFT_WHITE); + + espgui::tft.drawString(state_select_color ? + "Please select a color!" : + "Please select a side!", 50, y_pos); + + if (!already_drew_circle) + { + drawSide(static_cast(selected_side), TFT_GOLD); + already_drew_circle = true; + } +} + +void LedstripColorsDisplay::rotate(int offset) +{ + if (offset < 0) + { + if (state_select_color) + { + selected_color++; + if (selected_color > 7) + { + selected_color = 0; + } + } + else + { + selected_side++; + if (selected_side > 7) + { + selected_side = 0; + } + } + } + else if (offset > 0) + { + if (state_select_color) + { + selected_color--; + if (selected_color < 0) + { + selected_color = 7; + } + } + else + { + selected_side--; + if (selected_side < 0) + { + selected_side = 7; + } + } + } + + if (state_select_color) + { + drawColors(); + } + else + { + espgui::tft.fillRect(0, 228, espgui::tft.width(), ((espgui::tft.width() - 40) / 8) + 4, TFT_BLACK); + clearSides(); + drawSide(static_cast(selected_side), TFT_GOLD); + } +} + +void LedstripColorsDisplay::confirm() +{ + if(!state_select_color) + { + state_select_color = true; + drawColors(); + } + else + { + ledstrip_custom_colors[selected_side] = Colors[selected_color]; + // Uncomment to close select color menu on color select + /* + state_select_color = false; + espgui::tft.fillRect(0, 228, espgui::tft.width(), ((espgui::tft.width() - 40) / 8) + 4, TFT_BLACK); + */ + } +} + +void LedstripColorsDisplay::drawColors() +{ + uint16_t width = (espgui::tft.width() - 40); + auto cube_width = width / 8; + + espgui::tft.fillRect(0, 228, espgui::tft.width(), cube_width + 4, TFT_BLACK); + espgui::tft.fillRect(21, 231, width - 1, cube_width - 1, TFT_WHITE); + + espgui::tft.fillRect(20 + (selected_color * cube_width - 1), 228, cube_width + 4, cube_width + 4, TFT_YELLOW); + for (int index = 0; index < 8; index++) + { + auto offset = index * (cube_width); + espgui::tft.fillRect(22 + offset, 232, cube_width - 4, cube_width - 4, tft_colors[index]); + } +} + +void LedstripColorsDisplay::clearSides() +{ + for(int index = 0; index < 8; index++) + { + drawSide(static_cast(index), TFT_BLACK); + } +} + +void LedstripColorsDisplay::drawSide(Bobbycar_Side side, unsigned int color) +{ + const auto middle = espgui::tft.width() / 2; + const auto width = bobbyicons::bobbycar.WIDTH; + const auto height = bobbyicons::bobbycar.HEIGHT; + const auto left = middle - (width / 2); + const auto right = middle + (width / 2); + const auto above = 50; + const auto bellow = above + 10 + bobbyicons::bobbycar.HEIGHT; + + switch (side) { + case Bobbycar_Side::FRONT: + espgui::tft.fillRect(left, above, width, 5, color); + break; + case Bobbycar_Side::FRONT_LEFT: + espgui::tft.fillRect(left - 10, above + 10, 5, height / 2, color); + espgui::tft.fillRect(left, above, width / 2, 5, color); + break; + case Bobbycar_Side::LEFT: + espgui::tft.fillRect(left - 10, above + 10, 5, height, color); + break; + case Bobbycar_Side::BACK_LEFT: + espgui::tft.fillRect(left - 10, above + 10 + (height / 2), 5, height / 2, color); + espgui::tft.fillRect(left, bellow + 5, width / 2, 5, color); + break; + case Bobbycar_Side::BACK: + espgui::tft.fillRect(left, bellow + 5, width, 5, color); + break; + case Bobbycar_Side::BACK_RIGHT: + espgui::tft.fillRect(right + 5, above + 10 + (height / 2), 5, height / 2, color); + espgui::tft.fillRect(middle, bellow + 5, width / 2, 5, color); + break; + case Bobbycar_Side::RIGHT: + espgui::tft.fillRect(right + 5, above + 10, 5, height, color); + break; + case Bobbycar_Side::FRONT_RIGHT: + espgui::tft.fillRect(right + 5, above + 10, 5, height / 2, color); + espgui::tft.fillRect(middle, above, width / 2, 5, color); + break; + } + // espgui::tft.fillCircle(espgui::tft.width() / 2, 140, 100, TFT_BLACK); +} diff --git a/main/displays/ledstripcolorsdisplay.h b/main/displays/ledstripcolorsdisplay.h index db350a6..65fbcbd 100644 --- a/main/displays/ledstripcolorsdisplay.h +++ b/main/displays/ledstripcolorsdisplay.h @@ -1,57 +1,23 @@ #pragma once -// esp-idf includes -#include +// system includes +#include // 3rdparty lib includes -#include +#include #include -#include -#include -#include -#include // local includes -#include "menudisplay.h" -#include "utils.h" #include "ledstrip.h" -#include "icons/back.h" -#include "icons/bobbycar.h" -#include "texts.h" -#include "actions/dummyaction.h" -#include "globals.h" -namespace { -class LedstripMenu; -} +extern int8_t selected_side; +extern int8_t selected_color; +extern bool state_select_color; +extern bool last_state; -namespace { -static int8_t selected_side = 7; -static int8_t selected_color; -bool state_select_color{false}; -bool last_state = {false}; +extern const std::array Colors; -const std::array Colors = { - CRGB{0,0,0}, - CRGB{255,255,255}, - CRGB{255,0,0}, - CRGB{255,255,0}, - CRGB{0,255,0}, - CRGB{0,255,255}, - CRGB{0,0,255}, - CRGB{255,0,255} -}; - -const std::array tft_colors = { - TFT_BLACK, - TFT_WHITE, - TFT_RED, - TFT_YELLOW, - TFT_GREEN, - TFT_CYAN, - TFT_BLUE, - TFT_MAGENTA -}; +extern const std::array tft_colors; class LedstripColorsDisplay : public espgui::DisplayWithTitle { @@ -72,195 +38,3 @@ public: private: bool already_drew_circle{false}; }; - -std::string LedstripColorsDisplay::text() const -{ - return TEXT_LEDSTRIPCOLORMENU; -} - -void LedstripColorsDisplay::back() -{ - if(!state_select_color) - { - switchScreen(); - } - else - { - state_select_color = false; - tft.fillRect(0, 228, tft.width(), ((tft.width() - 40) / 8) + 4, TFT_BLACK); - } -} - -void LedstripColorsDisplay::initScreen() -{ - Base::initScreen(); - - tft.setSwapBytes(true); - tft.pushImage(70, 60, bobbyicons::bobbycar.WIDTH, bobbyicons::bobbycar.HEIGHT, bobbyicons::bobbycar.buffer); - tft.setSwapBytes(false); -} - -void LedstripColorsDisplay::redraw() -{ - Base::redraw(); - - auto y_pos = ((tft.width() - 40) / 8 + 4) + 240; - if (last_state != state_select_color) - { - tft.fillRect(0,y_pos - 1, tft.width(), 20, TFT_BLACK); - last_state = state_select_color; - } - - tft.setTextFont(2); - tft.setTextColor(TFT_WHITE); - - tft.drawString(state_select_color ? - "Please select a color!" : - "Please select a side!", 50, y_pos); - - if (!already_drew_circle) - { - drawSide(static_cast(selected_side), TFT_GOLD); - already_drew_circle = true; - } -} - -void LedstripColorsDisplay::rotate(int offset) -{ - if (offset < 0) - { - if (state_select_color) - { - selected_color++; - if (selected_color > 7) - { - selected_color = 0; - } - } - else - { - selected_side++; - if (selected_side > 7) - { - selected_side = 0; - } - } - } - else if (offset > 0) - { - if (state_select_color) - { - selected_color--; - if (selected_color < 0) - { - selected_color = 7; - } - } - else - { - selected_side--; - if (selected_side < 0) - { - selected_side = 7; - } - } - } - - if (state_select_color) - { - drawColors(); - } - else - { - tft.fillRect(0, 228, tft.width(), ((tft.width() - 40) / 8) + 4, TFT_BLACK); - clearSides(); - drawSide(static_cast(selected_side), TFT_GOLD); - } -} - -void LedstripColorsDisplay::confirm() -{ - if(!state_select_color) - { - state_select_color = true; - drawColors(); - } - else - { - ledstrip_custom_colors[selected_side] = Colors[selected_color]; - // Uncomment to close select color menu on color select - /* - state_select_color = false; - tft.fillRect(0, 228, tft.width(), ((tft.width() - 40) / 8) + 4, TFT_BLACK); - */ - } -} - -void LedstripColorsDisplay::drawColors() -{ - uint16_t width = (tft.width() - 40); - auto cube_width = width / 8; - - tft.fillRect(0, 228, tft.width(), cube_width + 4, TFT_BLACK); - tft.fillRect(21, 231, width - 1, cube_width - 1, TFT_WHITE); - - tft.fillRect(20 + (selected_color * cube_width - 1), 228, cube_width + 4, cube_width + 4, TFT_YELLOW); - for (int index = 0; index < 8; index++) - { - auto offset = index * (cube_width); - tft.fillRect(22 + offset, 232, cube_width - 4, cube_width - 4, tft_colors[index]); - } -} - -void LedstripColorsDisplay::clearSides() -{ - for(int index = 0; index < 8; index++) - { - drawSide(static_cast(index), TFT_BLACK); - } -} - -void LedstripColorsDisplay::drawSide(Bobbycar_Side side, unsigned int color) -{ - const auto middle = tft.width() / 2; - const auto width = bobbyicons::bobbycar.WIDTH; - const auto height = bobbyicons::bobbycar.HEIGHT; - const auto left = middle - (width / 2); - const auto right = middle + (width / 2); - const auto above = 50; - const auto bellow = above + 10 + bobbyicons::bobbycar.HEIGHT; - - switch (side) { - case Bobbycar_Side::FRONT: - tft.fillRect(left, above, width, 5, color); - break; - case Bobbycar_Side::FRONT_LEFT: - tft.fillRect(left - 10, above + 10, 5, height / 2, color); - tft.fillRect(left, above, width / 2, 5, color); - break; - case Bobbycar_Side::LEFT: - tft.fillRect(left - 10, above + 10, 5, height, color); - break; - case Bobbycar_Side::BACK_LEFT: - tft.fillRect(left - 10, above + 10 + (height / 2), 5, height / 2, color); - tft.fillRect(left, bellow + 5, width / 2, 5, color); - break; - case Bobbycar_Side::BACK: - tft.fillRect(left, bellow + 5, width, 5, color); - break; - case Bobbycar_Side::BACK_RIGHT: - tft.fillRect(right + 5, above + 10 + (height / 2), 5, height / 2, color); - tft.fillRect(middle, bellow + 5, width / 2, 5, color); - break; - case Bobbycar_Side::RIGHT: - tft.fillRect(right + 5, above + 10, 5, height, color); - break; - case Bobbycar_Side::FRONT_RIGHT: - tft.fillRect(right + 5, above + 10, 5, height / 2, color); - tft.fillRect(middle, above, width / 2, 5, color); - break; - } - // tft.fillCircle(tft.width() / 2, 140, 100, TFT_BLACK); -} - -} // Namespace diff --git a/main/displays/menus/commanddebugmenu.h b/main/displays/menus/commanddebugmenu.h index e751a63..e264a2b 100644 --- a/main/displays/menus/commanddebugmenu.h +++ b/main/displays/menus/commanddebugmenu.h @@ -10,11 +10,6 @@ #include "texts.h" #include "debugtexthelpers.h" -// forward declares -namespace { -class DebugMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/debugmenu.cpp b/main/displays/menus/debugmenu.cpp index e69de29..8b065e6 100644 --- a/main/displays/menus/debugmenu.cpp +++ b/main/displays/menus/debugmenu.cpp @@ -0,0 +1,59 @@ +#include "debugmenu.h" + +// 3rdparty lib includes +#include "menuitem.h" +#include "actions/switchscreenaction.h" +#include "actions/dummyaction.h" +#include "actions/toggleboolaction.h" +#include "checkboxicon.h" +#include "icons/back.h" + +// local includes +#include "utils.h" +#include "actions/loadsettingsaction.h" +#include "actions/savesettingsaction.h" +#include "actions/erasenvsaction.h" +#include "icons/lock.h" +#include "debugcolorhelpers.h" +#include "esptexthelpers.h" +#include "displays/menus/commanddebugmenu.h" +#include "displays/menus/motorstatedebugmenu.h" +#include "displays/menus/feedbackdebugmenu.h" +#include "displays/menus/motorfeedbackdebugmenu.h" +#include "displays/menus/dynamicdebugmenu.h" +#include "displays/menus/mainmenu.h" + +using namespace espgui; + +DebugMenu::DebugMenu() +{ + constructMenuItem, LoadSettingsAction>>(); + constructMenuItem, SaveSettingsAction>>(); + constructMenuItem, EraseNvsAction>>(); + constructMenuItem>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem>(); + constructMenuItem, SwitchScreenAction, FrontFeedbackColor>>(); + constructMenuItem, SwitchScreenAction, BackFeedbackColor>>(); + constructMenuItem>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem>(); + constructMenuItem, SwitchScreenAction, FrontFeedbackColor>>(); + constructMenuItem, SwitchScreenAction, FrontFeedbackColor>>(); + constructMenuItem, SwitchScreenAction, BackFeedbackColor>>(); + constructMenuItem, SwitchScreenAction, BackFeedbackColor>>(); + constructMenuItem>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void DebugMenu::back() +{ + switchScreen(); +} diff --git a/main/displays/menus/debugmenu.h b/main/displays/menus/debugmenu.h index 2ae7392..8aeb2a2 100644 --- a/main/displays/menus/debugmenu.h +++ b/main/displays/menus/debugmenu.h @@ -1,56 +1,17 @@ #pragma once -// local includes +// 3rdparty lib includes #include "menudisplay.h" -#include "utils.h" -#include "menuitem.h" -#include "actions/loadsettingsaction.h" -#include "actions/savesettingsaction.h" -#include "actions/erasenvsaction.h" -#include "actions/switchscreenaction.h" -#include "actions/dummyaction.h" -#include "actions/toggleboolaction.h" -#include "icons/lock.h" -#include "checkboxicon.h" -#include "icons/back.h" + +// local includes #include "texts.h" -#include "debugcolorhelpers.h" -using namespace espgui; - -namespace { class DebugMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - DebugMenu() - { - constructMenuItem, LoadSettingsAction>>(); - constructMenuItem, SaveSettingsAction>>(); - constructMenuItem, EraseNvsAction>>(); - constructMenuItem>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem>(); - constructMenuItem, SwitchScreenAction, FrontFeedbackColor>>(); - constructMenuItem, SwitchScreenAction, BackFeedbackColor>>(); - constructMenuItem>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem>(); - constructMenuItem, SwitchScreenAction, FrontFeedbackColor>>(); - constructMenuItem, SwitchScreenAction, FrontFeedbackColor>>(); - constructMenuItem, SwitchScreenAction, BackFeedbackColor>>(); - constructMenuItem, SwitchScreenAction, BackFeedbackColor>>(); - constructMenuItem>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + DebugMenu(); + + void back() override; }; -} // namespace diff --git a/main/displays/menus/dynamicdebugmenu.h b/main/displays/menus/dynamicdebugmenu.h index 7b125a9..470464b 100644 --- a/main/displays/menus/dynamicdebugmenu.h +++ b/main/displays/menus/dynamicdebugmenu.h @@ -22,11 +22,6 @@ #include "icons/back.h" #include "texts.h" -// forward declares -namespace { -class DebugMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/feedbackdebugmenu.h b/main/displays/menus/feedbackdebugmenu.h index b9c4b30..5e1fb06 100644 --- a/main/displays/menus/feedbackdebugmenu.h +++ b/main/displays/menus/feedbackdebugmenu.h @@ -11,11 +11,6 @@ #include "debugtexthelpers.h" #include "debugcolorhelpers.h" -// forward declares -namespace { -class DebugMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/ledstripmenu.cpp b/main/displays/menus/ledstripmenu.cpp index e69de29..271c308 100644 --- a/main/displays/menus/ledstripmenu.cpp +++ b/main/displays/menus/ledstripmenu.cpp @@ -0,0 +1,143 @@ +#include "ledstripmenu.h" + +// 3rdparty lib includes +#include +#include "menuitem.h" +#include "actions/toggleboolaction.h" +#include "actions/switchscreenaction.h" +#include "icons/back.h" +#include "checkboxicon.h" +#include "changevaluedisplay.h" +#include "actioninterface.h" + +// local includes +#include "ledstripselectanimationmenu.h" +#include "ledstripselectblinkmenu.h" +#include "globals.h" +#include "accessors/settingsaccessors.h" +#ifdef FEATURE_LEDSTRIP +#include "ledstrip.h" +#endif +#include "displays/ledstripcolorsdisplay.h" +#include "displays/menus/mainmenu.h" + +#ifdef FEATURE_LEDSTRIP +namespace { +using LedsCountChangeScreen = makeComponent< + ChangeValueDisplay, + StaticText, + LedsCountAccessor, + BackActionInterface>, + SwitchScreenAction +>; + +using CenterOffsetChangeScreen = makeComponent< + ChangeValueDisplay, + StaticText, + CenterOffsetAccessor, + BackActionInterface>, + SwitchScreenAction +>; + +using SmallOffsetChangeScreen = makeComponent< + ChangeValueDisplay, + StaticText, + SmallOffsetAccessor, + BackActionInterface>, + SwitchScreenAction +>; + +using BigOffsetChangeScreen = makeComponent< + ChangeValueDisplay, + StaticText, + BigOffsetAccessor, + BackActionInterface>, + SwitchScreenAction +>; + +using DeziampereChangeScreen = makeComponent< + ChangeValueDisplay, + StaticText, + DeziampereAccessor, + BackActionInterface>, + SwitchScreenAction +>; + +using StVOOffsetChangeScreen = makeComponent< + ChangeValueDisplay, + StaticText, + LedsStVOFrontOffsetAccessor, + BackActionInterface>, + SwitchScreenAction +>; + +using StVOLengthChangeScreen = makeComponent< + ChangeValueDisplay, + StaticText, + LedsStVOFrontLengthAccessor, + BackActionInterface>, + SwitchScreenAction +>; + +using animationMultiplierChangeScreen = makeComponent< + ChangeValueDisplay, + StaticText, + AnimationMultiplierAccessor, + BackActionInterface>, + SwitchScreenAction +>; + +using ledstripBrightnessChangeScreen = makeComponent< + ChangeValueDisplay, + StaticText, + LedstripBrightnessAccessor, + BackActionInterface>, + SwitchScreenAction +>; + +class AllCustomLedsOffAction : public virtual ActionInterface +{ +public: + void triggered() override + { + for(int index = 0; index < 8; index++) + { + ledstrip_custom_colors[index] = CRGB{0,0,0}; + } + } +}; +} // namespace + +using namespace espgui; + +LedstripMenu::LedstripMenu() +{ + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableLedAnimationAccessor>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableBrakeLightsAccessor>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableBeepWhenBlinkAccessor>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableFullBlinkAccessor>>(); + + if (!simplified) { constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableLedstripStVOAccessor>>(); } + constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableLedstripStVOFrontlight>>(); + constructMenuItem, AllCustomLedsOffAction>>(); + if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } + if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } + + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } + if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } + if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } + if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } + if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } + if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); +} + +void LedstripMenu::back() +{ + switchScreen(); +} +#endif diff --git a/main/displays/menus/ledstripmenu.h b/main/displays/menus/ledstripmenu.h index c2e44a2..d093463 100644 --- a/main/displays/menus/ledstripmenu.h +++ b/main/displays/menus/ledstripmenu.h @@ -1,152 +1,19 @@ #pragma once -#include +// 3rdparty lib includes +#include "menudisplay.h" // local includes -#include "menudisplay.h" -#include "menuitem.h" -#include "actions/toggleboolaction.h" -#include "actions/switchscreenaction.h" -#include "ledstripselectanimationmenu.h" -#include "ledstripselectblinkmenu.h" #include "texts.h" -#include "icons/back.h" -#include "checkboxicon.h" -#include "globals.h" -#include "accessors/settingsaccessors.h" + #ifdef FEATURE_LEDSTRIP -#include "ledstrip.h" -#endif -#include "changevaluedisplay.h" -#include "actioninterface.h" - -// forward declares -namespace { -class MainWindow; -class LedstripColorsDisplay; -} // namespace - -using namespace espgui; - -namespace { -#ifdef FEATURE_LEDSTRIP -class LedstripMenu; -class LedstripSelectAnimationMenu; - -using LedsCountChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - LedsCountAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -using CenterOffsetChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - CenterOffsetAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -using SmallOffsetChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - SmallOffsetAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -using BigOffsetChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - BigOffsetAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -using DeziampereChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - DeziampereAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -using StVOOffsetChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - LedsStVOFrontOffsetAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -using StVOLengthChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - LedsStVOFrontLengthAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -using animationMultiplierChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - AnimationMultiplierAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -using ledstripBrightnessChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - LedstripBrightnessAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -class AllCustomLedsOffAction : public virtual ActionInterface -{ -public: - void triggered() { - for(int index = 0; index < 8; index++) - { - ledstrip_custom_colors[index] = CRGB{0,0,0}; - } - } -}; - class LedstripMenu : - public MenuDisplay, - public StaticText, - public BackActionInterface> + public espgui::MenuDisplay, + public espgui::StaticText { public: - LedstripMenu() - { - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableLedAnimationAccessor>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableBrakeLightsAccessor>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableBeepWhenBlinkAccessor>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableFullBlinkAccessor>>(); + LedstripMenu(); - if (!simplified) { constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableLedstripStVOAccessor>>(); } - constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableLedstripStVOFrontlight>>(); - constructMenuItem, AllCustomLedsOffAction>>(); - if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } - if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } - - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } - if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } - if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } - if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } - if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } - if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + void back() override; }; #endif -} // namespace diff --git a/main/displays/menus/ledstripselectanimationmenu.h b/main/displays/menus/ledstripselectanimationmenu.h index df731a7..4a22635 100644 --- a/main/displays/menus/ledstripselectanimationmenu.h +++ b/main/displays/menus/ledstripselectanimationmenu.h @@ -32,10 +32,6 @@ class currentSelectedAnimationText : public virtual TextInterface { public: std: using namespace espgui; -namespace { - class LedstripMenu; -} - namespace { class LedstripSelectAnimationMenu : public MenuDisplay, diff --git a/main/displays/menus/ledstripselectblinkmenu.h b/main/displays/menus/ledstripselectblinkmenu.h index 06122e4..cbb862a 100644 --- a/main/displays/menus/ledstripselectblinkmenu.h +++ b/main/displays/menus/ledstripselectblinkmenu.h @@ -37,11 +37,7 @@ class currentSelectedBlinkAnimationText : public virtual TextInterface { public: using namespace espgui; -namespace { - class LedstripMenu; -} - -namespace { +namespace { class LedstripSelectBlinkMenu : public MenuDisplay, public StaticText, diff --git a/main/displays/menus/motorfeedbackdebugmenu.h b/main/displays/menus/motorfeedbackdebugmenu.h index c1a2c70..d3d6a4a 100644 --- a/main/displays/menus/motorfeedbackdebugmenu.h +++ b/main/displays/menus/motorfeedbackdebugmenu.h @@ -11,11 +11,6 @@ #include "debugtexthelpers.h" #include "debugcolorhelpers.h" -// forward declares -namespace { -class DebugMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/menus/motorstatedebugmenu.h b/main/displays/menus/motorstatedebugmenu.h index 378b1a1..ff591d5 100644 --- a/main/displays/menus/motorstatedebugmenu.h +++ b/main/displays/menus/motorstatedebugmenu.h @@ -10,11 +10,6 @@ #include "texts.h" #include "debugtexthelpers.h" -// forward declares -namespace { -class DebugMenu; -} // namespace - using namespace espgui; namespace { diff --git a/main/displays/powersupplydisplay.cpp b/main/displays/powersupplydisplay.cpp index e69de29..5ed8339 100644 --- a/main/displays/powersupplydisplay.cpp +++ b/main/displays/powersupplydisplay.cpp @@ -0,0 +1,46 @@ +#include "powersupplydisplay.h" + +// 3rdparty lib includes +#include +#include +#include "actions/switchscreenaction.h" + +// local includes +#include "globals.h" +#include "displays/menus/mainmenu.h" + +#if defined(FEATURE_CAN) && defined(FEATURE_POWERSUPPLY) +void PowerSupplyDisplay::initScreen() +{ + espgui::tft.fillScreen(TFT_BLACK); + espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK); + + espgui::tft.setTextFont(4); + + espgui::tft.drawString("Voltage:", 0, m_voltageLabel.y()); + m_voltageLabel.start(); + espgui::tft.drawString("Current:", 0, m_currentLabel.y()); + m_currentLabel.start(); +} + +void PowerSupplyDisplay::redraw() +{ + m_voltageLabel.redraw(std::to_string(50.4) + 'V'); + m_currentLabel.redraw(std::to_string(15.1) + 'A'); +} + +void PowerSupplyDisplay::confirm() +{ + // TODO +} + +void PowerSupplyDisplay::back() +{ + espgui::switchScreen(); +} + +void PowerSupplyDisplay::rotate(int offset) +{ + // TODO +} +#endif diff --git a/main/displays/powersupplydisplay.h b/main/displays/powersupplydisplay.h index be38517..afe7ba9 100644 --- a/main/displays/powersupplydisplay.h +++ b/main/displays/powersupplydisplay.h @@ -1,56 +1,24 @@ #pragma once -// Arduino includes -#include - -// local includes +// 3rdparty lib includes #include "display.h" -#include "actions/switchscreenaction.h" -#include "globals.h" #include "widgets/label.h" -namespace { #if defined(FEATURE_CAN) && defined(FEATURE_POWERSUPPLY) -class PowerSupplyDisplay : public Display, public DummyConfirm, public BackActionInterface> +class PowerSupplyDisplay : public espgui::Display { + using Base = espgui::Display; + public: void initScreen() override; void redraw() override; void confirm() override; + void back() override; + void rotate(int offset) override; - Label m_voltageLabel{120, 50}; - Label m_currentLabel{120, 75}; + espgui::Label m_voltageLabel{120, 50}; + espgui::Label m_currentLabel{120, 75}; }; - -void PowerSupplyDisplay::initScreen() -{ - tft.fillScreen(TFT_BLACK); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - - tft.setTextFont(4); - - tft.drawString("Voltage:", 0, m_voltageLabel.y()); - m_voltageLabel.start(); - tft.drawString("Current:", 0, m_currentLabel.y()); - m_currentLabel.start(); -} - -void PowerSupplyDisplay::redraw() -{ - m_voltageLabel.redraw(std::to_string(50.4) + 'V'); - m_currentLabel.redraw(std::to_string(15.1) + 'A'); -} - -void PowerSupplyDisplay::confirm() -{ - // TODO -} - -void PowerSupplyDisplay::rotate(int offset) -{ - // TODO -} #endif -} diff --git a/main/esptexthelpers.h b/main/esptexthelpers.h index b5a47ee..d312f63 100644 --- a/main/esptexthelpers.h +++ b/main/esptexthelpers.h @@ -5,6 +5,7 @@ // 3rdparty lib includes #include +#include // local includes #include "textinterface.h" @@ -37,46 +38,7 @@ class HeapLargest32Text : public virtual espgui::TextInterface { public: std::st return fmt::format("HeapLargest32: {}", heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL|MALLOC_CAP_32BIT)); }}; class LastRebootReasonText : public virtual espgui::TextInterface { public: std::string text() const override { - std::string reset_reason_string; - switch (esp_reset_reason()) { - case 0: - reset_reason_string = "Unkown"; - break; - case 1: - reset_reason_string = "Power on"; - break; - case 2: - reset_reason_string = "External Pin"; - break; - case 3: - reset_reason_string = "esp_restart"; - break; - case 4: - reset_reason_string = "Exception/panic"; - break; - case 5: - reset_reason_string = "Interrupt wd"; - break; - case 6: - reset_reason_string = "Task wd"; - break; - case 7: - reset_reason_string = "Other wd"; - break; - case 8: - reset_reason_string = "Deepsleep"; - break; - case 9: - reset_reason_string = "Brownout"; - break; - case 10: - reset_reason_string = "SDIO"; - break; - default: - return fmt::format("Last Reboot Reason: {}", esp_reset_reason()); - } - - return fmt::format("Last Reboot Reason: {}", reset_reason_string); }}; + return fmt::format("Last Reboot Reason: {}", espcpputils::toString(esp_reset_reason())); }}; constexpr char TEXT_ESPCHIPREVISION[] = "Chip revision: "; using EspChipRevisionText = espgui::StaticText; //EspStatusTextHelper; diff --git a/main/ledstrip.cpp b/main/ledstrip.cpp index e69de29..3264dba 100644 --- a/main/ledstrip.cpp +++ b/main/ledstrip.cpp @@ -0,0 +1,259 @@ +#include "ledstrip.h" + +// 3rdparty lib includes + +// local includes +#include "globals.h" +#include "cpputils.h" +#include "espchrono.h" +#include "ledstripdefines.h" + +using namespace std::chrono_literals; + +#ifdef FEATURE_LEDSTRIP +std::vector leds; +uint8_t gHue = 0; + +int16_t blinkAnimation = LEDSTRIP_OVERWRITE_NONE; +int16_t animation_type = LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW; + + +void initLedStrip() +{ + animation_type = settings.ledstrip.animationType; + leds.resize(settings.ledstrip.ledsCount); + FastLED.addLeds(&*std::begin(leds), leds.size()) + .setCorrection(TypicalSMD5050); +} + +void updateLedStrip() +{ + EVERY_N_MILLISECONDS( 20 ) { gHue++; } + static bool have_disabled_beeper = false; + + if (cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH)) + { + std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0}); + if (espchrono::millis_clock::now().time_since_epoch() % 750ms < 375ms) + { + if (settings.ledstrip.enableBeepWhenBlink) + { + for (Controller &controller : controllers) + controller.command.buzzer.freq = 3; + } + auto color = CRGB{255, 255, 0}; + const auto center = (std::begin(leds) + (leds.size() / 2) + settings.ledstrip.centerOffset); + + if (blinkAnimation != LEDSTRIP_OVERWRITE_BLINKRIGHT && !settings.ledstrip.enableFullBlink) + { + std::fill(center - settings.ledstrip.bigOffset, center - settings.ledstrip.smallOffset, color); + } + else if(blinkAnimation != LEDSTRIP_OVERWRITE_BLINKRIGHT && settings.ledstrip.enableFullBlink) + { + std::fill(std::begin(leds), center, color); + } + if (blinkAnimation != LEDSTRIP_OVERWRITE_BLINKLEFT && !settings.ledstrip.enableFullBlink) + { + std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color); + } + else if(blinkAnimation != LEDSTRIP_OVERWRITE_BLINKLEFT && settings.ledstrip.enableFullBlink) + { + std::fill(center, std::end(leds), color); + } + + } else { + if (settings.ledstrip.enableBeepWhenBlink) + { + for (Controller &controller : controllers) + controller.command.buzzer.freq = 0; + } + } + } + else + { + if (settings.ledstrip.enableBrakeLights) + { + float avgPwm{}; + for (const Controller &controller : controllers) + { + avgPwm += + controller.command.left.pwm * (controller.invertLeft ? -1 : 1) + + controller.command.right.pwm * (controller.invertRight ? -1 : 1); + } + avgPwm /= 4; + + if (avgPwm < -1.f) + { + auto color = avgSpeedKmh < -0.1f ? CRGB{255, 255, 255} : CRGB{255, 0, 0}; + + const auto center = (std::begin(leds) + (leds.size() / 2) + settings.ledstrip.centerOffset); + + std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0}); + if (settings.ledstrip.enableFullBlink) + { + std::fill(std::begin(leds), std::end(leds), color); + } + else + { + std::fill(center - settings.ledstrip.bigOffset, center - settings.ledstrip.smallOffset, color); + std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color); + } + } + else + { + showAnimation(); + } + } + else + { + showAnimation(); + } + } + + if (have_disabled_beeper == false && (!(cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH)) || !settings.ledstrip.enableBeepWhenBlink)) + { + for (Controller &controller : controllers) + controller.command.buzzer.freq = 0; + have_disabled_beeper = true; + } + else if ((cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH)) && settings.ledstrip.enableBeepWhenBlink) have_disabled_beeper = false; + + if (simplified || settings.ledstrip.enableStVO) + { + const auto center = (std::begin(leds) + (leds.size() / 2) + settings.ledstrip.centerOffset); + + if (!(blinkAnimation == LEDSTRIP_OVERWRITE_BLINKLEFT || blinkAnimation == LEDSTRIP_OVERWRITE_BLINKBOTH) || !(espchrono::millis_clock::now().time_since_epoch() % 750ms < 375ms) || settings.ledstrip.enableFullBlink) // Condition for right + { + std::fill(center - settings.ledstrip.bigOffset, center - settings.ledstrip.smallOffset, CRGB{0, 0, 0}); + std::fill(center - settings.ledstrip.bigOffset - 1U, center - settings.ledstrip.smallOffset - 1U, CRGB{255, 0, 0}); // Right + } + if (!(blinkAnimation == LEDSTRIP_OVERWRITE_BLINKRIGHT || blinkAnimation == LEDSTRIP_OVERWRITE_BLINKBOTH) || !(espchrono::millis_clock::now().time_since_epoch() % 750ms < 375ms) || settings.ledstrip.enableFullBlink) // Condition for left + { + std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, CRGB{0, 0, 0}); + std::fill(center + settings.ledstrip.smallOffset + 1U, center + settings.ledstrip.bigOffset + 1U, CRGB{255, 0, 0}); // Left + } + + if (settings.ledstrip.stvoFrontEnable) + { + std::fill(std::begin(leds) + settings.ledstrip.stvoFrontOffset, std::begin(leds) + settings.ledstrip.stvoFrontOffset + settings.ledstrip.stvoFrontLength, CRGB{255, 255, 255}); + std::fill(std::end(leds) - settings.ledstrip.stvoFrontOffset - settings.ledstrip.stvoFrontLength, std::end(leds) - settings.ledstrip.stvoFrontOffset, CRGB{255, 255, 255}); + } + } + + FastLED.setMaxPowerInVoltsAndMilliamps(5,settings.ledstrip.deziampere * 100); + FastLED.setBrightness(settings.ledstrip.brightness); + FastLED.show(); +} + +void showAnimation() +{ + if (settings.ledstrip.enableLedAnimation && !simplified) + { + if (animation_type == LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW) showDefaultLedstrip(); + else if (animation_type == LEDSTRIP_ANIMATION_TYPE_BETTERRAINBOW) showBetterRainbow(); + else if (animation_type == LEDSTRIP_ANIMATION_TYPE_SPEEDSYNCANIMATION) showSpeedSyncAnimation(); + else if (animation_type == LEDSTRIP_ANIMATION_TYPE_CUSTOMCOLOR) showCustomColor(); + else showDefaultLedstrip(); + } + else + { + std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0}); + } +} + +void showBetterRainbow() +{ + fill_rainbow(&*std::begin(leds), leds.size(), gHue); +} + +void fill_rainbow_invert_at( struct CRGB * pFirstLED, int numToFill, int invertAtLed, + uint8_t initialhue, + float deltahue ) +{ + float huecalc = initialhue; + CHSV hsv; + hsv.hue = initialhue; + hsv.val = 255; + hsv.sat = 240; + for( int i = 0; i < numToFill; i++) { + hsv.hue = huecalc; + pFirstLED[i] = hsv; + if(i>invertAtLed){ + huecalc -= deltahue; + }else{ + huecalc += deltahue; + } + } +} + +void showSpeedSyncAnimation() +{ +#ifdef LEDS_PER_METER + const float leds_per_meter = LEDS_PER_METER; +#else + const float leds_per_meter = 144; +#endif + + static auto last_interval = espchrono::millis_clock::now(); + auto difference_ms = espchrono::ago(last_interval).count(); + + static float hue_result = 0; + + const float hue_per_led = 1. / std::max(uint8_t(1), uint8_t(settings.ledstrip.animationMultiplier)); + const float meter_per_second = avgSpeedKmh / 3.6; + const float leds_per_second = meter_per_second * leds_per_meter; + const float hue_per_second = leds_per_second * hue_per_led; + + hue_result += hue_per_second * difference_ms / 1000.f; + + fill_rainbow_invert_at(&*std::begin(leds), leds.size(),leds.size()/2, hue_result,-hue_per_led); + + last_interval = espchrono::millis_clock::now(); +} + +void showDefaultLedstrip() +{ + fadeToBlackBy(&*std::begin(leds), leds.size(), 20); + + uint8_t dothue = 0; + for (int i = 0; i < 8; i++) + { + leds[beatsin16(i + 7, 0, leds.size())] |= CHSV(dothue, 200, 255); + dothue += 32; + } +} + +void showCustomColor() +{ + const auto eighth_length = leds.size() / 8; + const auto center = (std::begin(leds) + (leds.size() / 2) + settings.ledstrip.centerOffset); + + std::fill(std::begin(leds), std::end(leds), ledstrip_custom_colors[int(Bobbycar_Side::FRONT)]); // Front + std::fill(center - (eighth_length / 2), center + (eighth_length / 2), ledstrip_custom_colors[int(Bobbycar_Side::BACK)]); // Back + +#ifdef LEDSTRIP_WRONG_DIRECTION + std::fill(center + (eighth_length / 2), center + (eighth_length / 2) + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::BACK_LEFT)]); // Back Left + std::fill(center - (eighth_length / 2) - eighth_length, center - (eighth_length / 2), ledstrip_custom_colors[int(Bobbycar_Side::BACK_RIGHT)]); // Back Right +#else + std::fill(center + (eighth_length / 2), center + (eighth_length / 2) + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::BACK_RIGHT)]); // Back Right + std::fill(center - (eighth_length / 2) - eighth_length, center - (eighth_length / 2), ledstrip_custom_colors[int(Bobbycar_Side::BACK_LEFT)]); // Back Left +#endif + +#ifdef LEDSTRIP_WRONG_DIRECTION + std::fill(center + (eighth_length / 2) + eighth_length, center + (eighth_length / 2) + eighth_length + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::LEFT)]); // Left + std::fill(center - (eighth_length / 2) - eighth_length - eighth_length, center - (eighth_length / 2) - eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::RIGHT)]); // Right +#else + std::fill(center + (eighth_length / 2) + eighth_length, center + (eighth_length / 2) + eighth_length + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::RIGHT)]); // Right + std::fill(center - (eighth_length / 2) - eighth_length - eighth_length, center - (eighth_length / 2) - eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::LEFT)]); // Left +#endif + +#ifdef LEDSTRIP_WRONG_DIRECTION + std::fill(center + (eighth_length / 2) + eighth_length + eighth_length, center + (eighth_length / 2) + eighth_length + eighth_length + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::FRONT_LEFT)]); // Front Left + std::fill(center - (eighth_length / 2) - eighth_length - eighth_length - eighth_length, center - (eighth_length / 2) - eighth_length - eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::FRONT_RIGHT)]); // Front Right +#else + std::fill(center + (eighth_length / 2) + eighth_length + eighth_length, center + (eighth_length / 2) + eighth_length + eighth_length + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::FRONT_RIGHT)]); // Front Right + std::fill(center - (eighth_length / 2) - eighth_length - eighth_length - eighth_length, center - (eighth_length / 2) - eighth_length - eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::FRONT_LEFT)]); // Front Left +#endif +} + +#endif diff --git a/main/ledstrip.h b/main/ledstrip.h index 25f84ef..aea82f8 100644 --- a/main/ledstrip.h +++ b/main/ledstrip.h @@ -1,19 +1,14 @@ #pragma once -#ifdef FEATURE_LEDSTRIP + +// system includes +#include + // 3rdparty lib includes #include -// local includes -#include "globals.h" -#include "cpputils.h" -#include "espchrono.h" -#include "ledstripdefines.h" - -using namespace std::chrono_literals; - -namespace { - -enum Bobbycar_Side { +#ifdef FEATURE_LEDSTRIP +enum Bobbycar_Side +{ FRONT_RIGHT, RIGHT, BACK_RIGHT, @@ -24,11 +19,11 @@ enum Bobbycar_Side { FRONT }; -std::vector leds; -uint8_t gHue = 0; +extern std::vector leds; +extern uint8_t gHue; -int16_t blinkAnimation = LEDSTRIP_OVERWRITE_NONE; -int16_t animation_type = LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW; +extern int16_t blinkAnimation; +extern int16_t animation_type; void showDefaultLedstrip(); void showAnimation(); @@ -36,240 +31,7 @@ void showBetterRainbow(); void showSpeedSyncAnimation(); void showCustomColor(); -void initLedStrip() -{ - animation_type = settings.ledstrip.animationType; - leds.resize(settings.ledstrip.ledsCount); - FastLED.addLeds(&*std::begin(leds), leds.size()) - .setCorrection(TypicalSMD5050); -} +void initLedStrip(); -void updateLedStrip() -{ - EVERY_N_MILLISECONDS( 20 ) { gHue++; } - static bool have_disabled_beeper = false; - - if (cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH)) - { - std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0}); - if (espchrono::millis_clock::now().time_since_epoch() % 750ms < 375ms) - { - if (settings.ledstrip.enableBeepWhenBlink) - { - for (Controller &controller : controllers) - controller.command.buzzer.freq = 3; - } - auto color = CRGB{255, 255, 0}; - const auto center = (std::begin(leds) + (leds.size() / 2) + settings.ledstrip.centerOffset); - - if (blinkAnimation != LEDSTRIP_OVERWRITE_BLINKRIGHT && !settings.ledstrip.enableFullBlink) - { - std::fill(center - settings.ledstrip.bigOffset, center - settings.ledstrip.smallOffset, color); - } - else if(blinkAnimation != LEDSTRIP_OVERWRITE_BLINKRIGHT && settings.ledstrip.enableFullBlink) - { - std::fill(std::begin(leds), center, color); - } - if (blinkAnimation != LEDSTRIP_OVERWRITE_BLINKLEFT && !settings.ledstrip.enableFullBlink) - { - std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color); - } - else if(blinkAnimation != LEDSTRIP_OVERWRITE_BLINKLEFT && settings.ledstrip.enableFullBlink) - { - std::fill(center, std::end(leds), color); - } - - } else { - if (settings.ledstrip.enableBeepWhenBlink) - { - for (Controller &controller : controllers) - controller.command.buzzer.freq = 0; - } - } - } - else - { - if (settings.ledstrip.enableBrakeLights) - { - float avgPwm{}; - for (const Controller &controller : controllers) - { - avgPwm += - controller.command.left.pwm * (controller.invertLeft ? -1 : 1) + - controller.command.right.pwm * (controller.invertRight ? -1 : 1); - } - avgPwm /= 4; - - if (avgPwm < -1.f) - { - auto color = avgSpeedKmh < -0.1f ? CRGB{255, 255, 255} : CRGB{255, 0, 0}; - - const auto center = (std::begin(leds) + (leds.size() / 2) + settings.ledstrip.centerOffset); - - std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0}); - if (settings.ledstrip.enableFullBlink) - { - std::fill(std::begin(leds), std::end(leds), color); - } - else - { - std::fill(center - settings.ledstrip.bigOffset, center - settings.ledstrip.smallOffset, color); - std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color); - } - } - else - { - showAnimation(); - } - } - else - { - showAnimation(); - } - } - - if (have_disabled_beeper == false && (!(cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH)) || !settings.ledstrip.enableBeepWhenBlink)) - { - for (Controller &controller : controllers) - controller.command.buzzer.freq = 0; - have_disabled_beeper = true; - } - else if ((cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH)) && settings.ledstrip.enableBeepWhenBlink) have_disabled_beeper = false; - - if (simplified || settings.ledstrip.enableStVO) - { - const auto center = (std::begin(leds) + (leds.size() / 2) + settings.ledstrip.centerOffset); - - if (!(blinkAnimation == LEDSTRIP_OVERWRITE_BLINKLEFT || blinkAnimation == LEDSTRIP_OVERWRITE_BLINKBOTH) || !(espchrono::millis_clock::now().time_since_epoch() % 750ms < 375ms) || settings.ledstrip.enableFullBlink) // Condition for right - { - std::fill(center - settings.ledstrip.bigOffset, center - settings.ledstrip.smallOffset, CRGB{0, 0, 0}); - std::fill(center - settings.ledstrip.bigOffset - 1U, center - settings.ledstrip.smallOffset - 1U, CRGB{255, 0, 0}); // Right - } - if (!(blinkAnimation == LEDSTRIP_OVERWRITE_BLINKRIGHT || blinkAnimation == LEDSTRIP_OVERWRITE_BLINKBOTH) || !(espchrono::millis_clock::now().time_since_epoch() % 750ms < 375ms) || settings.ledstrip.enableFullBlink) // Condition for left - { - std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, CRGB{0, 0, 0}); - std::fill(center + settings.ledstrip.smallOffset + 1U, center + settings.ledstrip.bigOffset + 1U, CRGB{255, 0, 0}); // Left - } - - if (settings.ledstrip.stvoFrontEnable) - { - std::fill(std::begin(leds) + settings.ledstrip.stvoFrontOffset, std::begin(leds) + settings.ledstrip.stvoFrontOffset + settings.ledstrip.stvoFrontLength, CRGB{255, 255, 255}); - std::fill(std::end(leds) - settings.ledstrip.stvoFrontOffset - settings.ledstrip.stvoFrontLength, std::end(leds) - settings.ledstrip.stvoFrontOffset, CRGB{255, 255, 255}); - } - } - - FastLED.setMaxPowerInVoltsAndMilliamps(5,settings.ledstrip.deziampere * 100); - FastLED.setBrightness(settings.ledstrip.brightness); - FastLED.show(); -} - -void showAnimation() { - if (settings.ledstrip.enableLedAnimation && !simplified) - { - if (animation_type == LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW) showDefaultLedstrip(); - else if (animation_type == LEDSTRIP_ANIMATION_TYPE_BETTERRAINBOW) showBetterRainbow(); - else if (animation_type == LEDSTRIP_ANIMATION_TYPE_SPEEDSYNCANIMATION) showSpeedSyncAnimation(); - else if (animation_type == LEDSTRIP_ANIMATION_TYPE_CUSTOMCOLOR) showCustomColor(); - else showDefaultLedstrip(); - } - else - { - std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0}); - } -} - -void showBetterRainbow() { - fill_rainbow(&*std::begin(leds), leds.size(), gHue); -} - -void fill_rainbow_invert_at( struct CRGB * pFirstLED, int numToFill, int invertAtLed, - uint8_t initialhue, - float deltahue ) -{ - float huecalc = initialhue; - CHSV hsv; - hsv.hue = initialhue; - hsv.val = 255; - hsv.sat = 240; - for( int i = 0; i < numToFill; i++) { - hsv.hue = huecalc; - pFirstLED[i] = hsv; - if(i>invertAtLed){ - huecalc -= deltahue; - }else{ - huecalc += deltahue; - } - } -} - -void showSpeedSyncAnimation() { -#ifdef LEDS_PER_METER - const float leds_per_meter = LEDS_PER_METER; -#else - const float leds_per_meter = 144; -#endif - - static auto last_interval = espchrono::millis_clock::now(); - auto difference_ms = espchrono::ago(last_interval).count(); - - static float hue_result = 0; - - const float hue_per_led = 1. / std::max(uint8_t(1), uint8_t(settings.ledstrip.animationMultiplier)); - const float meter_per_second = avgSpeedKmh / 3.6; - const float leds_per_second = meter_per_second * leds_per_meter; - const float hue_per_second = leds_per_second * hue_per_led; - - hue_result += hue_per_second * difference_ms / 1000.f; - - fill_rainbow_invert_at(&*std::begin(leds), leds.size(),leds.size()/2, hue_result,-hue_per_led); - - last_interval = espchrono::millis_clock::now(); -} - -void showDefaultLedstrip() -{ - fadeToBlackBy(&*std::begin(leds), leds.size(), 20); - - uint8_t dothue = 0; - for (int i = 0; i < 8; i++) - { - leds[beatsin16(i + 7, 0, leds.size())] |= CHSV(dothue, 200, 255); - dothue += 32; - } -} - -void showCustomColor() -{ - const auto eighth_length = leds.size() / 8; - const auto center = (std::begin(leds) + (leds.size() / 2) + settings.ledstrip.centerOffset); - - std::fill(std::begin(leds), std::end(leds), ledstrip_custom_colors[int(Bobbycar_Side::FRONT)]); // Front - std::fill(center - (eighth_length / 2), center + (eighth_length / 2), ledstrip_custom_colors[int(Bobbycar_Side::BACK)]); // Back - -#ifdef LEDSTRIP_WRONG_DIRECTION - std::fill(center + (eighth_length / 2), center + (eighth_length / 2) + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::BACK_LEFT)]); // Back Left - std::fill(center - (eighth_length / 2) - eighth_length, center - (eighth_length / 2), ledstrip_custom_colors[int(Bobbycar_Side::BACK_RIGHT)]); // Back Right -#else - std::fill(center + (eighth_length / 2), center + (eighth_length / 2) + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::BACK_RIGHT)]); // Back Right - std::fill(center - (eighth_length / 2) - eighth_length, center - (eighth_length / 2), ledstrip_custom_colors[int(Bobbycar_Side::BACK_LEFT)]); // Back Left -#endif - -#ifdef LEDSTRIP_WRONG_DIRECTION - std::fill(center + (eighth_length / 2) + eighth_length, center + (eighth_length / 2) + eighth_length + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::LEFT)]); // Left - std::fill(center - (eighth_length / 2) - eighth_length - eighth_length, center - (eighth_length / 2) - eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::RIGHT)]); // Right -#else - std::fill(center + (eighth_length / 2) + eighth_length, center + (eighth_length / 2) + eighth_length + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::RIGHT)]); // Right - std::fill(center - (eighth_length / 2) - eighth_length - eighth_length, center - (eighth_length / 2) - eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::LEFT)]); // Left -#endif - -#ifdef LEDSTRIP_WRONG_DIRECTION - std::fill(center + (eighth_length / 2) + eighth_length + eighth_length, center + (eighth_length / 2) + eighth_length + eighth_length + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::FRONT_LEFT)]); // Front Left - std::fill(center - (eighth_length / 2) - eighth_length - eighth_length - eighth_length, center - (eighth_length / 2) - eighth_length - eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::FRONT_RIGHT)]); // Front Right -#else - std::fill(center + (eighth_length / 2) + eighth_length + eighth_length, center + (eighth_length / 2) + eighth_length + eighth_length + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::FRONT_RIGHT)]); // Front Right - std::fill(center - (eighth_length / 2) - eighth_length - eighth_length - eighth_length, center - (eighth_length / 2) - eighth_length - eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::FRONT_LEFT)]); // Front Left -#endif - -} -} // namespace +void updateLedStrip(); #endif From fc1e277423b9aa596e4d8027a800f9b7fe9a929a Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Tue, 2 Nov 2021 23:13:43 +0100 Subject: [PATCH 07/10] Refactorings again more --- main/actions/rebootaction.cpp | 26 ++++ main/actions/rebootaction.h | 24 +-- main/changevaluedisplay_unifiedmodelmode.cpp | 37 +++++ main/changevaluedisplay_unifiedmodelmode.h | 34 +---- main/displays/garagedisplay.cpp | 50 +++++++ main/displays/garagedisplay.h | 44 +----- main/displays/lockscreen.cpp | 144 ++++++++++++++++++ main/displays/lockscreen.h | 149 +------------------ main/displays/poweroffdisplay.cpp | 56 +++++++ main/displays/poweroffdisplay.h | 47 +----- main/ota.cpp | 4 +- main/ota.h | 4 +- 12 files changed, 338 insertions(+), 281 deletions(-) diff --git a/main/actions/rebootaction.cpp b/main/actions/rebootaction.cpp index e69de29..a343c6e 100644 --- a/main/actions/rebootaction.cpp +++ b/main/actions/rebootaction.cpp @@ -0,0 +1,26 @@ +#include "rebootaction.h" + +// esp-idf includes +#include + +// 3rdparty lib includes +#include + +// local includes +#include "globals.h" +#include "texts.h" + +void RebootAction::triggered() +{ + espgui::tft.fillScreen(TFT_BLACK); + espgui::tft.setTextColor(TFT_YELLOW); + + espgui::tft.drawString(TEXT_REBOOT, 5, 5, 4); + + espgui::tft.fillRect(0, 34, espgui::tft.width(), 3, TFT_WHITE); + + espgui::tft.setTextColor(TFT_WHITE); + espgui::tft.drawString("Rebooting now...", 0, 50, 4); + + esp_restart(); +} diff --git a/main/actions/rebootaction.h b/main/actions/rebootaction.h index 92b0125..3bc01f2 100644 --- a/main/actions/rebootaction.h +++ b/main/actions/rebootaction.h @@ -1,30 +1,12 @@ #pragma once -#include - +// 3rdparty lib includes #include "actioninterface.h" -#include "globals.h" -#include "texts.h" using namespace espgui; -namespace { -class RebootAction : public virtual ActionInterface +class RebootAction : public virtual espgui::ActionInterface { public: - void triggered() override - { - tft.fillScreen(TFT_BLACK); - tft.setTextColor(TFT_YELLOW); - - tft.drawString(TEXT_REBOOT, 5, 5, 4); - - tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE); - - tft.setTextColor(TFT_WHITE); - tft.drawString("Rebooting now...", 0, 50, 4); - - esp_restart(); - } + void triggered() override; }; -} diff --git a/main/changevaluedisplay_unifiedmodelmode.cpp b/main/changevaluedisplay_unifiedmodelmode.cpp index e69de29..9f3ab55 100644 --- a/main/changevaluedisplay_unifiedmodelmode.cpp +++ b/main/changevaluedisplay_unifiedmodelmode.cpp @@ -0,0 +1,37 @@ +#include "changevaluedisplay_unifiedmodelmode.h" + +// esp-idf includes +#include + +// local includes +#include "utils.h" +#include "texts.h" + +namespace espgui { +ChangeValueDisplay::ChangeValueDisplay() +{ + constructMenuItem, StaticText>>(UnifiedModelMode::Commutation, *this, *this); + constructMenuItem, StaticText>>(UnifiedModelMode::Sinusoidal, *this, *this); + constructMenuItem, StaticText>>(UnifiedModelMode::FocVoltage, *this, *this); + constructMenuItem, StaticText>>(UnifiedModelMode::FocSpeed, *this, *this); + constructMenuItem, StaticText>>(UnifiedModelMode::FocTorque, *this, *this); + constructMenuItem, StaticMenuItemIcon<&espgui::icons::back>>>(*this); +} + +void ChangeValueDisplay::start() +{ + Base::start(); + + switch (const auto value = getValue()) + { + case UnifiedModelMode::Commutation: setSelectedIndex(0); break; + case UnifiedModelMode::Sinusoidal: setSelectedIndex(1); break; + case UnifiedModelMode::FocVoltage: setSelectedIndex(2); break; + case UnifiedModelMode::FocSpeed: setSelectedIndex(3); break; + case UnifiedModelMode::FocTorque: setSelectedIndex(4); break; + default: + ESP_LOGW("BOBBY", "Unknown UnifiedModelMode: %i", int(value)); + setSelectedIndex(5); + } +} +} // namespace espgui diff --git a/main/changevaluedisplay_unifiedmodelmode.h b/main/changevaluedisplay_unifiedmodelmode.h index 5e538f3..3e7b120 100644 --- a/main/changevaluedisplay_unifiedmodelmode.h +++ b/main/changevaluedisplay_unifiedmodelmode.h @@ -1,14 +1,13 @@ #pragma once -#include - +// 3rdparty lib includes #include "changevaluedisplay.h" #include "menudisplay.h" -#include "utils.h" #include "actions/setvalueaction.h" #include "actions/backproxyaction.h" #include "icons/back.h" -#include "texts.h" + +// local includes #include "unifiedmodelmode.h" namespace espgui { @@ -25,31 +24,4 @@ public: void start() override; }; - -ChangeValueDisplay::ChangeValueDisplay() -{ - constructMenuItem, StaticText>>(UnifiedModelMode::Commutation, *this, *this); - constructMenuItem, StaticText>>(UnifiedModelMode::Sinusoidal, *this, *this); - constructMenuItem, StaticText>>(UnifiedModelMode::FocVoltage, *this, *this); - constructMenuItem, StaticText>>(UnifiedModelMode::FocSpeed, *this, *this); - constructMenuItem, StaticText>>(UnifiedModelMode::FocTorque, *this, *this); - constructMenuItem, StaticMenuItemIcon<&espgui::icons::back>>>(*this); -} - -void ChangeValueDisplay::start() -{ - Base::start(); - - switch (const auto value = getValue()) - { - case UnifiedModelMode::Commutation: setSelectedIndex(0); break; - case UnifiedModelMode::Sinusoidal: setSelectedIndex(1); break; - case UnifiedModelMode::FocVoltage: setSelectedIndex(2); break; - case UnifiedModelMode::FocSpeed: setSelectedIndex(3); break; - case UnifiedModelMode::FocTorque: setSelectedIndex(4); break; - default: - ESP_LOGW("BOBBY", "Unknown UnifiedModelMode: %i", int(value)); - setSelectedIndex(5); - } -} } // namespace espgui diff --git a/main/displays/garagedisplay.cpp b/main/displays/garagedisplay.cpp index e69de29..dba370f 100644 --- a/main/displays/garagedisplay.cpp +++ b/main/displays/garagedisplay.cpp @@ -0,0 +1,50 @@ +#include "garagedisplay.h" + +// system includes + +// esp-idf includes +#include + +// 3rdparty lib includes +#include +#include +#include + +// local includes +#include "displays/menus/mainmenu.h" +#include "globals.h" +#include "texts.h" + +#ifdef FEATURE_GARAGE +void GarageDisplay::start() +{ +} + +void GarageDisplay::initScreen() +{ + espgui::tft.fillScreen(TFT_BLACK); + espgui::tft.setTextFont(4); + espgui::tft.setTextColor(TFT_YELLOW); + + espgui::tft.drawString(TEXT_GARAGE, 5, 5, 4); + + espgui::tft.fillRect(0, 34, espgui::tft.width(), 3, TFT_WHITE); + + espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK); + + espgui::tft.drawString("Garage", 20, 100); +} + +void GarageDisplay::redraw() +{ +} + +void GarageDisplay::confirm() +{ +} + +void GarageDisplay::back() +{ + espgui::switchScreen(); +} +#endif diff --git a/main/displays/garagedisplay.h b/main/displays/garagedisplay.h index 2b53af2..db53db1 100644 --- a/main/displays/garagedisplay.h +++ b/main/displays/garagedisplay.h @@ -1,58 +1,18 @@ #pragma once -// system includes - -// esp-idf includes -#include - -// 3rdparty lib includes -#include - // local includes #include "display.h" -#include "actions/switchscreenaction.h" -#include "globals.h" -#include "texts.h" -#include "widgets/label.h" -namespace { #ifdef FEATURE_GARAGE -class GarageDisplay : public Display, public BackActionInterface> +class GarageDisplay : public espgui::Display { public: void start() override; void initScreen() override; void redraw() override; void confirm() override; + void back() override; private: }; - -void GarageDisplay::start() -{ -} - -void GarageDisplay::initScreen() -{ - tft.fillScreen(TFT_BLACK); - tft.setTextFont(4); - tft.setTextColor(TFT_YELLOW); - - tft.drawString(TEXT_GARAGE, 5, 5, 4); - - tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE); - - tft.setTextColor(TFT_WHITE, TFT_BLACK); - - tft.drawString("Garage", 20, 100); -} - -void GarageDisplay::redraw() -{ -} - -void GarageDisplay::confirm() -{ -} #endif -} diff --git a/main/displays/lockscreen.cpp b/main/displays/lockscreen.cpp index e69de29..fe909d7 100644 --- a/main/displays/lockscreen.cpp +++ b/main/displays/lockscreen.cpp @@ -0,0 +1,144 @@ +#include "lockscreen.h" + +// 3rdparty lib includes +#include +#include + +// local includes +#include "globals.h" +#include "utils.h" +#include "texts.h" +#include "buttons.h" +#include "displays/menus/mainmenu.h" + +void Lockscreen::start() +{ + m_numbers = {0,0,0,0}; + m_currentIndex = 0; + m_pressed = false; + m_rotated = 0; + + m_oldMode = currentMode; + currentMode = &m_mode; + + profileButtonDisabled = !settings.lockscreen.allowPresetSwitch; +} + +void Lockscreen::initScreen() +{ + espgui::tft.fillScreen(TFT_BLACK); + espgui::tft.setTextFont(4); + espgui::tft.setTextColor(TFT_YELLOW); + + espgui::tft.drawString(TEXT_LOCKVEHICLE, 5, 5); + + espgui::tft.fillRect(0, 34, espgui::tft.width(), 3, TFT_WHITE); + + espgui::tft.setTextColor(TFT_WHITE); + espgui::tft.drawString("Enter code to unlock:", 0, 50); + + espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK); + + for(int i = 0; i <= 3; i++) + { + drawRect(i, 3, TFT_WHITE); + drawRect(i, 4, TFT_WHITE); + } + + for (auto &label : m_labels) + label.start(); + + espgui::tft.setTextFont(7); + + drawRect(0, 1, TFT_YELLOW); + drawRect(0, 2, TFT_YELLOW); + m_labels[0].redraw(std::to_string(m_numbers[0])); +} + +void Lockscreen::update() +{ + // just in case someone changes that settings somehow + profileButtonDisabled = !settings.lockscreen.allowPresetSwitch; +} + +void Lockscreen::redraw() +{ + if (m_pressed) + { + drawRect(m_currentIndex, 1, TFT_BLACK); + drawRect(m_currentIndex, 2, TFT_BLACK); + + if (++m_currentIndex>=4) + { + if (m_numbers == settings.lockscreen.pin) + { + espgui::switchScreen(); +#ifdef LOCKSCREEN_PLUGIN +#pragma message "Activating Lockscreen Plugin" +#include LOCKSCREEN_PLUGIN +#endif + return; + } + + m_numbers = {0,0,0,0}; + m_currentIndex = 0; + std::for_each(std::begin(m_labels) + 1, std::end(m_labels), [](auto &label){ label.redraw({}); }); + } + + m_labels[m_currentIndex].redraw(std::to_string(m_numbers[m_currentIndex])); + + drawRect(m_currentIndex, 1, TFT_YELLOW); + drawRect(m_currentIndex, 2, TFT_YELLOW); + + m_pressed = false; + } + + if (m_rotated) + { + m_numbers[m_currentIndex] -= m_rotated; + + if (m_numbers[m_currentIndex] < 0) + m_numbers[m_currentIndex]+=10; + else if (m_numbers[m_currentIndex] > 9) + m_numbers[m_currentIndex]-=10; + + m_labels[m_currentIndex].redraw(std::to_string(m_numbers[m_currentIndex])); + + m_rotated = 0; + } +} + +void Lockscreen::stop() +{ + Base::stop(); + + if (currentMode == &m_mode) + { + // to avoid crash after deconstruction + m_mode.stop(); + lastMode = nullptr; + + currentMode = m_oldMode; + } + + profileButtonDisabled = false; +} + +void Lockscreen::confirm() +{ + m_pressed = true; +} + +void Lockscreen::back() +{ +} + +void Lockscreen::rotate(int offset) +{ + m_rotated += offset; +} + +void Lockscreen::drawRect(int index, int offset, uint32_t color) const +{ + espgui::tft.drawRect(m_labels[index].x()-offset, m_labels[index].y()-offset, boxWidth+(offset*2), boxHeight+(offset*2), color); +} diff --git a/main/displays/lockscreen.h b/main/displays/lockscreen.h index 934f36f..5af1037 100644 --- a/main/displays/lockscreen.h +++ b/main/displays/lockscreen.h @@ -6,20 +6,15 @@ // local includes #include "display.h" #include "widgets/label.h" -#include "globals.h" -#include "utils.h" -#include "texts.h" #include "modes/ignoreinputmode.h" -#include "buttons.h" #ifdef LOCKSCREEN_PLUGIN #include "ledstrip.h" #endif -namespace { -class Lockscreen : public Display, public DummyBack +class Lockscreen : public espgui::Display { - using Base = Display; + using Base = espgui::Display; static constexpr auto boxWidth = 35; static constexpr auto boxHeight = 50; @@ -33,16 +28,17 @@ public: void stop() override; void confirm() override; + void back() override; void rotate(int offset) override; private: void drawRect(int index, int offset, uint32_t color) const; - std::array m_labels {{ - Label{spacing, 100}, // boxWidth, boxHeight - Label{spacing*2+boxWidth, 100}, // boxWidth, boxHeight - Label{spacing*3+boxWidth*2, 100}, // boxWidth, boxHeight - Label{spacing*4+boxWidth*3, 100} // boxWidth, boxHeight + std::array m_labels {{ + espgui::Label{spacing, 100}, // boxWidth, boxHeight + espgui::Label{spacing*2+boxWidth, 100}, // boxWidth, boxHeight + espgui::Label{spacing*3+boxWidth*2, 100}, // boxWidth, boxHeight + espgui::Label{spacing*4+boxWidth*3, 100} // boxWidth, boxHeight }}; std::array m_numbers; @@ -55,132 +51,3 @@ private: ModeInterface *m_oldMode; IgnoreInputMode m_mode{0, bobbycar::protocol::ControlType::FieldOrientedControl, bobbycar::protocol::ControlMode::Speed}; }; - -void Lockscreen::start() -{ - m_numbers = {0,0,0,0}; - m_currentIndex = 0; - m_pressed = false; - m_rotated = 0; - - m_oldMode = currentMode; - currentMode = &m_mode; - - profileButtonDisabled = !settings.lockscreen.allowPresetSwitch; -} - -void Lockscreen::initScreen() -{ - tft.fillScreen(TFT_BLACK); - tft.setTextFont(4); - tft.setTextColor(TFT_YELLOW); - - tft.drawString(TEXT_LOCKVEHICLE, 5, 5); - - tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE); - - tft.setTextColor(TFT_WHITE); - tft.drawString("Enter code to unlock:", 0, 50); - - tft.setTextColor(TFT_WHITE, TFT_BLACK); - - for(int i = 0; i <= 3; i++) - { - drawRect(i, 3, TFT_WHITE); - drawRect(i, 4, TFT_WHITE); - } - - for (auto &label : m_labels) - label.start(); - - tft.setTextFont(7); - - drawRect(0, 1, TFT_YELLOW); - drawRect(0, 2, TFT_YELLOW); - m_labels[0].redraw(std::to_string(m_numbers[0])); -} - -void Lockscreen::update() -{ - // just in case someone changes that settings somehow - profileButtonDisabled = !settings.lockscreen.allowPresetSwitch; -} - -void Lockscreen::redraw() -{ - if (m_pressed) - { - drawRect(m_currentIndex, 1, TFT_BLACK); - drawRect(m_currentIndex, 2, TFT_BLACK); - - if (++m_currentIndex>=4) - { - if (m_numbers == settings.lockscreen.pin) - { - switchScreen(); -#ifdef LOCKSCREEN_PLUGIN -#pragma message "Activating Lockscreen Plugin" -#include LOCKSCREEN_PLUGIN -#endif - return; - } - - m_numbers = {0,0,0,0}; - m_currentIndex = 0; - std::for_each(std::begin(m_labels) + 1, std::end(m_labels), [](auto &label){ label.redraw({}); }); - } - - m_labels[m_currentIndex].redraw(std::to_string(m_numbers[m_currentIndex])); - - drawRect(m_currentIndex, 1, TFT_YELLOW); - drawRect(m_currentIndex, 2, TFT_YELLOW); - - m_pressed = false; - } - - if (m_rotated) - { - m_numbers[m_currentIndex] -= m_rotated; - - if (m_numbers[m_currentIndex] < 0) - m_numbers[m_currentIndex]+=10; - else if (m_numbers[m_currentIndex] > 9) - m_numbers[m_currentIndex]-=10; - - m_labels[m_currentIndex].redraw(std::to_string(m_numbers[m_currentIndex])); - - m_rotated = 0; - } -} - -void Lockscreen::stop() -{ - Base::stop(); - - if (currentMode == &m_mode) - { - // to avoid crash after deconstruction - m_mode.stop(); - lastMode = nullptr; - - currentMode = m_oldMode; - } - - profileButtonDisabled = false; -} - -void Lockscreen::confirm() -{ - m_pressed = true; -} - -void Lockscreen::rotate(int offset) -{ - m_rotated += offset; -} - -void Lockscreen::drawRect(int index, int offset, uint32_t color) const -{ - tft.drawRect(m_labels[index].x()-offset, m_labels[index].y()-offset, boxWidth+(offset*2), boxHeight+(offset*2), color); -} -} diff --git a/main/displays/poweroffdisplay.cpp b/main/displays/poweroffdisplay.cpp index e69de29..f84367b 100644 --- a/main/displays/poweroffdisplay.cpp +++ b/main/displays/poweroffdisplay.cpp @@ -0,0 +1,56 @@ +#include "poweroffdisplay.h" + +// 3rdparty lib includes +#include +#include + +// local includes +#include "utils.h" +#include "globals.h" +#include "texts.h" +#include "displays/menus/mainmenu.h" + +using namespace std::chrono_literals; + +void PoweroffDisplay::start() +{ + m_startTime = espchrono::millis_clock::now(); + + for (Controller &controller : controllers) + controller.command.poweroff = true; +} + +void PoweroffDisplay::initScreen() +{ + espgui::tft.fillScreen(TFT_BLACK); + espgui::tft.setTextColor(TFT_YELLOW); + + espgui::tft.drawString(TEXT_POWEROFF, 5, 5, 4); + + espgui::tft.fillRect(0, 34, espgui::tft.width(), 3, TFT_WHITE); + + espgui::tft.setTextColor(TFT_WHITE); + espgui::tft.drawString("Trying to turn off", 15, 50, 4); + espgui::tft.drawString("both controllers", 25, 75, 4); + espgui::tft.drawString("Please stand still...", 20, 125, 4); +} + +void PoweroffDisplay::update() +{ + if (espchrono::millis_clock::now() - m_startTime >= 1000ms) + espgui::switchScreen(); +} + +void PoweroffDisplay::stop() +{ + for (Controller &controller : controllers) + controller.command.poweroff = false; +} + +void PoweroffDisplay::confirm() +{ +} + +void PoweroffDisplay::back() +{ +} diff --git a/main/displays/poweroffdisplay.h b/main/displays/poweroffdisplay.h index 6735450..3ac0b78 100644 --- a/main/displays/poweroffdisplay.h +++ b/main/displays/poweroffdisplay.h @@ -5,56 +5,19 @@ // local includes #include "display.h" -#include "utils.h" -#include "globals.h" -#include "texts.h" -namespace { -class PoweroffDisplay : public Display, public DummyConfirm, public DummyBack +class PoweroffDisplay : public espgui::Display { public: void start() override; void initScreen() override; void update() override; - void redraw() override {}; + void redraw() override {} void stop() override; + void confirm() override; + void back() override; + private: espchrono::millis_clock::time_point m_startTime; }; - -void PoweroffDisplay::start() -{ - m_startTime = espchrono::millis_clock::now(); - - for (Controller &controller : controllers) - controller.command.poweroff = true; -} - -void PoweroffDisplay::initScreen() -{ - tft.fillScreen(TFT_BLACK); - tft.setTextColor(TFT_YELLOW); - - tft.drawString(TEXT_POWEROFF, 5, 5, 4); - - tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE); - - tft.setTextColor(TFT_WHITE); - tft.drawString("Trying to turn off", 15, 50, 4); - tft.drawString("both controllers", 25, 75, 4); - tft.drawString("Please stand still...", 20, 125, 4); -} - -void PoweroffDisplay::update() -{ - if (espchrono::millis_clock::now() - m_startTime >= 1000ms) - switchScreen(); -} - -void PoweroffDisplay::stop() -{ - for (Controller &controller : controllers) - controller.command.poweroff = false; -} -} diff --git a/main/ota.cpp b/main/ota.cpp index 1ec404d..06214ae 100644 --- a/main/ota.cpp +++ b/main/ota.cpp @@ -7,8 +7,8 @@ #include #ifdef FEATURE_OTA -extern cpputils::DelayedConstruction asyncOta; -extern bool asyncOtaTaskStarted; +cpputils::DelayedConstruction asyncOta; +bool asyncOtaTaskStarted{}; namespace { constexpr const char * const TAG = "BOBBYOTA"; diff --git a/main/ota.h b/main/ota.h index 8ad7c47..0b501da 100644 --- a/main/ota.h +++ b/main/ota.h @@ -9,8 +9,8 @@ // local includes #ifdef FEATURE_OTA -cpputils::DelayedConstruction asyncOta; -bool asyncOtaTaskStarted{}; +extern cpputils::DelayedConstruction asyncOta; +extern bool asyncOtaTaskStarted; void initOta(); void handleOta(); From 08e97debe7c70440d592c4a2543224f13efce583 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Tue, 2 Nov 2021 23:17:10 +0100 Subject: [PATCH 08/10] Fixed compiling --- main/displays/calibratedisplay.cpp | 46 ++++++++++++++---------------- main/displays/calibratedisplay.h | 3 +- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/main/displays/calibratedisplay.cpp b/main/displays/calibratedisplay.cpp index 903b53e..a537308 100644 --- a/main/displays/calibratedisplay.cpp +++ b/main/displays/calibratedisplay.cpp @@ -179,33 +179,8 @@ void CalibrateDisplay::rotate(int offset) 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 @@ -259,6 +234,27 @@ void CalibrateDisplay::confirm() } } +void CalibrateDisplay::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::copyFromSettings() { m_gasMin = settings.boardcomputerHardware.gasMin; diff --git a/main/displays/calibratedisplay.h b/main/displays/calibratedisplay.h index 45b14bd..7846e13 100644 --- a/main/displays/calibratedisplay.h +++ b/main/displays/calibratedisplay.h @@ -35,9 +35,8 @@ public: void rotate(int offset) override; - void back() override; - void confirm() override; + void back() override; private: void copyFromSettings(); From 0428a126f28f076a3c13cf709376bdce40fa4ce2 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Tue, 2 Nov 2021 23:26:28 +0100 Subject: [PATCH 09/10] fix mick compile --- main/actions/ledstripanimationactions.h | 2 ++ main/actions/ledstripblinkactions.h | 2 ++ main/buildserver.h | 2 ++ main/displays/ledstripcolorsdisplay.cpp | 2 ++ main/displays/ledstripcolorsdisplay.h | 2 ++ main/displays/menus/cloudsettingsmenu.cpp | 2 ++ main/displays/menus/ledstripselectanimationmenu.h | 2 ++ main/displays/menus/ledstripselectblinkmenu.h | 2 ++ main/displays/menus/otamenu.cpp | 2 ++ main/displays/menus/selectbuildservermenu.cpp | 2 ++ main/displays/menus/selectbuildservermenu.h | 2 ++ main/displays/menus/selectotabuildmenu.h | 2 ++ 12 files changed, 24 insertions(+) diff --git a/main/actions/ledstripanimationactions.h b/main/actions/ledstripanimationactions.h index 2d58f69..ed08b8f 100644 --- a/main/actions/ledstripanimationactions.h +++ b/main/actions/ledstripanimationactions.h @@ -9,6 +9,7 @@ using namespace espgui; namespace { +#ifdef FEATURE_LEDSTRIP template class LedStripSetAnimationAction : public virtual ActionInterface { @@ -35,4 +36,5 @@ public: void triggered() override { animation_type = LEDSTRIP_ANIMATION_TYPE_SPEEDSYNCANIMATION; } }; */ +#endif } diff --git a/main/actions/ledstripblinkactions.h b/main/actions/ledstripblinkactions.h index 06c5f8d..f22efa5 100644 --- a/main/actions/ledstripblinkactions.h +++ b/main/actions/ledstripblinkactions.h @@ -8,6 +8,7 @@ using namespace espgui; +#ifdef FEATURE_LEDSTRIP namespace { class LedstripAnimationBlinkNoneAction : public virtual ActionInterface { @@ -49,3 +50,4 @@ public: void triggered() override { blinkAnimation = LEDSTRIP_OVERWRITE_BLINKBOTH; } }; } +#endif diff --git a/main/buildserver.h b/main/buildserver.h index 5f1f8ca..b190c78 100644 --- a/main/buildserver.h +++ b/main/buildserver.h @@ -16,6 +16,7 @@ // esp-idf #include "esp_http_client.h" +#ifdef FEATURE_OTA namespace { void buildMenuFromJson(std::string json); void buildMenuRequestError(std::string error); @@ -191,3 +192,4 @@ namespace { return request_running; } } +#endif diff --git a/main/displays/ledstripcolorsdisplay.cpp b/main/displays/ledstripcolorsdisplay.cpp index 87bdbbe..22732eb 100644 --- a/main/displays/ledstripcolorsdisplay.cpp +++ b/main/displays/ledstripcolorsdisplay.cpp @@ -22,6 +22,7 @@ #include "globals.h" #include "displays/menus/ledstripmenu.h" +#ifdef FEATURE_LEDSTRIP int8_t selected_side = 7; int8_t selected_color; bool state_select_color{false}; @@ -238,3 +239,4 @@ void LedstripColorsDisplay::drawSide(Bobbycar_Side side, unsigned int color) } // espgui::tft.fillCircle(espgui::tft.width() / 2, 140, 100, TFT_BLACK); } +#endif diff --git a/main/displays/ledstripcolorsdisplay.h b/main/displays/ledstripcolorsdisplay.h index 65fbcbd..bd14554 100644 --- a/main/displays/ledstripcolorsdisplay.h +++ b/main/displays/ledstripcolorsdisplay.h @@ -10,6 +10,7 @@ // local includes #include "ledstrip.h" +#ifdef FEATURE_LEDSTRIP extern int8_t selected_side; extern int8_t selected_color; extern bool state_select_color; @@ -38,3 +39,4 @@ public: private: bool already_drew_circle{false}; }; +#endif diff --git a/main/displays/menus/cloudsettingsmenu.cpp b/main/displays/menus/cloudsettingsmenu.cpp index ec4dd36..ec9f2f2 100644 --- a/main/displays/menus/cloudsettingsmenu.cpp +++ b/main/displays/menus/cloudsettingsmenu.cpp @@ -16,6 +16,7 @@ #include "cloud.h" #include "displays/menus/settingsmenu.h" +#ifdef FEATURE_CLOUD namespace { using CloudTransmitTimeoutChangeScreen = espgui::makeComponent< espgui::ChangeValueDisplay, @@ -70,3 +71,4 @@ void CloudSettingsMenu::back() { switchScreen(); } +#endif diff --git a/main/displays/menus/ledstripselectanimationmenu.h b/main/displays/menus/ledstripselectanimationmenu.h index 4a22635..8deae40 100644 --- a/main/displays/menus/ledstripselectanimationmenu.h +++ b/main/displays/menus/ledstripselectanimationmenu.h @@ -14,6 +14,7 @@ #include "ledstrip.h" #include "ledstripdefines.h" +#ifdef FEATURE_LEDSTRIP class currentSelectedAnimationText : public virtual TextInterface { public: std::string text() const override { switch (animation_type) { case LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW: @@ -51,3 +52,4 @@ namespace { } }; } // Namespace +#endif diff --git a/main/displays/menus/ledstripselectblinkmenu.h b/main/displays/menus/ledstripselectblinkmenu.h index cbb862a..e565bf2 100644 --- a/main/displays/menus/ledstripselectblinkmenu.h +++ b/main/displays/menus/ledstripselectblinkmenu.h @@ -13,6 +13,7 @@ #include "actions/switchscreenaction.h" #include "ledstripdefines.h" +#ifdef FEATURE_LEDSTRIP class currentSelectedBlinkAnimationText : public virtual TextInterface { public: std::string text() const override { switch (blinkAnimation) { case LEDSTRIP_OVERWRITE_BLINKLEFT: @@ -56,3 +57,4 @@ namespace { } }; } // Namespace +#endif diff --git a/main/displays/menus/otamenu.cpp b/main/displays/menus/otamenu.cpp index 422fafc..4770618 100644 --- a/main/displays/menus/otamenu.cpp +++ b/main/displays/menus/otamenu.cpp @@ -16,6 +16,7 @@ #include "displays/menus/selectbuildservermenu.h" #include "displays/menus/mainmenu.h" +#ifdef FEATURE_OTA namespace { class RedownloadJsonAction : public virtual espgui::ActionInterface @@ -44,3 +45,4 @@ void OtaMenu::back() { switchScreen(); } +#endif diff --git a/main/displays/menus/selectbuildservermenu.cpp b/main/displays/menus/selectbuildservermenu.cpp index cc9413b..be80491 100644 --- a/main/displays/menus/selectbuildservermenu.cpp +++ b/main/displays/menus/selectbuildservermenu.cpp @@ -10,6 +10,7 @@ // local includes #include "displays/menus/settingsmenu.h" +#ifdef FEATURE_OTA namespace { class BuildserverMenuItem : public espgui::MenuItem { @@ -69,3 +70,4 @@ void SelectBuildServerMenu::back() { espgui::switchScreen(); } +#endif diff --git a/main/displays/menus/selectbuildservermenu.h b/main/displays/menus/selectbuildservermenu.h index aae8471..be4ce41 100644 --- a/main/displays/menus/selectbuildservermenu.h +++ b/main/displays/menus/selectbuildservermenu.h @@ -11,6 +11,7 @@ #include "globals.h" #include "buildserver.h" +#ifdef FEATURE_OTA class SelectBuildServerMenu : public espgui::MenuDisplay, public espgui::StaticText @@ -20,3 +21,4 @@ public: void back() override; }; +#endif diff --git a/main/displays/menus/selectotabuildmenu.h b/main/displays/menus/selectotabuildmenu.h index 3c9c051..746f104 100644 --- a/main/displays/menus/selectotabuildmenu.h +++ b/main/displays/menus/selectotabuildmenu.h @@ -20,6 +20,7 @@ using namespace espgui; +#ifdef FEATURE_OTA namespace { // ToDo: if (request_failed) => MESSAGE("An error occurred") @@ -147,3 +148,4 @@ void SelectBuildMenu::buildMenuRequestError(std::string error) constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); } } // namespace +#endif From e5b513297befb6be84033a40e4a7bf7b7a14b6a8 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Tue, 2 Nov 2021 23:27:06 +0100 Subject: [PATCH 10/10] Add mick cloud builds --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f74a22e..56e419e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - node: [feedc0de, comred, peter] + node: [feedc0de, comred, peter, mick] steps: - name: Checkout (without submodules) uses: actions/checkout@v2