Preparation of battery menu
This commit is contained in:
@ -168,6 +168,10 @@ struct AnimationMultiplierAccessor : public RefAccessorSaveSettings<int16_t> { i
|
||||
struct LedstripBrightnessAccessor : public RefAccessorSaveSettings<uint8_t> { uint8_t &getRef() const override { return settings.ledstrip.brightness; } };
|
||||
#endif
|
||||
|
||||
// Battery
|
||||
struct BatterySeriesCellsAccessor : public RefAccessorSaveSettings<uint8_t> { uint8_t &getRef() const override { return settings.battery.cellsSeries; } };
|
||||
struct BatteryParallelCellsAccessor : public RefAccessorSaveSettings<uint8_t> { uint8_t &getRef() const override { return settings.battery.cellsParallel; } };
|
||||
|
||||
struct LockscreenAllowPresetSwitchAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.lockscreen.allowPresetSwitch; } };
|
||||
template<uint8_t index>
|
||||
struct LockscreenPinDigitAccessor : public RefAccessorSaveSettings<int8_t> { int8_t &getRef() const override { return settings.lockscreen.pin[index]; } };
|
||||
|
40
main/battery.h
Normal file
40
main/battery.h
Normal file
@ -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;
|
||||
}
|
57
main/displays/menus/batterymenu.h
Normal file
57
main/displays/menus/batterymenu.h
Normal file
@ -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<uint8_t>,
|
||||
StaticText<TEXT_CELL_SERIES>,
|
||||
BatterySeriesCellsAccessor,
|
||||
BackActionInterface<SwitchScreenAction<BatteryMenu>>,
|
||||
SwitchScreenAction<BatteryMenu>
|
||||
>;
|
||||
|
||||
using BatteryCellParallelChangeScreen = makeComponent<
|
||||
ChangeValueDisplay<uint8_t>,
|
||||
StaticText<TEXT_CELL_PARALLEL>,
|
||||
BatteryParallelCellsAccessor,
|
||||
BackActionInterface<SwitchScreenAction<BatteryMenu>>,
|
||||
SwitchScreenAction<BatteryMenu>
|
||||
>;
|
||||
}
|
||||
|
||||
namespace {
|
||||
class BatteryMenu :
|
||||
public MenuDisplay,
|
||||
public StaticText<TEXT_BATTERY>,
|
||||
public BackActionInterface<SwitchScreenAction<MainMenu>>
|
||||
{
|
||||
public:
|
||||
BatteryMenu()
|
||||
{
|
||||
constructMenuItem<makeComponent<MenuItem, currentBatteryStatus, DisabledColor, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_CELL_SERIES, BatterySeriesCellsAccessor>, SwitchScreenAction<BatteryCellSeriesChangeScreen>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_CELL_PARALLEL, BatteryParallelCellsAccessor>, SwitchScreenAction<BatteryCellParallelChangeScreen>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_SELECT_CELL_TYPE>, SwitchScreenAction<BatteryTypeMenu>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<MainMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||
}
|
||||
};
|
||||
} // Namespace
|
@ -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<makeComponent<MenuItem, currentSelectedAnimationText, DisabledColor, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_DEFAULTRAINBOW>, LedstripAnimationDefaultRainbowAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BETTERRAINBOW>, LedstripAnimationBetterRainbowAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_SPEEDSYNCANIMATION>, LedstripAnimationSyncToSpeedAction>>();
|
||||
|
@ -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<makeComponent<MenuItem, currentSelectedBlinkAnimationText, DisabledColor, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKNONE>, LedstripAnimationBlinkNoneAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKLEFT>, LedstripAnimationBlinkLeftAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKRIGHT>, LedstripAnimationBlinkRightAction>>();
|
||||
|
@ -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<makeComponent<MenuItem, StaticText<TEXT_PRESETS>, SwitchScreenAction<PresetsMenu>, StaticMenuItemIcon<&icons::presets>>>(); }
|
||||
if (!simplified) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_PROFILES>, SwitchScreenAction<ProfilesMenu>>>(); }
|
||||
if (!simplified) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_GRAPHS>, SwitchScreenAction<GraphsMenu>, StaticMenuItemIcon<&icons::graph>>>(); }
|
||||
if (!simplified) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERY>, SwitchScreenAction<BatteryMenu>, StaticMenuItemIcon<&icons::battery>>>(); }
|
||||
#if defined(FEATURE_CAN) && defined(FEATURE_POWERSUPPLY)
|
||||
if (!simplified) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_POWERSUPPLY>, SwitchScreenAction<PowerSupplyDisplay>>>(); }
|
||||
#endif
|
||||
|
65
main/displays/menus/selectbatterytypemenu.h
Normal file
65
main/displays/menus/selectbatterytypemenu.h
Normal file
@ -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<TEXT_SELECT_CELL_TYPE>,
|
||||
public BackActionInterface<SwitchScreenAction<BatteryMenu>>
|
||||
{
|
||||
public:
|
||||
BatteryTypeMenu()
|
||||
{
|
||||
constructMenuItem<makeComponent<MenuItem, currentBatteryType, DisabledColor, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERY_TYPE_22P>, BatterySelectType22PAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERY_TYPE_HG2>, BatterySelectTypeHG2Action>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERY_TYPE_MH1>, BatterySelectTypeMH1Action>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERY_TYPE_VTC5>, BatterySelectTypeVTC5Action>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<MainMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||
}
|
||||
};
|
||||
} // Namespace
|
@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#define FEATURE_LEDSTRIP
|
||||
#ifdef FEATURE_LEDSTRIP
|
||||
// 3rdparty lib includes
|
||||
#include <FastLED.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
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
12
main/texts.h
12
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";
|
||||
|
Reference in New Issue
Block a user