diff --git a/components/esp-gui-lib b/components/esp-gui-lib index ad0d903..3a843d9 160000 --- a/components/esp-gui-lib +++ b/components/esp-gui-lib @@ -1 +1 @@ -Subproject commit ad0d90339e63ad97ff64875d6c17aba887d7d6e2 +Subproject commit 3a843d9202d7d3a1aa9e82b3bbbc1ddfbb5fb686 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index da8b5e4..9cdd54f 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -19,7 +19,6 @@ set(headers actions/rebootaction.h actions/savesettingsaction.h actions/tempomatmodeapplycurrentpeedaction.h - actions/toggleboolaction.h actions/wifiscanaction.h actions/switchprofileaction.h actions/updateswapfrontbackaction.h diff --git a/main/actions/modesettingsaction.h b/main/actions/modesettingsaction.h index 76564cc..2b61f31 100644 --- a/main/actions/modesettingsaction.h +++ b/main/actions/modesettingsaction.h @@ -10,6 +10,7 @@ #include "displays/menus/tempomatmodesettingsmenu.h" #include "displays/menus/larsmmodesettingsmenu.h" #include "displays/menus/gametrakmodesettingsmenu.h" +#include "screenmanager.h" using namespace espgui; diff --git a/main/actions/toggleboolaction.h b/main/actions/toggleboolaction.h deleted file mode 100644 index 2eaae09..0000000 --- a/main/actions/toggleboolaction.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "actioninterface.h" -#include "accessorinterface.h" - -using namespace espgui; - -namespace { -class ToggleBoolAction : public virtual ActionInterface, public virtual AccessorInterface -{ -public: - void triggered() override - { - setValue(!getValue()); - } -}; -} diff --git a/main/displays/bmsdisplay.h b/main/displays/bmsdisplay.h index 95184f9..103f464 100644 --- a/main/displays/bmsdisplay.h +++ b/main/displays/bmsdisplay.h @@ -1,12 +1,15 @@ #pragma once +// Arduino includes #include +// local includes #include "display.h" #include "actions/switchscreenaction.h" #include "globals.h" #include "bmsutils.h" #include "widgets/label.h" +#include "screenmanager.h" namespace { class MainMenu; diff --git a/main/globals.h b/main/globals.h index d74c246..a40a453 100644 --- a/main/globals.h +++ b/main/globals.h @@ -89,8 +89,6 @@ BluetoothSerial bluetoothSerial; ModeInterface *lastMode{}; ModeInterface *currentMode{}; -std::unique_ptr currentDisplay; - #ifdef FEATURE_LEDBACKLIGHT constexpr const bool ledBacklightInverted = #ifdef LEDBACKLIGHT_INVERTED diff --git a/main/ledstrip.h b/main/ledstrip.h index 791f3ce..fefc9d1 100644 --- a/main/ledstrip.h +++ b/main/ledstrip.h @@ -21,7 +21,16 @@ void updateLedStrip() { EVERY_N_MILLISECONDS( 20 ) { gHue++; } - if (brems && *brems > 50.f) + 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 < -50.f) { auto color = avgSpeedKmh < -0.1f ? CRGB{255, 255, 255} : CRGB{255, 0, 0}; constexpr auto kleinerOffset = 4; diff --git a/main/screens.h b/main/screens.h index fa24a74..a2aba69 100644 --- a/main/screens.h +++ b/main/screens.h @@ -1,49 +1,20 @@ #pragma once +// system includes #include +// local includes #include "globals.h" #include "utils.h" #include "widgets/label.h" #include "icons/logo.h" +#include "screenmanager.h" + +using namespace espgui; namespace { Label bootLabel{32, 250}; -void deconstructScreen() -{ - if (currentDisplay) - { - currentDisplay->stop(); - //currentDisplay->~Display(); - currentDisplay = nullptr; - } -} - -template -void switchScreenImpl(Args&&... args) -{ - deconstructScreen(); - - std::unique_ptr ptr = std::make_unique(std::forward(args)...); - currentDisplay = std::move(ptr); - currentDisplay->start(); - currentDisplay->initScreen(); - currentDisplay->update(); - currentDisplay->redraw(); -} - -std::function changeScreenCallback; - -template -void switchScreen(Args&&... args) -{ - if (currentDisplay) - changeScreenCallback = [&args...](){ switchScreenImpl(std::forward(args)...); }; - else - switchScreenImpl(std::forward(args)...); -} - void initScreen() { tft.init(); diff --git a/main/utils.h b/main/utils.h index 32ed158..2bd3bd5 100644 --- a/main/utils.h +++ b/main/utils.h @@ -218,9 +218,6 @@ void sendCommands() #endif } -template -void switchScreen(Args&&... args); - #ifdef FEATURE_SERIAL void updateSwapFrontBack() {