Merge pull request #254 from bobbycar-graz/code-cleanup
This commit is contained in:
@ -42,13 +42,13 @@ set(headers
|
||||
bobbycheckbox.h
|
||||
bobbyerrorhandler.h
|
||||
bobbyquickactions.h
|
||||
bobbytypesafeenum.h
|
||||
buildserver.h
|
||||
can.h
|
||||
changevaluedisplay_bluetoothmode.h
|
||||
changevaluedisplay_bobbyquickactions.h
|
||||
changevaluedisplay_controlmode.h
|
||||
changevaluedisplay_controltype.h
|
||||
changevaluedisplay_handbremsmode.h
|
||||
changevaluedisplay_larsmmode_mode.h
|
||||
changevaluedisplay_unifiedmodelmode.h
|
||||
cloud.h
|
||||
@ -105,7 +105,6 @@ set(headers
|
||||
displays/menus/invertmenu.h
|
||||
displays/menus/larsmmodesettingsmenu.h
|
||||
displays/menus/ledstripmenu.h
|
||||
displays/menus/ledstripselectanimationmenu.h
|
||||
displays/menus/ledstripselectblinkmenu.h
|
||||
displays/menus/ledstripselectotamode.h
|
||||
displays/menus/limitssettingsmenu.h
|
||||
@ -120,7 +119,6 @@ set(headers
|
||||
displays/menus/networksettingsmenu.h
|
||||
displays/menus/otamenu.h
|
||||
displays/menus/profilesmenu.h
|
||||
displays/menus/selectbatterytypemenu.h
|
||||
displays/menus/selectbuildserverbranch.h
|
||||
displays/menus/selectbuildservermenu.h
|
||||
displays/menus/selectmodemenu.h
|
||||
@ -132,6 +130,7 @@ set(headers
|
||||
displays/menus/tempomatmodesettingsmenu.h
|
||||
displays/menus/timersmenu.h
|
||||
displays/menus/timesettingsmenu.h
|
||||
displays/menus/typesafeenumchangemenu.h
|
||||
displays/menus/udpcloudsettingsmenu.h
|
||||
displays/menus/wifiapclientsmenu.h
|
||||
displays/menus/wifiapsettingsmenu.h
|
||||
@ -281,7 +280,6 @@ set(sources
|
||||
changevaluedisplay_bobbyquickactions.cpp
|
||||
changevaluedisplay_controlmode.cpp
|
||||
changevaluedisplay_controltype.cpp
|
||||
changevaluedisplay_handbremsmode.cpp
|
||||
changevaluedisplay_larsmmode_mode.cpp
|
||||
changevaluedisplay_unifiedmodelmode.cpp
|
||||
cloud.cpp
|
||||
@ -336,7 +334,6 @@ set(sources
|
||||
displays/menus/invertmenu.cpp
|
||||
displays/menus/larsmmodesettingsmenu.cpp
|
||||
displays/menus/ledstripmenu.cpp
|
||||
displays/menus/ledstripselectanimationmenu.cpp
|
||||
displays/menus/ledstripselectblinkmenu.cpp
|
||||
displays/menus/ledstripselectotamode.cpp
|
||||
displays/menus/limitssettingsmenu.cpp
|
||||
@ -351,7 +348,6 @@ set(sources
|
||||
displays/menus/networksettingsmenu.cpp
|
||||
displays/menus/otamenu.cpp
|
||||
displays/menus/profilesmenu.cpp
|
||||
displays/menus/selectbatterytypemenu.cpp
|
||||
displays/menus/selectbuildserverbranch.cpp
|
||||
displays/menus/selectbuildservermenu.cpp
|
||||
displays/menus/selectmodemenu.cpp
|
||||
@ -363,6 +359,7 @@ set(sources
|
||||
displays/menus/tempomatmodesettingsmenu.cpp
|
||||
displays/menus/timersmenu.cpp
|
||||
displays/menus/timesettingsmenu.cpp
|
||||
displays/menus/typesafeenumchangemenu.cpp
|
||||
displays/menus/udpcloudsettingsmenu.cpp
|
||||
displays/menus/wifiapclientsmenu.cpp
|
||||
displays/menus/wifiapsettingsmenu.cpp
|
||||
|
@ -0,0 +1,8 @@
|
||||
#include "ledstripanimationactions.h"
|
||||
#ifdef FEATURE_LEDSTRIP
|
||||
void LedStripSetAnimationAction::triggered()
|
||||
{
|
||||
if (auto result = configs.write_config(configs.ledstrip.animationType, m_animation); !result)
|
||||
BobbyErrorHandler{}.errorOccured(std::move(result).error());
|
||||
}
|
||||
#endif
|
||||
|
@ -11,16 +11,23 @@
|
||||
|
||||
#ifdef FEATURE_LEDSTRIP
|
||||
template<LedstripAnimation type>
|
||||
class LedStripSetAnimationActionStatic : public virtual espgui::ActionInterface
|
||||
{
|
||||
public:
|
||||
void triggered() override
|
||||
{
|
||||
if (auto result = configs.write_config(configs.ledstrip.animationType, type); !result)
|
||||
BobbyErrorHandler{}.errorOccured(std::move(result).error());
|
||||
}
|
||||
};
|
||||
|
||||
class LedStripSetAnimationAction : public virtual espgui::ActionInterface
|
||||
{
|
||||
public:
|
||||
LedStripSetAnimationAction(LedstripAnimation animation) : m_animation{animation} {};
|
||||
void triggered() override;
|
||||
private:
|
||||
const LedstripAnimation m_animation;
|
||||
};
|
||||
|
||||
template<LedstripAnimation type>
|
||||
void LedStripSetAnimationAction<type>::triggered()
|
||||
{
|
||||
if (auto result = configs.write_config(configs.ledstrip.animationType, type); !result)
|
||||
BobbyErrorHandler{}.errorOccured(std::move(result).error());
|
||||
}
|
||||
#endif
|
||||
|
@ -3,8 +3,8 @@
|
||||
// system includes
|
||||
#include <cstdint>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <cpptypesafeenum.h>
|
||||
// local includes
|
||||
#include <bobbytypesafeenum.h>
|
||||
|
||||
#define BatteryCellTypeValues(x) \
|
||||
x(_22P) \
|
||||
@ -13,7 +13,7 @@
|
||||
x(VTC5) \
|
||||
x(BAK_25R) \
|
||||
x(HE4)
|
||||
DECLARE_TYPESAFE_ENUM(BatteryCellType, : uint8_t, BatteryCellTypeValues)
|
||||
DECLARE_BOBBYTYPESAFE_ENUM(BatteryCellType, : uint8_t, BatteryCellTypeValues)
|
||||
|
||||
float getBatteryPercentage(float batVoltage, BatteryCellType cellType);
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <cpptypesafeenum.h>
|
||||
#include <buttonsinterface.h>
|
||||
#include <cpptypesafeenum.h>
|
||||
|
||||
// local includes
|
||||
#include "bobbybuttons.h"
|
||||
|
19
main/bobbytypesafeenum.h
Normal file
19
main/bobbytypesafeenum.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <cpptypesafeenum.h>
|
||||
|
||||
template<typename T>
|
||||
struct iterateEnum;
|
||||
|
||||
#define DECLARE_BOBBYTYPESAFE_ENUM(Name, Derivation, Values) \
|
||||
DECLARE_TYPESAFE_ENUM(Name, Derivation, Values) \
|
||||
\
|
||||
template<> \
|
||||
struct iterateEnum<Name> { \
|
||||
template<typename T> \
|
||||
static void iterate(T&&cb) \
|
||||
{ \
|
||||
return iterate##Name(std::forward<T>(cb)); \
|
||||
} \
|
||||
};
|
@ -5,6 +5,7 @@
|
||||
#include <configutils_priv_enum.h>
|
||||
|
||||
// local includes
|
||||
#include "battery.h"
|
||||
#include "ledstrip.h"
|
||||
#include "handbremse.h"
|
||||
#include "bobbyquickactions.h"
|
||||
@ -13,3 +14,4 @@ IMPLEMENT_NVS_GET_SET_ENUM(OtaAnimationModes)
|
||||
IMPLEMENT_NVS_GET_SET_ENUM(HandbremseMode)
|
||||
IMPLEMENT_NVS_GET_SET_ENUM(LedstripAnimation)
|
||||
IMPLEMENT_NVS_GET_SET_ENUM(BobbyQuickActions)
|
||||
IMPLEMENT_NVS_GET_SET_ENUM(BatteryCellType)
|
||||
|
@ -8,3 +8,4 @@ INSTANTIATE_CONFIGWRAPPER_TEMPLATES(OtaAnimationModes)
|
||||
INSTANTIATE_CONFIGWRAPPER_TEMPLATES(HandbremseMode)
|
||||
INSTANTIATE_CONFIGWRAPPER_TEMPLATES(LedstripAnimation)
|
||||
INSTANTIATE_CONFIGWRAPPER_TEMPLATES(BobbyQuickActions)
|
||||
INSTANTIATE_CONFIGWRAPPER_TEMPLATES(BatteryCellType)
|
||||
|
@ -12,29 +12,21 @@
|
||||
#include <tftinstance.h>
|
||||
|
||||
// Local includes
|
||||
#include "utils.h"
|
||||
#include "icons/settings.h"
|
||||
#include "battery.h"
|
||||
#include "selectbatterytypemenu.h"
|
||||
#include "displays/bobbychangevaluedisplay.h"
|
||||
#include "mainmenu.h"
|
||||
#include "displays/calibratevoltagedisplay.h"
|
||||
#include "accessors/settingsaccessors.h"
|
||||
#include "battery.h"
|
||||
#include "displays/bobbychangevaluedisplay.h"
|
||||
#include "displays/calibratevoltagedisplay.h"
|
||||
#include "icons/settings.h"
|
||||
#include "mainmenu.h"
|
||||
#include "typesafeenumchangemenu.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace {
|
||||
constexpr char TEXT_BATTERY[] = "Battery";
|
||||
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";
|
||||
constexpr char TEXT_BATTERY_TYPE_BAK_25R[] = "BAK / 25R cells";
|
||||
constexpr char TEXT_BATTERY_TYPE_HE4[] = "HE4 cells";
|
||||
constexpr char TEXT_BATTERY_WHKM[] = "Wh per km";
|
||||
constexpr char TEXT_BATTERY_APPLYCALIB[] = "Apply calibration";
|
||||
constexpr char TEXT_VOLTAGECALIBRATION_RESET[] = "Reset calibration";
|
||||
@ -85,7 +77,7 @@ BatteryMenu::BatteryMenu()
|
||||
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_CELL_SERIES, BatterySeriesCellsAccessor>, SwitchScreenAction<BatteryCellSeriesChangeScreen>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_CELL_PARALLEL, BatteryParallelCellsAccessor>, SwitchScreenAction<BatteryCellParallelChangeScreen>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_BATTERY_WHKM, BatteryWHperKMAccessor>, SwitchScreenAction<BatteryWHperKMChangeScreen>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_SELECT_CELL_TYPE>, SwitchScreenAction<BatteryTypeMenu>>>();
|
||||
constructMenuItem<SwitchScreenTypeSafeChangeMenuItem<BatteryCellType, BatteryMenu, TEXT_SELECT_CELL_TYPE>>(&configs.battery.cellType);
|
||||
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, WhStatisticsText, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERY_CALIBRATE>, SwitchScreenAction<CalibrateVoltageDisplay>, StaticMenuItemIcon<&bobbyicons::settings>>>();
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
// local includes
|
||||
#include "displays/bobbychangevaluedisplay.h"
|
||||
#include "displays/menus/typesafeenumchangemenu.h"
|
||||
#include "accessors/settingsaccessors.h"
|
||||
#include "changevaluedisplay_handbremsmode.h"
|
||||
#include "displays/menus/defaultmodesettingsmenu.h"
|
||||
@ -30,21 +31,6 @@ using HandBremsTriggerTimeoutChangeValueDisplay = espgui::makeComponent<
|
||||
espgui::ConfirmActionInterface<espgui::SwitchScreenAction<HandbremsSettingsMenu>>,
|
||||
espgui::BackActionInterface<espgui::SwitchScreenAction<HandbremsSettingsMenu>>
|
||||
>;
|
||||
using HandBremsModeChangeValueDisplay = espgui::makeComponent<
|
||||
BobbyChangeValueDisplay<HandbremseMode>,
|
||||
espgui::StaticText<TEXT_HANDBREMSE_MODE>,
|
||||
HandbremsModeAccessor,
|
||||
espgui::ConfirmActionInterface<espgui::SwitchScreenAction<HandbremsSettingsMenu>>,
|
||||
espgui::BackActionInterface<espgui::SwitchScreenAction<HandbremsSettingsMenu>>
|
||||
>;
|
||||
class HandBremsModeText : public virtual espgui::TextInterface
|
||||
{
|
||||
public:
|
||||
std::string text() const override
|
||||
{
|
||||
return fmt::format("Mode: &2{}", configs.handbremse.mode.valueAsString());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
HandbremsSettingsMenu::HandbremsSettingsMenu()
|
||||
@ -53,7 +39,7 @@ HandbremsSettingsMenu::HandbremsSettingsMenu()
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_HANDBREMSE_ENABLE>, BobbyCheckbox, HandbremsEnabledAccessor>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_HANDBREMSE_AUTOMATIC>, BobbyCheckbox, HandbremsAutomaticAccessor>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_HANDBREMSE_VISUALIZE>, BobbyCheckbox, HandbremsVisualizeAccessor>>();
|
||||
constructMenuItem<makeComponent<MenuItem, HandBremsModeText, SwitchScreenAction<HandBremsModeChangeValueDisplay>>>();
|
||||
constructMenuItem<SwitchScreenTypeSafeChangeMenuItem<HandbremseMode, HandbremsSettingsMenu, TEXT_HANDBREMSE_MODE>>(&configs.handbremse.mode);
|
||||
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_HANDBREMSE_TRIGGERTIMEOUT, HandbremsTimeoutAccessor>, SwitchScreenAction<HandBremsTriggerTimeoutChangeValueDisplay>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<DefaultModeSettingsMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||
}
|
||||
|
@ -11,16 +11,16 @@
|
||||
#include <textwithvaluehelper.h>
|
||||
|
||||
// local includes
|
||||
#include "displays/bobbychangevaluedisplay.h"
|
||||
#include "accessors/settingsaccessors.h"
|
||||
#include "bobbycheckbox.h"
|
||||
#include "displays/bobbychangevaluedisplay.h"
|
||||
#include "displays/ledstripcolorsdisplay.h"
|
||||
#include "displays/menus/ledstripselectotamode.h"
|
||||
#include "displays/menus/mainmenu.h"
|
||||
#include "displays/menus/typesafeenumchangemenu.h"
|
||||
#include "globals.h"
|
||||
#include "ledstrip.h"
|
||||
#include "ledstripselectanimationmenu.h"
|
||||
#include "ledstripselectblinkmenu.h"
|
||||
#include "bobbycheckbox.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
@ -149,7 +149,7 @@ LedstripMenu::LedstripMenu()
|
||||
constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_STVO_ENABLEFRONTLIGHT>, BobbyCheckbox, EnableLedstripStVOFrontlight>>();
|
||||
|
||||
constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_LEDANIMATION>, BobbyCheckbox, EnableLedAnimationAccessor>>();
|
||||
constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_SELECTANIMATION>, espgui::SwitchScreenAction<LedstripSelectAnimationMenu>>>();
|
||||
constructMenuItem<SwitchScreenTypeSafeChangeMenuItem<LedstripAnimation, LedstripMenu, TEXT_SELECTANIMATION>>(&configs.ledstrip.animationType);
|
||||
|
||||
constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_BRAKELIGHTS>, BobbyCheckbox, EnableBrakeLightsAccessor>>();
|
||||
|
||||
|
@ -1,72 +0,0 @@
|
||||
#include "ledstripselectanimationmenu.h"
|
||||
|
||||
// Local includes
|
||||
#include "actions/dummyaction.h"
|
||||
#include "actions/ledstripanimationactions.h"
|
||||
#include "actions/switchscreenaction.h"
|
||||
#include "icons/back.h"
|
||||
#include "ledstripdefines.h"
|
||||
#include "ledstripmenu.h"
|
||||
#include "newsettings.h"
|
||||
|
||||
#ifdef FEATURE_LEDSTRIP
|
||||
namespace {
|
||||
constexpr char TEXT_SELECTANIMATION[] = "Select Animation";
|
||||
constexpr char TEXT_ANIMATION_DEFAULTRAINBOW[] = "Default Rainbow";
|
||||
constexpr char TEXT_ANIMATION_BETTERRAINBOW[] = "Better Rainbow";
|
||||
constexpr char TEXT_ANIMATION_SPEEDSYNCANIMATION[] = "Speed Sync";
|
||||
constexpr char TEXT_ANIMATION_CUSTOMCOLOR[] = "Custom Color";
|
||||
constexpr char TEXT_BACK[] = "Back";
|
||||
|
||||
class CurrentSelectedAnimationText : public virtual espgui::TextInterface
|
||||
{
|
||||
public:
|
||||
std::string text() const override;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
LedstripSelectAnimationMenu::LedstripSelectAnimationMenu()
|
||||
{
|
||||
using namespace espgui;
|
||||
|
||||
constructMenuItem<makeComponent<MenuItem, CurrentSelectedAnimationText, DisabledColor, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_DEFAULTRAINBOW>, LedStripSetAnimationAction<LedstripAnimation::DefaultRainbow>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BETTERRAINBOW>, LedStripSetAnimationAction<LedstripAnimation::BetterRainbow>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_SPEEDSYNCANIMATION>, LedStripSetAnimationAction<LedstripAnimation::SpeedSync>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_CUSTOMCOLOR>, LedStripSetAnimationAction<LedstripAnimation::CustomColor>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<LedstripMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||
}
|
||||
|
||||
std::string LedstripSelectAnimationMenu::text() const
|
||||
{
|
||||
return TEXT_SELECTANIMATION;
|
||||
}
|
||||
|
||||
void LedstripSelectAnimationMenu::back()
|
||||
{
|
||||
espgui::switchScreen<LedstripMenu>();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
std::string CurrentSelectedAnimationText::text() const
|
||||
{
|
||||
switch (configs.ledstrip.animationType.value)
|
||||
{
|
||||
case LedstripAnimation::DefaultRainbow:
|
||||
return TEXT_ANIMATION_DEFAULTRAINBOW;
|
||||
case LedstripAnimation::BetterRainbow:
|
||||
return TEXT_ANIMATION_BETTERRAINBOW;
|
||||
case LedstripAnimation::SpeedSync:
|
||||
return TEXT_ANIMATION_SPEEDSYNCANIMATION;
|
||||
case LedstripAnimation::CustomColor:
|
||||
return TEXT_ANIMATION_CUSTOMCOLOR;
|
||||
default:
|
||||
return "Animation Unkown";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
#endif
|
@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// Local includes
|
||||
#include "displays/bobbymenudisplay.h"
|
||||
|
||||
#ifdef FEATURE_LEDSTRIP
|
||||
class LedstripSelectAnimationMenu : public BobbyMenuDisplay
|
||||
{
|
||||
public:
|
||||
LedstripSelectAnimationMenu();
|
||||
|
||||
std::string text() const override;
|
||||
|
||||
void back() override;
|
||||
};
|
||||
#endif
|
@ -1,73 +0,0 @@
|
||||
#include "selectbatterytypemenu.h"
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <menuitem.h>
|
||||
#include <icons/back.h>
|
||||
#include <actions/switchscreenaction.h>
|
||||
#include <actioninterface.h>
|
||||
#include <actions/dummyaction.h>
|
||||
|
||||
// local includes
|
||||
#include "battery.h"
|
||||
#include "newsettings.h"
|
||||
#include "utils.h"
|
||||
#include "displays/menus/batterymenu.h"
|
||||
#include "batterymenu.h"
|
||||
#include "displays/menus/mainmenu.h"
|
||||
|
||||
namespace {
|
||||
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";
|
||||
constexpr char TEXT_BATTERY_TYPE_BAK_25R[] = "BAK / 25R cells";
|
||||
constexpr char TEXT_BATTERY_TYPE_HE4[] = "HE4 cells";
|
||||
constexpr char TEXT_BATTERY_WHKM[] = "Wh per km";
|
||||
constexpr char TEXT_BATTERY_APPLYCALIB[] = "Apply calibration";
|
||||
constexpr char TEXT_VOLTAGECALIBRATION_RESET[] = "Reset calibration";
|
||||
constexpr char TEXT_BACK[] = "Back";
|
||||
|
||||
class CurrentBatteryTypeText : public virtual espgui::TextInterface
|
||||
{
|
||||
public:
|
||||
std::string text() const override
|
||||
{
|
||||
return getBatteryCellTypeString();
|
||||
}
|
||||
};
|
||||
|
||||
template<BatteryCellType T>
|
||||
class BatterySelectTypeAction : public virtual espgui::ActionInterface
|
||||
{
|
||||
public:
|
||||
void triggered() override { configs.write_config(configs.battery.cellType, uint8_t(T)); }
|
||||
};
|
||||
} // namespace
|
||||
|
||||
BatteryTypeMenu::BatteryTypeMenu()
|
||||
{
|
||||
using namespace espgui;
|
||||
constructMenuItem<makeComponent<MenuItem, CurrentBatteryTypeText, DisabledColor, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERY_TYPE_22P>, BatterySelectTypeAction<BatteryCellType::_22P>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERY_TYPE_HG2>, BatterySelectTypeAction<BatteryCellType::HG2>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERY_TYPE_MH1>, BatterySelectTypeAction<BatteryCellType::MH1>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERY_TYPE_VTC5>, BatterySelectTypeAction<BatteryCellType::VTC5>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERY_TYPE_BAK_25R>, BatterySelectTypeAction<BatteryCellType::BAK_25R>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERY_TYPE_HE4>, BatterySelectTypeAction<BatteryCellType::HE4>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<MainMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||
}
|
||||
|
||||
std::string BatteryTypeMenu::text() const
|
||||
{
|
||||
return TEXT_SELECT_CELL_TYPE;
|
||||
}
|
||||
|
||||
void BatteryTypeMenu::back()
|
||||
{
|
||||
espgui::switchScreen<BatteryMenu>();
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// Local includes
|
||||
#include "displays/bobbymenudisplay.h"
|
||||
|
||||
class BatteryTypeMenu : public BobbyMenuDisplay
|
||||
{
|
||||
public:
|
||||
BatteryTypeMenu();
|
||||
|
||||
std::string text() const override;
|
||||
|
||||
void back() override;
|
||||
};
|
1
main/displays/menus/typesafeenumchangemenu.cpp
Normal file
1
main/displays/menus/typesafeenumchangemenu.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "typesafeenumchangemenu.h"
|
109
main/displays/menus/typesafeenumchangemenu.h
Normal file
109
main/displays/menus/typesafeenumchangemenu.h
Normal file
@ -0,0 +1,109 @@
|
||||
#pragma once
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <configwrapper.h>
|
||||
#include <fmt/core.h>
|
||||
#include <icons/back.h>
|
||||
|
||||
// local includes
|
||||
#include "globals.h"
|
||||
#include "actions/dummyaction.h"
|
||||
#include "actions/switchscreenaction.h"
|
||||
#include "displays/bobbymenudisplay.h"
|
||||
#include "bobbyerrorhandler.h"
|
||||
|
||||
namespace typesafeenumchangemenu {
|
||||
constexpr char TEXT_BACK[] = "Back";
|
||||
|
||||
template<typename TEnum>
|
||||
class TypesafeEnumCurrentValueMenuItem :
|
||||
public espgui::MenuItem
|
||||
{
|
||||
public:
|
||||
TypesafeEnumCurrentValueMenuItem(ConfigWrapper<TEnum>* config) : m_config{config} {}
|
||||
std::string text() const override
|
||||
{
|
||||
return toString(m_config->value);
|
||||
}
|
||||
void triggered() override {}
|
||||
|
||||
int color() const override
|
||||
{
|
||||
return TFT_DARKGREY;
|
||||
}
|
||||
private:
|
||||
ConfigWrapper<TEnum>* m_config;
|
||||
};
|
||||
|
||||
template<typename TEnum>
|
||||
class TypesafeEnumSetterMenuItem :
|
||||
public espgui::MenuItem
|
||||
{
|
||||
public:
|
||||
TypesafeEnumSetterMenuItem(TEnum value, ConfigWrapper<TEnum>* config) : m_value{value}, m_config{config} {}
|
||||
|
||||
std::string text() const override
|
||||
{
|
||||
return toString(m_value);
|
||||
}
|
||||
|
||||
void triggered() override
|
||||
{
|
||||
if (auto result = m_config->write(configs.nvs_handle_user, m_value); !result)
|
||||
BobbyErrorHandler{}.errorOccured(std::move(result).error());
|
||||
}
|
||||
private:
|
||||
const TEnum m_value;
|
||||
ConfigWrapper<TEnum>* m_config;
|
||||
};
|
||||
|
||||
template<typename TEnum, typename TMenu>
|
||||
class TypeSafeChangeMenu :
|
||||
public BobbyMenuDisplay
|
||||
{
|
||||
public:
|
||||
TypeSafeChangeMenu(ConfigWrapper<TEnum>* config) : m_config{config}
|
||||
{
|
||||
using namespace espgui;
|
||||
using namespace typesafeenumchangemenu;
|
||||
constructMenuItem<TypesafeEnumCurrentValueMenuItem<TEnum>>(m_config);
|
||||
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
|
||||
iterateEnum<TEnum>::iterate([&](TEnum enum_value, const auto &string_value){
|
||||
constructMenuItem<TypesafeEnumSetterMenuItem<TEnum>>(enum_value, m_config);
|
||||
});
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<TMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||
}
|
||||
|
||||
std::string text() const override
|
||||
{
|
||||
return fmt::format("Select {}", m_config->nvsName());
|
||||
}
|
||||
|
||||
void back() override
|
||||
{
|
||||
espgui::switchScreen<TMenu>();
|
||||
}
|
||||
private:
|
||||
ConfigWrapper<TEnum>* m_config;
|
||||
};
|
||||
} // namespace typesafeenumchangemenu
|
||||
|
||||
template<typename TEnum, typename TMenu, const char *Ttext>
|
||||
class SwitchScreenTypeSafeChangeMenuItem : public espgui::MenuItem
|
||||
{
|
||||
public:
|
||||
SwitchScreenTypeSafeChangeMenuItem(ConfigWrapper<TEnum>* config) : m_config{config} {}
|
||||
|
||||
static constexpr const char *STATIC_TEXT = Ttext;
|
||||
std::string text() const override
|
||||
{
|
||||
return Ttext;
|
||||
}
|
||||
|
||||
void triggered() override
|
||||
{
|
||||
espgui::switchScreen<typesafeenumchangemenu::TypeSafeChangeMenu<TEnum, TMenu>>(m_config);
|
||||
}
|
||||
private:
|
||||
ConfigWrapper<TEnum>* m_config;
|
||||
};
|
@ -4,14 +4,16 @@
|
||||
#include <cstdint>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <cpptypesafeenum.h>
|
||||
#include <espchrono.h>
|
||||
|
||||
// local includes
|
||||
#include "bobbytypesafeenum.h"
|
||||
|
||||
#define HandbremseModeValues(x) \
|
||||
x(MOSFETS_OFF) \
|
||||
x(OPENMODE) \
|
||||
x(SPEED_0)
|
||||
DECLARE_TYPESAFE_ENUM(HandbremseMode, : uint8_t, HandbremseModeValues)
|
||||
DECLARE_BOBBYTYPESAFE_ENUM(HandbremseMode, : uint8_t, HandbremseModeValues)
|
||||
|
||||
namespace handbremse {
|
||||
|
||||
|
@ -4,24 +4,24 @@
|
||||
#include <vector>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <cpptypesafeenum.h>
|
||||
#include <FastLED.h>
|
||||
|
||||
// local includes
|
||||
#include "bobbytypesafeenum.h"
|
||||
#include "ledstripdefines.h"
|
||||
|
||||
#define OtaAnimationModesValues(x) \
|
||||
x(None) \
|
||||
x(GreenProgressBar) \
|
||||
x(ColorChangeAll)
|
||||
DECLARE_TYPESAFE_ENUM(OtaAnimationModes, : uint8_t, OtaAnimationModesValues)
|
||||
DECLARE_BOBBYTYPESAFE_ENUM(OtaAnimationModes, : uint8_t, OtaAnimationModesValues)
|
||||
|
||||
#define LedstripAnimationValues(x) \
|
||||
x(DefaultRainbow) \
|
||||
x(BetterRainbow) \
|
||||
x(SpeedSync) \
|
||||
x(CustomColor)
|
||||
DECLARE_TYPESAFE_ENUM(LedstripAnimation, : uint8_t, LedstripAnimationValues)
|
||||
DECLARE_BOBBYTYPESAFE_ENUM(LedstripAnimation, : uint8_t, LedstripAnimationValues)
|
||||
|
||||
#ifdef FEATURE_LEDSTRIP
|
||||
enum Bobbycar_Side
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <makearray.h>
|
||||
|
||||
// local includes
|
||||
#include "battery.h"
|
||||
#include "ledstrip.h"
|
||||
#include "unifiedmodelmode.h"
|
||||
#include "displays/lockscreen.h"
|
||||
@ -253,7 +254,7 @@ public:
|
||||
struct {
|
||||
ConfigWrapper<uint8_t> cellsSeries {12, DoReset, {}, "batteryCS" };
|
||||
ConfigWrapper<uint8_t> cellsParallel {10, DoReset, {}, "batteryCP" };
|
||||
ConfigWrapper<uint8_t> cellType {0, DoReset, {}, "batteryType" };
|
||||
ConfigWrapper<BatteryCellType> cellType {BatteryCellType::_22P, DoReset, {}, "batteryType" };
|
||||
ConfigWrapper<uint16_t> watthoursPerKilometer{25, DoReset, {}, "whkm" };
|
||||
ConfigWrapper<int16_t> front30VoltCalibration{3000, DoReset, {}, "batF30VCal" };
|
||||
ConfigWrapper<int16_t> back30VoltCalibration {3000, DoReset, {}, "batB30VCal" };
|
||||
|
Reference in New Issue
Block a user