Finished menu to clear, swap and copy profiles
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "mainmenu.h"
|
#include "mainmenu.h"
|
||||||
#include "presets.h"
|
#include "presets.h"
|
||||||
|
#include "settingsutils.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
constexpr const char * const TAG = "ProfileManager";
|
constexpr const char * const TAG = "ProfileManager";
|
||||||
@@ -28,27 +29,101 @@ public:
|
|||||||
ManageProfileMenuItem(ManageProfilesMenu &menu, const uint8_t profileIndex) : m_menu{menu}, m_profileIndex{profileIndex} {}
|
ManageProfileMenuItem(ManageProfilesMenu &menu, const uint8_t profileIndex) : m_menu{menu}, m_profileIndex{profileIndex} {}
|
||||||
void copy()
|
void copy()
|
||||||
{
|
{
|
||||||
|
if (m_mode == CONFIRM_COPY)
|
||||||
|
{
|
||||||
|
const auto currProfile = settingsPersister.currentlyOpenProfileIndex();
|
||||||
|
if (!currProfile)
|
||||||
|
return;
|
||||||
|
|
||||||
|
settingsutils::switchProfile(m_menu.m_firstIndex);
|
||||||
|
|
||||||
|
if (!settingsPersister.openProfile(m_profileIndex)) // just switch nvs namespace
|
||||||
|
{
|
||||||
|
BobbyErrorHandler{}.errorOccured(fmt::format("openProfile({}) failed", m_profileIndex));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
saveProfileSettings();
|
||||||
|
settingsutils::switchProfile(*currProfile);
|
||||||
|
m_mode = _DEFAULT;
|
||||||
|
m_menu.m_firstIndex = -1;
|
||||||
|
}
|
||||||
|
else if (m_menu.m_firstIndex == m_profileIndex && m_mode == SELECT_OTHER)
|
||||||
|
{
|
||||||
|
m_mode = _DEFAULT;
|
||||||
|
m_menu.m_firstIndex = -1;
|
||||||
|
}
|
||||||
|
else if (m_menu.m_firstIndex == -1 && m_mode == _DEFAULT)
|
||||||
|
{
|
||||||
|
m_mode = SELECT_OTHER;
|
||||||
|
m_menu.m_firstIndex = m_profileIndex;
|
||||||
|
}
|
||||||
|
else if (m_menu.m_firstIndex != -1 && m_menu.m_firstIndex != m_profileIndex)
|
||||||
|
{
|
||||||
|
BobbyErrorHandler{}.errorOccured(fmt::format("Press CONFIRM to COPY from Profile {} to Profile {}", m_menu.m_firstIndex, m_profileIndex));
|
||||||
|
m_mode = CONFIRM_COPY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap()
|
void swap()
|
||||||
{
|
{
|
||||||
|
if (m_mode == CONFIRM_SWAP)
|
||||||
|
{
|
||||||
|
const auto currProfile = settingsPersister.currentlyOpenProfileIndex();
|
||||||
|
if (!currProfile)
|
||||||
|
return;
|
||||||
|
|
||||||
|
settingsutils::switchProfile(m_menu.m_firstIndex);
|
||||||
|
const ProfileSettings tmp = profileSettings;
|
||||||
|
settingsutils::switchProfile(m_profileIndex);
|
||||||
|
const ProfileSettings tmp2 = profileSettings;
|
||||||
|
|
||||||
|
profileSettings = tmp;
|
||||||
|
saveProfileSettings();
|
||||||
|
settingsutils::switchProfile(m_menu.m_firstIndex);
|
||||||
|
profileSettings = tmp2;
|
||||||
|
saveProfileSettings();
|
||||||
|
|
||||||
|
m_mode = _DEFAULT;
|
||||||
|
m_menu.m_firstIndex = -1;
|
||||||
|
settingsutils::switchProfile(*currProfile);
|
||||||
|
}
|
||||||
|
else if (m_menu.m_firstIndex == m_profileIndex && m_mode == SELECT_OTHER)
|
||||||
|
{
|
||||||
|
m_mode = _DEFAULT;
|
||||||
|
m_menu.m_firstIndex = -1;
|
||||||
|
}
|
||||||
|
else if (m_menu.m_firstIndex == -1 && m_mode == _DEFAULT)
|
||||||
|
{
|
||||||
|
m_mode = SELECT_OTHER;
|
||||||
|
m_menu.m_firstIndex = m_profileIndex;
|
||||||
|
}
|
||||||
|
else if (m_menu.m_firstIndex != -1 && m_menu.m_firstIndex != m_profileIndex)
|
||||||
|
{
|
||||||
|
BobbyErrorHandler{}.errorOccured(fmt::format("Press CONFIRM to SWAP Profile {} with Profile {}", m_menu.m_firstIndex, m_profileIndex));
|
||||||
|
m_mode = CONFIRM_SWAP;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
if (m_mode == CONFIRMCLEAR)
|
if (m_mode == CONFIRM_CLEAR)
|
||||||
{
|
{
|
||||||
|
const auto currProfile = settingsPersister.currentlyOpenProfileIndex();
|
||||||
|
if (!currProfile)
|
||||||
|
return;
|
||||||
|
|
||||||
m_menu.unlock();
|
m_menu.unlock();
|
||||||
ESP_LOGI(TAG, "Reseting profile %i...", m_profileIndex);
|
ESP_LOGI(TAG, "Reseting profile %i...", m_profileIndex);
|
||||||
|
settingsutils::switchProfile(m_profileIndex);
|
||||||
profileSettings = presets::defaultProfileSettings;
|
profileSettings = presets::defaultProfileSettings;
|
||||||
|
saveProfileSettings();
|
||||||
m_mode = _DEFAULT;
|
m_mode = _DEFAULT;
|
||||||
|
settingsutils::switchProfile(*currProfile);
|
||||||
}
|
}
|
||||||
else
|
else if(m_mode == _DEFAULT)
|
||||||
{
|
{
|
||||||
m_menu.lock();
|
m_menu.lock();
|
||||||
m_mode = CONFIRMCLEAR;
|
m_mode = CONFIRM_CLEAR;
|
||||||
BobbyErrorHandler{}.errorOccured("Press CONFIRM to reset Profile or BACK to cancel.");
|
BobbyErrorHandler{}.errorOccured("Press CONFIRM to reset Profile or BACK to cancel.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,16 +134,22 @@ public:
|
|||||||
{
|
{
|
||||||
case _DEFAULT:
|
case _DEFAULT:
|
||||||
return fmt::format("Profile {}", m_profileIndex);
|
return fmt::format("Profile {}", m_profileIndex);
|
||||||
case CONFIRMCLEAR:
|
case CONFIRM_CLEAR:
|
||||||
return fmt::format("&1Profile {}", m_profileIndex);
|
return fmt::format("&1Profile {}", m_profileIndex);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return fmt::format("Profile {}", m_profileIndex);
|
return fmt::format("Profile {}", m_profileIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int color() const override
|
int color() const override
|
||||||
{
|
{
|
||||||
if (m_mode == CONFIRMCLEAR)
|
if (m_mode == CONFIRM_CLEAR || m_mode == CONFIRM_COPY || m_mode == CONFIRM_SWAP)
|
||||||
return TFT_RED;
|
return TFT_RED;
|
||||||
|
else if (m_menu.m_firstIndex == m_profileIndex)
|
||||||
|
return TFT_GREEN;
|
||||||
|
else if (m_menu.m_firstIndex != -1)
|
||||||
|
return TFT_GREY;
|
||||||
else if (m_menu.m_locked)
|
else if (m_menu.m_locked)
|
||||||
return TFT_DARKGREY;
|
return TFT_DARKGREY;
|
||||||
return TFT_WHITE;
|
return TFT_WHITE;
|
||||||
@@ -95,13 +176,16 @@ public:
|
|||||||
void update() override
|
void update() override
|
||||||
{
|
{
|
||||||
Base::update();
|
Base::update();
|
||||||
if (m_mode != _DEFAULT && !m_menu.m_locked)
|
if (m_mode != _DEFAULT && !m_menu.m_locked && m_menu.m_firstIndex == -1)
|
||||||
m_mode = _DEFAULT;
|
m_mode = _DEFAULT;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
enum Mode : uint8_t {
|
enum Mode : uint8_t {
|
||||||
_DEFAULT,
|
_DEFAULT,
|
||||||
CONFIRMCLEAR
|
CONFIRM_CLEAR,
|
||||||
|
SELECT_OTHER,
|
||||||
|
CONFIRM_COPY,
|
||||||
|
CONFIRM_SWAP
|
||||||
} m_mode;
|
} m_mode;
|
||||||
ManageProfilesMenu &m_menu;
|
ManageProfilesMenu &m_menu;
|
||||||
const uint8_t m_profileIndex;
|
const uint8_t m_profileIndex;
|
||||||
@@ -122,6 +206,8 @@ public:
|
|||||||
{
|
{
|
||||||
m_menu.m_action = Actions(0);
|
m_menu.m_action = Actions(0);
|
||||||
}
|
}
|
||||||
|
m_menu.m_firstIndex = -1;
|
||||||
|
m_menu.unlock();
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
ManageProfilesMenu &m_menu;
|
ManageProfilesMenu &m_menu;
|
||||||
@@ -158,10 +244,18 @@ void ManageProfilesMenu::stop()
|
|||||||
|
|
||||||
void ManageProfilesMenu::back()
|
void ManageProfilesMenu::back()
|
||||||
{
|
{
|
||||||
if (!m_locked)
|
if (!m_locked && m_firstIndex == -1)
|
||||||
|
{
|
||||||
switchScreen<MainMenu>();
|
switchScreen<MainMenu>();
|
||||||
else
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_locked)
|
||||||
m_locked = false;
|
m_locked = false;
|
||||||
|
|
||||||
|
if (m_firstIndex != -1)
|
||||||
|
m_firstIndex = -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ManageProfilesMenu::text() const
|
std::string ManageProfilesMenu::text() const
|
||||||
|
@@ -35,4 +35,5 @@ private:
|
|||||||
protected:
|
protected:
|
||||||
bool m_locked{false};
|
bool m_locked{false};
|
||||||
Actions m_action{Actions::Clear};
|
Actions m_action{Actions::Clear};
|
||||||
|
int8_t m_firstIndex{-1};
|
||||||
};
|
};
|
||||||
|
@@ -174,7 +174,7 @@ esp_err_t webserver_status_handler(httpd_req_t *req)
|
|||||||
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg);
|
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud");
|
||||||
std::string wants_json_query;
|
std::string wants_json_query;
|
||||||
if (auto result = esphttpdutils::webserver_get_query(req))
|
if (auto result = esphttpdutils::webserver_get_query(req))
|
||||||
wants_json_query = *result;
|
wants_json_query = *result;
|
||||||
|
@@ -281,6 +281,8 @@ esp_err_t webserver_root_handler(httpd_req_t *req)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud");
|
||||||
|
|
||||||
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Ok, (key_result == ESP_OK) ? "application/json":"text/html", body)
|
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Ok, (key_result == ESP_OK) ? "application/json":"text/html", body)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,6 +356,7 @@ esp_err_t webserver_triggerRawButton_handler(httpd_req_t *req)
|
|||||||
espgui::currentDisplay->rawButtonReleased(button);
|
espgui::currentDisplay->rawButtonReleased(button);
|
||||||
|
|
||||||
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Location", "/")
|
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Location", "/")
|
||||||
|
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud");
|
||||||
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::TemporaryRedirect, "text/html", "Ok, continue at <a href=\"/\">/</a>")
|
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::TemporaryRedirect, "text/html", "Ok, continue at <a href=\"/\">/</a>")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,6 +430,7 @@ esp_err_t webserver_triggerButton_handler(httpd_req_t *req)
|
|||||||
espgui::currentDisplay->buttonReleased(button);
|
espgui::currentDisplay->buttonReleased(button);
|
||||||
|
|
||||||
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Location", "/")
|
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Location", "/")
|
||||||
|
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud");
|
||||||
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::TemporaryRedirect, "text/html", "Ok, continue at <a href=\"/\">/</a>")
|
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::TemporaryRedirect, "text/html", "Ok, continue at <a href=\"/\">/</a>")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,6 +445,7 @@ esp_err_t webserver_triggerItem_handler(httpd_req_t *req)
|
|||||||
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg);
|
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud");
|
||||||
|
|
||||||
std::string query;
|
std::string query;
|
||||||
if (auto result = esphttpdutils::webserver_get_query(req))
|
if (auto result = esphttpdutils::webserver_get_query(req))
|
||||||
@@ -530,6 +535,8 @@ esp_err_t webserver_setValue_handler(httpd_req_t *req)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud");
|
||||||
|
|
||||||
std::string query;
|
std::string query;
|
||||||
if (auto result = esphttpdutils::webserver_get_query(req))
|
if (auto result = esphttpdutils::webserver_get_query(req))
|
||||||
query = *result;
|
query = *result;
|
||||||
|
@@ -43,7 +43,7 @@ esp_err_t webserver_ota_percentage_handler(httpd_req_t *req)
|
|||||||
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg);
|
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud");
|
||||||
std::string body;
|
std::string body;
|
||||||
|
|
||||||
std::string wants_json_query;
|
std::string wants_json_query;
|
||||||
@@ -102,7 +102,7 @@ esp_err_t webserver_ota_handler(httpd_req_t *req)
|
|||||||
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg);
|
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud");
|
||||||
std::string body;
|
std::string body;
|
||||||
|
|
||||||
std::string wants_json_query;
|
std::string wants_json_query;
|
||||||
@@ -370,7 +370,7 @@ esp_err_t webserver_trigger_ota_handler(httpd_req_t *req)
|
|||||||
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg);
|
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud");
|
||||||
std::string query;
|
std::string query;
|
||||||
if (auto result = esphttpdutils::webserver_get_query(req))
|
if (auto result = esphttpdutils::webserver_get_query(req))
|
||||||
query = *result;
|
query = *result;
|
||||||
|
Reference in New Issue
Block a user