Added locked for swap and copy
This commit is contained in:
@ -1,12 +1,12 @@
|
|||||||
#include "manageprofilesmenu.h"
|
#include "manageprofilesmenu.h"
|
||||||
|
|
||||||
// 3rdparty lib includes
|
// 3rdparty lib includes
|
||||||
#include <icons/back.h>
|
|
||||||
#include <TFT_eSPI.h>
|
#include <TFT_eSPI.h>
|
||||||
|
#include <icons/back.h>
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "actions/pushscreenaction.h"
|
|
||||||
#include "actions/popscreenaction.h"
|
#include "actions/popscreenaction.h"
|
||||||
|
#include "actions/pushscreenaction.h"
|
||||||
#include "bobbyerrorhandler.h"
|
#include "bobbyerrorhandler.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "mainmenu.h"
|
#include "mainmenu.h"
|
||||||
@ -14,11 +14,10 @@
|
|||||||
#include "settingsutils.h"
|
#include "settingsutils.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
constexpr const char * const TAG = "ProfileManager";
|
|
||||||
|
|
||||||
using namespace espgui;
|
using namespace espgui;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
constexpr const char * const TAG = "ProfileManager";
|
||||||
constexpr char TEXT_MANAGEPROFILESMENU[] = "Manage Profiles Menu";
|
constexpr char TEXT_MANAGEPROFILESMENU[] = "Manage Profiles Menu";
|
||||||
constexpr char TEXT_BACK[] = "Back";
|
constexpr char TEXT_BACK[] = "Back";
|
||||||
} // namespace
|
} // namespace
|
||||||
@ -36,6 +35,8 @@ public:
|
|||||||
if (!currProfile)
|
if (!currProfile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
m_menu.unlock();
|
||||||
|
|
||||||
settingsutils::switchProfile(m_menu.m_firstIndex);
|
settingsutils::switchProfile(m_menu.m_firstIndex);
|
||||||
|
|
||||||
if (!settingsPersister.openProfile(m_profileIndex)) // just switch nvs namespace
|
if (!settingsPersister.openProfile(m_profileIndex)) // just switch nvs namespace
|
||||||
@ -60,10 +61,11 @@ public:
|
|||||||
}
|
}
|
||||||
else if (m_menu.m_firstIndex != -1 && m_menu.m_firstIndex != m_profileIndex)
|
else if (m_menu.m_firstIndex != -1 && m_menu.m_firstIndex != m_profileIndex)
|
||||||
{
|
{
|
||||||
|
m_menu.lock();
|
||||||
|
m_mode = CONFIRM_COPY;
|
||||||
BobbyErrorHandler{}.errorOccurred(
|
BobbyErrorHandler{}.errorOccurred(
|
||||||
fmt::format("Press CONFIRM to COPY from Profile {} to Profile {}", m_menu.m_firstIndex,
|
fmt::format("Press CONFIRM to COPY from Profile {} to Profile {}", m_menu.m_firstIndex,
|
||||||
m_profileIndex));
|
m_profileIndex));
|
||||||
m_mode = CONFIRM_COPY;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,6 +77,8 @@ public:
|
|||||||
if (!currProfile)
|
if (!currProfile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
m_menu.unlock();
|
||||||
|
|
||||||
settingsutils::switchProfile(m_menu.m_firstIndex);
|
settingsutils::switchProfile(m_menu.m_firstIndex);
|
||||||
const ProfileSettings tmp = profileSettings;
|
const ProfileSettings tmp = profileSettings;
|
||||||
settingsutils::switchProfile(m_profileIndex);
|
settingsutils::switchProfile(m_profileIndex);
|
||||||
@ -102,10 +106,11 @@ public:
|
|||||||
}
|
}
|
||||||
else if (m_menu.m_firstIndex != -1 && m_menu.m_firstIndex != m_profileIndex)
|
else if (m_menu.m_firstIndex != -1 && m_menu.m_firstIndex != m_profileIndex)
|
||||||
{
|
{
|
||||||
|
m_menu.lock();
|
||||||
|
m_mode = CONFIRM_SWAP;
|
||||||
BobbyErrorHandler{}.errorOccurred(
|
BobbyErrorHandler{}.errorOccurred(
|
||||||
fmt::format("Press CONFIRM to SWAP Profile {} with Profile {}", m_menu.m_firstIndex,
|
fmt::format("Press CONFIRM to SWAP Profile {} with Profile {}", m_menu.m_firstIndex,
|
||||||
m_profileIndex));
|
m_profileIndex));
|
||||||
m_mode = CONFIRM_SWAP;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,38 +252,59 @@ void ManageProfilesMenu::stop()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManageProfilesMenu::back()
|
|
||||||
{
|
|
||||||
if (!m_locked && m_firstIndex == -1)
|
|
||||||
{
|
|
||||||
espgui::popScreen();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_locked)
|
|
||||||
m_locked = false;
|
|
||||||
|
|
||||||
if (m_firstIndex != -1)
|
|
||||||
m_firstIndex = -1;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ManageProfilesMenu::text() const
|
std::string ManageProfilesMenu::text() const
|
||||||
{
|
{
|
||||||
return TEXT_MANAGEPROFILESMENU;
|
return TEXT_MANAGEPROFILESMENU;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ManageProfilesMenu::action_text() const {
|
std::string ManageProfilesMenu::action_text() const
|
||||||
|
{
|
||||||
return toString(m_action);
|
return toString(m_action);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManageProfilesMenu::lock() {
|
void ManageProfilesMenu::lock()
|
||||||
|
{
|
||||||
m_locked = true;
|
m_locked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManageProfilesMenu::unlock() {
|
void ManageProfilesMenu::unlock()
|
||||||
|
{
|
||||||
m_locked = false;
|
m_locked = false;
|
||||||
}
|
}
|
||||||
// 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.
|
void ManageProfilesMenu::buttonPressed(espgui::Button button)
|
||||||
//
|
{
|
||||||
|
using namespace espgui;
|
||||||
|
|
||||||
|
switch (button)
|
||||||
|
{
|
||||||
|
case Button::Left:
|
||||||
|
{
|
||||||
|
if (!m_locked && m_firstIndex == -1)
|
||||||
|
{
|
||||||
|
espgui::popScreen();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_locked)
|
||||||
|
{
|
||||||
|
m_locked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_firstIndex != -1)
|
||||||
|
{
|
||||||
|
m_firstIndex = -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Button::Up:
|
||||||
|
case Button::Down:
|
||||||
|
if (m_locked)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
Base::buttonPressed(button);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -26,9 +26,12 @@ public:
|
|||||||
|
|
||||||
std::string text() const override;
|
std::string text() const override;
|
||||||
std::string action_text() const;
|
std::string action_text() const;
|
||||||
void back() override;
|
|
||||||
void lock();
|
void lock();
|
||||||
void unlock();
|
void unlock();
|
||||||
|
|
||||||
|
void back() override {};
|
||||||
|
|
||||||
|
void buttonPressed(espgui::Button button) override;
|
||||||
private:
|
private:
|
||||||
ModeInterface *m_oldMode;
|
ModeInterface *m_oldMode;
|
||||||
IgnoreInputMode m_mode{0, bobbycar::protocol::ControlType::FieldOrientedControl, bobbycar::protocol::ControlMode::Torque};
|
IgnoreInputMode m_mode{0, bobbycar::protocol::ControlType::FieldOrientedControl, bobbycar::protocol::ControlMode::Torque};
|
||||||
|
Reference in New Issue
Block a user