diff --git a/main/accessors/settingsaccessors.h b/main/accessors/settingsaccessors.h index 4bb5e4e..f5c1a83 100644 --- a/main/accessors/settingsaccessors.h +++ b/main/accessors/settingsaccessors.h @@ -168,6 +168,10 @@ struct AnimationMultiplierAccessor : public RefAccessorSaveSettings { i struct LedstripBrightnessAccessor : public RefAccessorSaveSettings { uint8_t &getRef() const override { return settings.ledstrip.brightness; } }; #endif +// Battery +struct BatterySeriesCellsAccessor : public RefAccessorSaveSettings { uint8_t &getRef() const override { return settings.battery.cellsSeries; } }; +struct BatteryParallelCellsAccessor : public RefAccessorSaveSettings { uint8_t &getRef() const override { return settings.battery.cellsParallel; } }; + struct LockscreenAllowPresetSwitchAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.lockscreen.allowPresetSwitch; } }; template struct LockscreenPinDigitAccessor : public RefAccessorSaveSettings { int8_t &getRef() const override { return settings.lockscreen.pin[index]; } }; diff --git a/main/battery.h b/main/battery.h new file mode 100644 index 0000000..842d3fc --- /dev/null +++ b/main/battery.h @@ -0,0 +1,40 @@ +#pragma once + +// local includes +#include "globals.h" +#include "cpputils.h" + +#define BATTERY_CELLTYPE_22P 0 +#define BATTERY_CELLTYPE_HG2 1 +#define BATTERY_CELLTYPE_MH1 2 +#define BATTERY_CELLTYPE_VTC5 3 + +float battery_percentage = 42.0; + +std::string getBatteryPercentageString() { + std::string output = fmt::format("Battery: {:.1f}%", battery_percentage); + return output; +} + +std::string getBatteryCellTypeString() { + std::string output = ""; + switch (settings.battery.cellType) { + case BATTERY_CELLTYPE_22P: + output = "Cells: 22P"; + break; + case BATTERY_CELLTYPE_HG2: + output = "Cells: HG2"; + break; + case BATTERY_CELLTYPE_MH1: + output = "Cells: MH1"; + break; + case BATTERY_CELLTYPE_VTC5: + output = "Cells: VTC5"; + break; + default: + output = "Unkown cell type"; + break; + } + + return output; +} diff --git a/main/displays/menus/batterymenu.h b/main/displays/menus/batterymenu.h new file mode 100644 index 0000000..92f8c77 --- /dev/null +++ b/main/displays/menus/batterymenu.h @@ -0,0 +1,57 @@ +#pragma once + +// 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" + +// Helper +class currentBatteryStatus : public virtual TextInterface { public: std::string text() const override { return getBatteryPercentageString(); } }; + +using namespace espgui; + +namespace { + class BatteryMenu; + + using BatteryCellSeriesChangeScreen = makeComponent< + ChangeValueDisplay, + StaticText, + BatterySeriesCellsAccessor, + BackActionInterface>, + SwitchScreenAction + >; + + using BatteryCellParallelChangeScreen = makeComponent< + ChangeValueDisplay, + StaticText, + BatteryParallelCellsAccessor, + BackActionInterface>, + SwitchScreenAction + >; +} + +namespace { + class BatteryMenu : + public MenuDisplay, + public StaticText, + public BackActionInterface> + { + public: + BatteryMenu() + { + constructMenuItem>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); + } + }; +} // Namespace diff --git a/main/displays/menus/ledstripselectanimationmenu.h b/main/displays/menus/ledstripselectanimationmenu.h index da001ad..6d07fb7 100644 --- a/main/displays/menus/ledstripselectanimationmenu.h +++ b/main/displays/menus/ledstripselectanimationmenu.h @@ -11,6 +11,22 @@ #include "actions/dummyaction.h" #include "actions/ledstripanimationactions.h" #include "actions/switchscreenaction.h" +#include "ledstrip.h" +#include "ledstripdefines.h" + +class currentSelectedAnimationText : public virtual TextInterface { public: std::string text() const override { + switch (animation_type) { + case LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW: + return TEXT_ANIMATION_DEFAULTRAINBOW; + case LEDSTRIP_ANIMATION_TYPE_BETTERRAINBOW: + return TEXT_ANIMATION_BETTERRAINBOW; + case LEDSTRIP_ANIMATION_TYPE_SPEEDSYNCANIMATION: + return TEXT_ANIMATION_SPEEDSYNCANIMATION; + default: + return "Animation Unkown"; + } + }; +}; using namespace espgui; @@ -27,6 +43,8 @@ namespace { public: LedstripSelectAnimationMenu() { + constructMenuItem>(); + constructMenuItem>(); constructMenuItem, LedstripAnimationDefaultRainbowAction>>(); constructMenuItem, LedstripAnimationBetterRainbowAction>>(); constructMenuItem, LedstripAnimationSyncToSpeedAction>>(); diff --git a/main/displays/menus/ledstripselectblinkmenu.h b/main/displays/menus/ledstripselectblinkmenu.h index 336d291..06122e4 100644 --- a/main/displays/menus/ledstripselectblinkmenu.h +++ b/main/displays/menus/ledstripselectblinkmenu.h @@ -11,6 +11,29 @@ #include "actions/dummyaction.h" #include "actions/ledstripblinkactions.h" #include "actions/switchscreenaction.h" +#include "ledstripdefines.h" + +class currentSelectedBlinkAnimationText : public virtual TextInterface { public: std::string text() const override { + switch (blinkAnimation) { + case LEDSTRIP_OVERWRITE_BLINKLEFT: +#ifndef LEDSTRIP_WRONG_DIRECTION + return TEXT_ANIMATION_BLINKLEFT; +#else + return TEXT_ANIMATION_BLINKRIGHT; +#endif + case LEDSTRIP_OVERWRITE_BLINKRIGHT: +#ifndef LEDSTRIP_WRONG_DIRECTION + return TEXT_ANIMATION_BLINKRIGHT; +#else + return TEXT_ANIMATION_BLINKLEFT; +#endif + case LEDSTRIP_OVERWRITE_BLINKBOTH: + return TEXT_ANIMATION_BLINKBOTH; + default: + return TEXT_ANIMATION_BLINKNONE; + } + }; +}; using namespace espgui; @@ -27,6 +50,8 @@ namespace { public: LedstripSelectBlinkMenu() { + constructMenuItem>(); + constructMenuItem>(); constructMenuItem, LedstripAnimationBlinkNoneAction>>(); constructMenuItem, LedstripAnimationBlinkLeftAction>>(); constructMenuItem, LedstripAnimationBlinkRightAction>>(); diff --git a/main/displays/menus/mainmenu.h b/main/displays/menus/mainmenu.h index e5c3020..37d4518 100644 --- a/main/displays/menus/mainmenu.h +++ b/main/displays/menus/mainmenu.h @@ -3,11 +3,13 @@ // local includes #include "menudisplay.h" #include "menuitem.h" +#include "batterymenu.h" #include "actions/switchscreenaction.h" #include "actions/modesettingsaction.h" #include "actions/rebootaction.h" #include "texts.h" #include "icons/back.h" +#include "icons/battery.h" #include "icons/modes.h" #include "icons/presets.h" #include "icons/graph.h" @@ -44,6 +46,7 @@ class GarageDisplay; class UpdateDisplay; class PoweroffDisplay; class DebugMenu; +class BatteryMenu; } // namespace using namespace espgui; @@ -66,6 +69,7 @@ public: if (!simplified) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::presets>>>(); } if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } if (!simplified) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::graph>>>(); } + if (!simplified) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::battery>>>(); } #if defined(FEATURE_CAN) && defined(FEATURE_POWERSUPPLY) if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } #endif diff --git a/main/displays/menus/selectbatterytypemenu.h b/main/displays/menus/selectbatterytypemenu.h new file mode 100644 index 0000000..72de417 --- /dev/null +++ b/main/displays/menus/selectbatterytypemenu.h @@ -0,0 +1,65 @@ +#pragma once + +// 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" + +// Helper +class currentBatteryType : public virtual TextInterface { public: std::string text() const override { return getBatteryCellTypeString(); } }; + +using namespace espgui; + +namespace { + class BatteryTypeMenu; + class BatteryMenu; + + class BatterySelectType22PAction : public virtual ActionInterface + { + public: + void triggered() override { settings.battery.cellType = BATTERY_CELLTYPE_22P; saveSettings(); } + }; + + class BatterySelectTypeHG2Action : public virtual ActionInterface + { + public: + void triggered() override { settings.battery.cellType = BATTERY_CELLTYPE_HG2; saveSettings(); } + }; + + class BatterySelectTypeMH1Action : public virtual ActionInterface + { + public: + void triggered() override { settings.battery.cellType = BATTERY_CELLTYPE_MH1; saveSettings(); } + }; + + class BatterySelectTypeVTC5Action : public virtual ActionInterface + { + public: + void triggered() override { settings.battery.cellType = BATTERY_CELLTYPE_VTC5; saveSettings(); } + }; +} + +namespace { + class BatteryTypeMenu : + public MenuDisplay, + public StaticText, + public BackActionInterface> + { + public: + BatteryTypeMenu() + { + constructMenuItem>(); + constructMenuItem, BatterySelectType22PAction>>(); + constructMenuItem, BatterySelectTypeHG2Action>>(); + constructMenuItem, BatterySelectTypeMH1Action>>(); + constructMenuItem, BatterySelectTypeVTC5Action>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); + } + }; +} // Namespace diff --git a/main/ledstrip.h b/main/ledstrip.h index 6f2b430..cdaa50c 100644 --- a/main/ledstrip.h +++ b/main/ledstrip.h @@ -1,5 +1,4 @@ #pragma once -#define FEATURE_LEDSTRIP #ifdef FEATURE_LEDSTRIP // 3rdparty lib includes #include diff --git a/main/presets.h b/main/presets.h index d75cc85..20a5a37 100644 --- a/main/presets.h +++ b/main/presets.h @@ -253,6 +253,12 @@ constexpr Settings::LockscreenSettings defaultLockscreen { .pin = { 1, 2, 3, 4 } }; +constexpr Settings::Battery defaultBattery { + .cellsSeries = 12, + .cellsParallel = 4, + .cellType = 0 +}; + constexpr Settings defaultSettings { #ifdef FEATURE_BMS .autoConnectBms = false, @@ -278,6 +284,7 @@ constexpr Settings defaultSettings { #ifdef FEATURE_LEDSTRIP .ledstrip = defaultLedstrip, #endif + .battery = defaultBattery, .lockscreen = defaultLockscreen }; diff --git a/main/settings.h b/main/settings.h index 6d92256..7eb693c 100644 --- a/main/settings.h +++ b/main/settings.h @@ -170,6 +170,13 @@ struct Settings int16_t animationMultiplier; uint8_t brightness; } ledstrip; + + struct Battery { + uint8_t cellsSeries; + uint8_t cellsParallel; + uint8_t cellType; + } battery; + #endif struct LockscreenSettings { @@ -275,10 +282,14 @@ void Settings::executeForEveryCommonSetting(T &&callable) callable("ledstvofoff", ledstrip.stvoFrontOffset); callable("ledstvoflen", ledstrip.stvoFrontLength); callable("ledstvoen", ledstrip.stvoFrontEnable); - callable("ledAnimMultiplier", ledstrip.animationMultiplier); + callable("ledAnimMul", ledstrip.animationMultiplier); callable("ledbrightness", ledstrip.brightness); #endif + callable("batteryCS", battery.cellsSeries); + callable("batteryCP", battery.cellsParallel); + callable("batteryType", battery.cellType); + callable("lockAlwPresetSw", lockscreen.allowPresetSwitch); callable("lockscreenPin", lockscreen.pin); } diff --git a/main/texts.h b/main/texts.h index 383719c..eb166c5 100644 --- a/main/texts.h +++ b/main/texts.h @@ -86,6 +86,18 @@ constexpr char TEXT_UPDATE[] = "Update"; constexpr char TEXT_POWEROFF[] = "Poweroff"; constexpr char TEXT_REBOOT[] = "Reboot"; constexpr char TEXT_DEBUG[] = "Debug"; +constexpr char TEXT_BATTERY[] = "Battery"; + +//BatteryMenu +constexpr char TEXT_CELL_SERIES[] = "Cells (Series)"; +constexpr char TEXT_CELL_PARALLEL[] = "Cells (Parallel)"; +constexpr char TEXT_SELECT_CELL_TYPE[] = "Select Cell Type"; +constexpr char TEXT_CELL_TYPE[] = "Cell Type"; +constexpr char TEXT_BATTERY_CALIBRATE[] = "Calibrate Voltages"; +constexpr char TEXT_BATTERY_TYPE_22P[] = "22P cells"; +constexpr char TEXT_BATTERY_TYPE_HG2[] = "HG2 cells"; +constexpr char TEXT_BATTERY_TYPE_MH1[] = "MH1 cells"; +constexpr char TEXT_BATTERY_TYPE_VTC5[] = "VTC5 cells"; //SettingsMenu //constexpr char TEXT_SETTINGS[] = "Settings";