Added profile reset functionallity
This commit is contained in:
@ -79,7 +79,7 @@ constexpr char TEXT_DEBUG[] = "Debug";
|
|||||||
constexpr char TEXT_BATTERY[] = "Battery";
|
constexpr char TEXT_BATTERY[] = "Battery";
|
||||||
constexpr char TEXT_BATTERYDEBUG[] = "Bat Debug Menu";
|
constexpr char TEXT_BATTERYDEBUG[] = "Bat Debug Menu";
|
||||||
constexpr char TEXT_TOGGLECLOUDDEBUG[] = "Cloud Debug";
|
constexpr char TEXT_TOGGLECLOUDDEBUG[] = "Cloud Debug";
|
||||||
constexpr char TEXT_MANAGEPROFILESMENU[] = "Manage Profile Settings";
|
constexpr char TEXT_MANAGEPROFILESMENU[] = "Manage Profiles";
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -116,8 +116,8 @@ MainMenu::MainMenu()
|
|||||||
if (SHOWITEM) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BMS>, SwitchScreenAction<BmsMenu>, StaticMenuItemIcon<&bobbyicons::bms>>>(); }
|
if (SHOWITEM) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BMS>, SwitchScreenAction<BmsMenu>, StaticMenuItemIcon<&bobbyicons::bms>>>(); }
|
||||||
#endif
|
#endif
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_DEMOS>, SwitchScreenAction<DemosMenu>, StaticMenuItemIcon<&bobbyicons::demos>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_DEMOS>, SwitchScreenAction<DemosMenu>, StaticMenuItemIcon<&bobbyicons::demos>>>();
|
||||||
if (SHOWITEM) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_PROFILES>, SwitchScreenAction<ProfilesMenu>>>(); }
|
if (SHOWITEM) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_PROFILES>, SwitchScreenAction<ProfilesMenu>, StaticMenuItemIcon<&bobbyicons::presets>>>(); }
|
||||||
if (SHOWITEM) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_MANAGEPROFILESMENU>,SwitchScreenAction<ManageProfilesMenu>>>(); }
|
if (SHOWITEM) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_MANAGEPROFILESMENU>,SwitchScreenAction<ManageProfilesMenu>, StaticMenuItemIcon<&bobbyicons::presets>>>(); }
|
||||||
if (SHOWITEM) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_DEBUG>, SwitchScreenAction<DebugMenu>>>(); }
|
if (SHOWITEM) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_DEBUG>, SwitchScreenAction<DebugMenu>>>(); }
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_POWEROFF>, SwitchScreenAction<PoweroffDisplay>, StaticMenuItemIcon<&bobbyicons::poweroff>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_POWEROFF>, SwitchScreenAction<PoweroffDisplay>, StaticMenuItemIcon<&bobbyicons::poweroff>>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_REBOOT>, RebootAction, StaticMenuItemIcon<&bobbyicons::reboot>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_REBOOT>, RebootAction, StaticMenuItemIcon<&bobbyicons::reboot>>>();
|
||||||
|
@ -2,30 +2,184 @@
|
|||||||
|
|
||||||
// 3rdparty lib includes
|
// 3rdparty lib includes
|
||||||
#include <icons/back.h>
|
#include <icons/back.h>
|
||||||
|
#include <TFT_eSPI.h>
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "actions/switchscreenaction.h"
|
#include "actions/switchscreenaction.h"
|
||||||
|
#include "bobbyerrorhandler.h"
|
||||||
|
#include "globals.h"
|
||||||
#include "mainmenu.h"
|
#include "mainmenu.h"
|
||||||
|
#include "presets.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
namespace {
|
constexpr const char * const TAG = "ProfileManager";
|
||||||
constexpr char TEXT_MANAGEPROFILESMENU[] = "Manage Profiles Menu";
|
|
||||||
constexpr char TEXT_BACK[] = "Back";
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace espgui;
|
using namespace espgui;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr char TEXT_MANAGEPROFILESMENU[] = "Manage Profiles Menu";
|
||||||
|
constexpr char TEXT_BACK[] = "Back";
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
class ManageProfileMenuItem : public MenuItem
|
||||||
|
{
|
||||||
|
using Base = MenuItem;
|
||||||
|
public:
|
||||||
|
ManageProfileMenuItem(ManageProfilesMenu &menu, const uint8_t profileIndex) : m_menu{menu}, m_profileIndex{profileIndex} {}
|
||||||
|
void copy()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void swap()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear()
|
||||||
|
{
|
||||||
|
if (m_mode == CONFIRMCLEAR)
|
||||||
|
{
|
||||||
|
m_menu.unlock();
|
||||||
|
ESP_LOGI(TAG, "Reseting profile %i...", m_profileIndex);
|
||||||
|
profileSettings = presets::defaultProfileSettings;
|
||||||
|
m_mode = _DEFAULT;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_menu.lock();
|
||||||
|
m_mode = CONFIRMCLEAR;
|
||||||
|
BobbyErrorHandler{}.errorOccured("Press CONFIRM to reset Profile or BACK to cancel.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string text() const override
|
||||||
|
{
|
||||||
|
switch (m_mode)
|
||||||
|
{
|
||||||
|
case _DEFAULT:
|
||||||
|
return fmt::format("Profile {}", m_profileIndex);
|
||||||
|
case CONFIRMCLEAR:
|
||||||
|
return fmt::format("&1Profile {}", m_profileIndex);
|
||||||
|
}
|
||||||
|
return fmt::format("Profile {}", m_profileIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
int color() const override
|
||||||
|
{
|
||||||
|
if (m_mode == CONFIRMCLEAR)
|
||||||
|
return TFT_RED;
|
||||||
|
else if (m_menu.m_locked)
|
||||||
|
return TFT_DARKGREY;
|
||||||
|
return TFT_WHITE;
|
||||||
|
};
|
||||||
|
|
||||||
|
void triggered() override
|
||||||
|
{
|
||||||
|
switch (m_menu.m_action)
|
||||||
|
{
|
||||||
|
case Actions::Clear:
|
||||||
|
clear();
|
||||||
|
break;
|
||||||
|
case Actions::Copy:
|
||||||
|
copy();
|
||||||
|
break;
|
||||||
|
case Actions::Swap:
|
||||||
|
swap();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void update() override
|
||||||
|
{
|
||||||
|
Base::update();
|
||||||
|
if (m_mode != _DEFAULT && !m_menu.m_locked)
|
||||||
|
m_mode = _DEFAULT;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
enum Mode : uint8_t {
|
||||||
|
_DEFAULT,
|
||||||
|
CONFIRMCLEAR
|
||||||
|
} m_mode;
|
||||||
|
ManageProfilesMenu &m_menu;
|
||||||
|
const uint8_t m_profileIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ManageProfileModeMenuItem : public MenuItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ManageProfileModeMenuItem(ManageProfilesMenu &menu) : m_menu{menu} {}
|
||||||
|
std::string text() const override {
|
||||||
|
return fmt::format("&7{}", m_menu.action_text());
|
||||||
|
}
|
||||||
|
|
||||||
|
void triggered() override {
|
||||||
|
m_menu.m_action = Actions((uint8_t)m_menu.m_action+1);
|
||||||
|
|
||||||
|
if(m_menu.m_action == Actions::__END__)
|
||||||
|
{
|
||||||
|
m_menu.m_action = Actions(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
ManageProfilesMenu &m_menu;
|
||||||
|
};
|
||||||
|
|
||||||
ManageProfilesMenu::ManageProfilesMenu()
|
ManageProfilesMenu::ManageProfilesMenu()
|
||||||
{
|
{
|
||||||
|
for (uint8_t i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
constructMenuItem<ManageProfileMenuItem>(*this, i);
|
||||||
|
}
|
||||||
|
constructMenuItem<ManageProfileModeMenuItem>(*this);
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<MainMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<MainMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ManageProfilesMenu::start()
|
||||||
|
{
|
||||||
|
Base::start();
|
||||||
|
m_oldMode = currentMode;
|
||||||
|
currentMode = &m_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ManageProfilesMenu::stop()
|
||||||
|
{
|
||||||
|
Base::stop();
|
||||||
|
|
||||||
|
if (currentMode == &m_mode)
|
||||||
|
{
|
||||||
|
m_mode.stop();
|
||||||
|
lastMode = nullptr;
|
||||||
|
currentMode = m_oldMode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ManageProfilesMenu::back()
|
void ManageProfilesMenu::back()
|
||||||
{
|
{
|
||||||
switchScreen<MainMenu>();
|
if (!m_locked)
|
||||||
|
switchScreen<MainMenu>();
|
||||||
|
else
|
||||||
|
m_locked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ManageProfilesMenu::text() const
|
std::string ManageProfilesMenu::text() const
|
||||||
{
|
{
|
||||||
return TEXT_MANAGEPROFILESMENU;
|
return TEXT_MANAGEPROFILESMENU;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string ManageProfilesMenu::action_text() const {
|
||||||
|
return toString(m_action);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ManageProfilesMenu::lock() {
|
||||||
|
m_locked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ManageProfilesMenu::unlock() {
|
||||||
|
m_locked = false;
|
||||||
|
}
|
||||||
// functions: clear profile, copy profile, move profile
|
// functions: clear profile, copy profile, move profile
|
||||||
|
// TODO: If m_locked == true, only confirm and back (espgui::Button::Right and espgui::Button::Left) should be allowed to pass to the menuitems.
|
||||||
|
//
|
||||||
|
@ -1,14 +1,38 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <cpptypesafeenum.h>
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include <displays/bobbymenudisplay.h>
|
#include "displays/bobbymenudisplay.h"
|
||||||
|
#include "modes/ignoreinputmode.h"
|
||||||
|
|
||||||
|
#define ActionValues(x) \
|
||||||
|
x(Clear) \
|
||||||
|
x(Copy) \
|
||||||
|
x(Swap) \
|
||||||
|
x(__END__)
|
||||||
|
DECLARE_TYPESAFE_ENUM(Actions, : uint8_t, ActionValues)
|
||||||
|
|
||||||
class ManageProfilesMenu : public BobbyMenuDisplay
|
class ManageProfilesMenu : public BobbyMenuDisplay
|
||||||
{
|
{
|
||||||
|
friend class ManageProfileMenuItem;
|
||||||
|
friend class ManageProfileModeMenuItem;
|
||||||
|
using Base = BobbyMenuDisplay;
|
||||||
public:
|
public:
|
||||||
ManageProfilesMenu();
|
ManageProfilesMenu();
|
||||||
|
void start() override;
|
||||||
|
void stop() override;
|
||||||
|
|
||||||
std::string text() const override;
|
std::string text() const override;
|
||||||
|
std::string action_text() const;
|
||||||
void back() override;
|
void back() override;
|
||||||
|
void lock();
|
||||||
|
void unlock();
|
||||||
|
private:
|
||||||
|
ModeInterface *m_oldMode;
|
||||||
|
IgnoreInputMode m_mode{0, bobbycar::protocol::ControlType::FieldOrientedControl, bobbycar::protocol::ControlMode::Torque};
|
||||||
|
protected:
|
||||||
|
bool m_locked{false};
|
||||||
|
Actions m_action{Actions::Clear};
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user