From 8dfc84eac26476930828a8a4e33b25f8a989494e Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Wed, 13 Mar 2024 16:03:28 +0100 Subject: [PATCH] add `restart other` command to change partition #1657 --- CHANGELOG_LATEST.md | 3 ++- src/console.cpp | 14 +++++++++++--- src/locale_common.h | 1 + src/system.cpp | 34 +++++++++++++++++++++++++++++----- src/system.h | 2 +- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index dfc3819ab..cb5e05e25 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -20,8 +20,9 @@ - mixer MM100 telegram 0x2CC [#1554](https://github.com/emsesp/EMS-ESP32/issues/1554) - boiler hpSetDiffPressure [#1563](https://github.com/emsesp/EMS-ESP32/issues/1563) - custom variables [#1423](https://github.com/emsesp/EMS-ESP32/issues/1423) -- weather compensation [#1642](https://github.com/emsesp/EMS-ESP32/issues/1442) +- weather compensation [#1642](https://github.com/emsesp/EMS-ESP32/issues/1642) - env and partitions for DevKitC-1-N32R8 [#1635](https://github.com/emsesp/EMS-ESP32/discussions/1635) +- command `restart other` and button long press to start with other partition [#1657](https://github.com/emsesp/EMS-ESP32/issues/1657) ## Fixed diff --git a/src/console.cpp b/src/console.cpp index a8a88f4d3..ef4187017 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -198,9 +198,17 @@ static void setup_commands(std::shared_ptr & commands) { }); }); - commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, string_vector{F_(restart)}, [](Shell & shell, const std::vector & arguments) { - to_app(shell).system_.system_restart(); - }); + commands->add_command(ShellContext::MAIN, + CommandFlags::ADMIN, + string_vector{F_(restart)}, + string_vector{F_(other_optional)}, + [](Shell & shell, const std::vector & arguments) { + if (arguments.size()) { + to_app(shell).system_.system_restart(arguments.front() == "other"); + } else { + to_app(shell).system_.system_restart(); + } + }); commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, diff --git a/src/locale_common.h b/src/locale_common.h index 59e965ad8..f6ae44e8d 100644 --- a/src/locale_common.h +++ b/src/locale_common.h @@ -140,6 +140,7 @@ MAKE_WORD_CUSTOM(asterisks, "********") MAKE_WORD_CUSTOM(n_mandatory, "") MAKE_WORD_CUSTOM(sensorid_optional, "[sensor ID]") MAKE_WORD_CUSTOM(id_optional, "[id|hc]") +MAKE_WORD_CUSTOM(other_optional, "[other]") MAKE_WORD_CUSTOM(data_optional, "[data]") MAKE_WORD_CUSTOM(nvs_optional, "[nvs]") MAKE_WORD_CUSTOM(offset_optional, "[offset]") diff --git a/src/system.cpp b/src/system.cpp index c4c6ed2cb..e984cf67e 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -261,12 +261,31 @@ void System::store_nvs_values() { } // restart EMS-ESP -void System::system_restart() { - LOG_INFO("Restarting EMS-ESP..."); +void System::system_restart(const bool other_partition) { + if (other_partition) { + LOG_INFO("Restarting EMS-ESP to other partition..."); + } else { + LOG_INFO("Restarting EMS-ESP..."); + } + store_nvs_values(); Shell::loop_all(); delay(1000); // wait a second #ifndef EMSESP_STANDALONE + if (other_partition) { + // check for factory partiton + const esp_partition_t * partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL); + if (!partition) { + partition = esp_ota_get_next_update_partition(NULL); + } + if (partition) { + uint64_t buffer; + esp_partition_read(partition, 0, &buffer, 8); + if (buffer != 0xFFFFFFFFFFFFFFFF) { // partition not empty + esp_ota_set_boot_partition(partition); + } + } + } ESP.restart(); #endif } @@ -458,7 +477,8 @@ void System::button_OnDblClick(PButton & b) { // button long press void System::button_OnLongPress(PButton & b) { - LOG_NOTICE("Button pressed - long press"); + LOG_NOTICE("Button pressed - long press - boot to other partition"); + EMSESP::system_.system_restart(true); } // button indefinite press @@ -1511,9 +1531,13 @@ bool System::load_board_profile(std::vector & data, const std::string & return true; } -// restart command - perform a hard reset by setting flag +// restart command - perform a hard reset bool System::command_restart(const char * value, const int8_t id) { - restart_requested(true); + if (value[0] == '1' || strcmp(value, "true") == 0 || strcmp(value, "other") == 0) { + EMSESP::system_.system_restart(true); + } else { + EMSESP::system_.system_restart(false); + } return true; } diff --git a/src/system.h b/src/system.h index b7dea5c9a..965de2d05 100644 --- a/src/system.h +++ b/src/system.h @@ -69,7 +69,7 @@ class System { std::string reset_reason(uint8_t cpu) const; void store_nvs_values(); - void system_restart(); + void system_restart(const bool other_partition = false); void format(uuid::console::Shell & shell); void upload_status(bool in_progress); bool upload_status();