mirror of
https://github.com/vicliu624/trail-mate.git
synced 2026-08-28 05:24:08 +00:00
feat(config): complete SD working configuration
This commit is contained in:
@@ -25,7 +25,6 @@ struct VisibilityContext
|
||||
bool wifi_supported = false;
|
||||
bool has_wifi_networks = false;
|
||||
bool firmware_update_supported = false;
|
||||
bool settings_backup_supported = false;
|
||||
bool wireless_companion_supported = false;
|
||||
bool mt_secondary_enabled = false;
|
||||
bool mt_use_preset = false;
|
||||
|
||||
@@ -158,9 +158,6 @@ enum class SettingId : std::uint16_t
|
||||
FwStatus,
|
||||
FwCheck,
|
||||
FwInstall,
|
||||
SettingsBackupStatus,
|
||||
SettingsBackup,
|
||||
SettingsRestore,
|
||||
AdvDebug,
|
||||
ChatResetMesh,
|
||||
ChatResetNodes,
|
||||
@@ -339,7 +336,6 @@ struct SettingsData
|
||||
char fw_current_version[24] = "";
|
||||
char fw_latest_version[24] = "";
|
||||
char fw_update_status[96] = "";
|
||||
char settings_backup_status[96] = "";
|
||||
bool advanced_debug_logs = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include "platform/ui/gps_runtime.h"
|
||||
#include "platform/ui/screen_brightness_steps.h"
|
||||
#include "platform/ui/screen_runtime.h"
|
||||
#include "platform/ui/settings_backup_runtime.h"
|
||||
#include "platform/ui/settings_store.h"
|
||||
#include "platform/ui/spi_diagnostics_runtime.h"
|
||||
#include "platform/ui/team_ui_store_runtime.h"
|
||||
@@ -36,6 +35,9 @@
|
||||
#include "platform/ui/tracker_runtime.h"
|
||||
#include "platform/ui/wifi_runtime.h"
|
||||
#include "platform/ui/wireless_companion_runtime.h"
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include "platform/esp/arduino_common/app_config_sd_tms_runtime.h"
|
||||
#endif
|
||||
#include "ui/app_runtime.h"
|
||||
#include "ui/assets/fonts/font_utils.h"
|
||||
#include "ui/components/info_card.h"
|
||||
@@ -81,7 +83,6 @@ namespace device_runtime = ::platform::ui::device;
|
||||
namespace firmware_update_runtime = ::platform::ui::firmware_update;
|
||||
namespace gps_runtime = ::platform::ui::gps;
|
||||
namespace screen_runtime = ::platform::ui::screen;
|
||||
namespace settings_backup_runtime = ::platform::ui::settings_backup;
|
||||
namespace settings_store = ::platform::ui::settings_store;
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
namespace spi_diagnostics_runtime = ::platform::ui::spi_diagnostics;
|
||||
@@ -356,7 +357,6 @@ static void append_custom_timezone_option_if_needed(int profile_id, int offset_m
|
||||
static void update_item_value(settings::ui::ItemWidget& widget);
|
||||
static settings::ui::SettingId item_id(const settings::ui::SettingItem& item);
|
||||
static void open_factory_reset_modal();
|
||||
static void open_settings_restore_modal();
|
||||
static void open_gps_diagnostics_modal();
|
||||
static void open_spi_diagnostics_modal();
|
||||
static void open_enabled_imes_modal(settings::ui::ItemWidget& widget);
|
||||
@@ -559,17 +559,6 @@ static void refresh_firmware_update_state_from_runtime()
|
||||
firmware_status_summary(status, g_settings.fw_update_status, sizeof(g_settings.fw_update_status));
|
||||
}
|
||||
|
||||
static void refresh_settings_backup_state_from_runtime()
|
||||
{
|
||||
const settings_backup_runtime::Status status = settings_backup_runtime::status();
|
||||
const char* message = status.message[0] != '\0'
|
||||
? status.message
|
||||
: (status.supported ? "No backup found" : "Backup unsupported");
|
||||
copy_bounded(g_settings.settings_backup_status,
|
||||
sizeof(g_settings.settings_backup_status),
|
||||
::ui::i18n::tr(message));
|
||||
}
|
||||
|
||||
static void refresh_wireless_companion_state_from_runtime()
|
||||
{
|
||||
const wireless_companion_runtime::Status status = wireless_companion_runtime::status();
|
||||
@@ -1480,14 +1469,24 @@ static void clear_message_db()
|
||||
::ui::feedback::show_notice(::ui::i18n::tr("Message DB cleared"), 3000);
|
||||
}
|
||||
|
||||
static void perform_factory_reset()
|
||||
static bool perform_factory_reset()
|
||||
{
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
app::sd_tms::beginWorkingConfigReset();
|
||||
if (!app::sd_tms::resetWorkingConfig())
|
||||
{
|
||||
app::sd_tms::endWorkingConfigReset();
|
||||
::ui::feedback::show_notice(::ui::i18n::tr("Unable to reset SD configuration"), 3500);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
static const char* kNamespacesToClear[] = {
|
||||
"chat",
|
||||
"gps",
|
||||
"settings",
|
||||
"aprs",
|
||||
"power",
|
||||
"a7682e",
|
||||
"chat_pki",
|
||||
"mc_peers",
|
||||
"lxmf_peers",
|
||||
@@ -1500,9 +1499,14 @@ static void perform_factory_reset()
|
||||
|
||||
team::ui::team_ui_snapshot_store().clear();
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
app::sd_tms::endWorkingConfigReset();
|
||||
#endif
|
||||
|
||||
::ui::feedback::show_notice(::ui::i18n::tr("Resetting..."), 1500);
|
||||
platform_delay_ms(300);
|
||||
platform_restart();
|
||||
return true;
|
||||
}
|
||||
|
||||
static void settings_load()
|
||||
@@ -1818,7 +1822,6 @@ static void settings_load()
|
||||
g_settings.vibration_enabled = prefs_get_bool("vibration_enabled", true);
|
||||
refresh_wifi_state_from_runtime();
|
||||
refresh_firmware_update_state_from_runtime();
|
||||
refresh_settings_backup_state_from_runtime();
|
||||
refresh_wireless_companion_state_from_runtime();
|
||||
|
||||
g_settings.advanced_debug_logs = prefs_get_bool("adv_debug", false);
|
||||
@@ -4177,7 +4180,7 @@ static void on_factory_reset_confirm_clicked(lv_event_t* e)
|
||||
ScopedSettingsBusyOverlay busy(::ui::i18n::tr("Resetting..."),
|
||||
::ui::i18n::tr("Clearing stored settings"),
|
||||
15);
|
||||
perform_factory_reset();
|
||||
(void)perform_factory_reset();
|
||||
}
|
||||
|
||||
static void on_factory_reset_cancel_clicked(lv_event_t* e)
|
||||
@@ -4186,93 +4189,6 @@ static void on_factory_reset_cancel_clicked(lv_event_t* e)
|
||||
modal_close();
|
||||
}
|
||||
|
||||
static void on_settings_restore_confirm_clicked(lv_event_t* e)
|
||||
{
|
||||
(void)e;
|
||||
modal_close();
|
||||
ScopedSettingsBusyOverlay busy(::ui::i18n::tr("Restoring settings..."),
|
||||
::ui::i18n::tr("Reading backup from SD"),
|
||||
20);
|
||||
if (!settings_backup_runtime::restore())
|
||||
{
|
||||
refresh_settings_backup_state_from_runtime();
|
||||
::ui::feedback::show_notice(::ui::i18n::tr("Restore failed"), 3500);
|
||||
refresh_visible_item_values();
|
||||
return;
|
||||
}
|
||||
busy.update(::ui::i18n::tr("Restarting..."),
|
||||
::ui::i18n::tr("Settings restored"),
|
||||
90);
|
||||
::ui::feedback::show_notice(::ui::i18n::tr("Settings restored. Restarting..."), 1500);
|
||||
platform_delay_ms(300);
|
||||
platform_restart();
|
||||
}
|
||||
|
||||
static void on_settings_restore_cancel_clicked(lv_event_t* e)
|
||||
{
|
||||
(void)e;
|
||||
modal_close();
|
||||
}
|
||||
|
||||
static void open_settings_restore_modal()
|
||||
{
|
||||
if (g_state.modal_root)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
modal_prepare_group();
|
||||
g_state.modal_root = create_modal_root(300, 180);
|
||||
lv_obj_t* win = lv_obj_get_child(g_state.modal_root, 0);
|
||||
|
||||
lv_obj_t* title = lv_label_create(win);
|
||||
::ui::i18n::set_label_text(title, "Restore Settings");
|
||||
style::apply_label_primary(title);
|
||||
lv_obj_align(title, LV_ALIGN_TOP_MID, 0, 0);
|
||||
|
||||
lv_obj_t* body = lv_label_create(win);
|
||||
lv_obj_set_width(body, LV_PCT(100));
|
||||
::ui::i18n::set_label_text(body, "Overwrite current settings and restart?");
|
||||
style::apply_label_muted(body);
|
||||
lv_obj_set_style_text_align(body, LV_TEXT_ALIGN_CENTER, 0);
|
||||
lv_obj_align(body, LV_ALIGN_CENTER, 0, -8);
|
||||
|
||||
lv_obj_t* btn_row = lv_obj_create(win);
|
||||
lv_obj_set_size(btn_row, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_align(btn_row, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||
lv_obj_set_flex_flow(btn_row, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_flex_align(btn_row,
|
||||
LV_FLEX_ALIGN_SPACE_EVENLY,
|
||||
LV_FLEX_ALIGN_CENTER,
|
||||
LV_FLEX_ALIGN_CENTER);
|
||||
lv_obj_set_style_pad_all(btn_row, 0, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_opa(btn_row, LV_OPA_TRANSP, LV_PART_MAIN);
|
||||
lv_obj_set_style_border_width(btn_row, 0, LV_PART_MAIN);
|
||||
lv_obj_clear_flag(btn_row, LV_OBJ_FLAG_SCROLLABLE);
|
||||
|
||||
lv_obj_t* cancel_btn = lv_btn_create(btn_row);
|
||||
lv_obj_set_size(cancel_btn,
|
||||
::ui::page_profile::resolve_control_button_min_width(),
|
||||
::ui::page_profile::resolve_control_button_height());
|
||||
lv_obj_t* cancel_label = lv_label_create(cancel_btn);
|
||||
::ui::i18n::set_label_text(cancel_label, "Cancel");
|
||||
lv_obj_center(cancel_label);
|
||||
lv_obj_add_event_cb(cancel_btn, on_settings_restore_cancel_clicked, LV_EVENT_CLICKED, nullptr);
|
||||
|
||||
lv_obj_t* confirm_btn = lv_btn_create(btn_row);
|
||||
lv_obj_set_size(confirm_btn,
|
||||
::ui::page_profile::resolve_control_button_min_width(),
|
||||
::ui::page_profile::resolve_control_button_height());
|
||||
lv_obj_t* confirm_label = lv_label_create(confirm_btn);
|
||||
::ui::i18n::set_label_text(confirm_label, "Restore");
|
||||
lv_obj_center(confirm_label);
|
||||
lv_obj_add_event_cb(confirm_btn, on_settings_restore_confirm_clicked, LV_EVENT_CLICKED, nullptr);
|
||||
|
||||
modal_add_focus_obj(cancel_btn);
|
||||
modal_add_focus_obj(confirm_btn);
|
||||
lv_group_focus_obj(cancel_btn);
|
||||
}
|
||||
|
||||
static void open_factory_reset_modal()
|
||||
{
|
||||
if (g_state.modal_root)
|
||||
@@ -5383,9 +5299,6 @@ static settings::ui::SettingItem kMaintenanceItems[] = {
|
||||
{"OTA Status", settings::ui::SettingType::Info, nullptr, 0, nullptr, nullptr, g_settings.fw_update_status, sizeof(g_settings.fw_update_status), false, "fw_status"},
|
||||
{"Check for Updates", settings::ui::SettingType::Action, nullptr, 0, nullptr, nullptr, nullptr, 0, false, "fw_check"},
|
||||
{"Install Update", settings::ui::SettingType::Action, nullptr, 0, nullptr, nullptr, nullptr, 0, false, "fw_install"},
|
||||
{"Backup Status", settings::ui::SettingType::Info, nullptr, 0, nullptr, nullptr, g_settings.settings_backup_status, sizeof(g_settings.settings_backup_status), false, "settings_backup_status"},
|
||||
{"Backup Settings", settings::ui::SettingType::Action, nullptr, 0, nullptr, nullptr, nullptr, 0, false, "settings_backup"},
|
||||
{"Restore Settings", settings::ui::SettingType::Action, nullptr, 0, nullptr, nullptr, nullptr, 0, false, "settings_restore"},
|
||||
{"Debug Logs", settings::ui::SettingType::Toggle, nullptr, 0, nullptr, &g_settings.advanced_debug_logs, nullptr, 0, false, "adv_debug"},
|
||||
{"Reset Mesh Profiles", settings::ui::SettingType::Action, nullptr, 0, nullptr, nullptr, nullptr, 0, false, "chat_reset_mesh"},
|
||||
{"Reset Node DB", settings::ui::SettingType::Action, nullptr, 0, nullptr, nullptr, nullptr, 0, false, "chat_reset_nodes"},
|
||||
@@ -5528,7 +5441,6 @@ static bool should_show_item(const settings::ui::SettingItem& item)
|
||||
context.wifi_supported = wifi_runtime::is_supported();
|
||||
context.has_wifi_networks = kWifiNetworkOptionCount > 0;
|
||||
context.firmware_update_supported = firmware_update_runtime::is_supported();
|
||||
context.settings_backup_supported = settings_backup_runtime::is_supported();
|
||||
context.wireless_companion_supported = wireless_companion_runtime::is_supported();
|
||||
context.mt_secondary_enabled = g_settings.mt_secondary_enabled;
|
||||
context.mt_use_preset = g_settings.net_use_preset != 0;
|
||||
@@ -6476,57 +6388,6 @@ static bool activate_item_widget(settings::ui::ItemWidget& widget)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case settings::ui::SettingId::SettingsBackup:
|
||||
{
|
||||
const settings_backup_runtime::Status before = settings_backup_runtime::status();
|
||||
if (!before.sd_present)
|
||||
{
|
||||
::ui::feedback::show_notice(::ui::i18n::tr("Insert SD card to backup settings"), 3000);
|
||||
}
|
||||
else
|
||||
{
|
||||
ScopedSettingsBusyOverlay busy(::ui::i18n::tr("Backing up settings..."),
|
||||
::ui::i18n::tr("Writing to SD card"),
|
||||
30);
|
||||
if (!settings_backup_runtime::backup())
|
||||
{
|
||||
busy.update(::ui::i18n::tr("Backup failed"),
|
||||
::ui::i18n::tr("Check SD card"),
|
||||
100);
|
||||
refresh_settings_backup_state_from_runtime();
|
||||
::ui::feedback::show_notice(::ui::i18n::tr("Backup failed"), 3000);
|
||||
}
|
||||
else
|
||||
{
|
||||
busy.update(::ui::i18n::tr("Backup complete"),
|
||||
::ui::i18n::tr("Settings saved to SD"),
|
||||
100);
|
||||
refresh_settings_backup_state_from_runtime();
|
||||
::ui::feedback::show_notice(::ui::i18n::tr("Settings backup saved to SD"), 2500);
|
||||
}
|
||||
}
|
||||
refresh_visible_item_values();
|
||||
break;
|
||||
}
|
||||
case settings::ui::SettingId::SettingsRestore:
|
||||
{
|
||||
const settings_backup_runtime::Status status = settings_backup_runtime::status();
|
||||
if (!status.sd_present)
|
||||
{
|
||||
::ui::feedback::show_notice(::ui::i18n::tr("Insert SD card to restore settings"), 3000);
|
||||
}
|
||||
else if (!status.has_backup)
|
||||
{
|
||||
::ui::feedback::show_notice(::ui::i18n::tr("No settings backup found"), 3000);
|
||||
}
|
||||
else
|
||||
{
|
||||
open_settings_restore_modal();
|
||||
}
|
||||
refresh_settings_backup_state_from_runtime();
|
||||
refresh_visible_item_values();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -149,9 +149,6 @@ constexpr SettingSpec kSpecs[] = {
|
||||
{SettingId::FwStatus, "fw_status", DynamicOptionKind::None},
|
||||
{SettingId::FwCheck, "fw_check", DynamicOptionKind::None},
|
||||
{SettingId::FwInstall, "fw_install", DynamicOptionKind::None},
|
||||
{SettingId::SettingsBackupStatus, "settings_backup_status", DynamicOptionKind::None},
|
||||
{SettingId::SettingsBackup, "settings_backup", DynamicOptionKind::None},
|
||||
{SettingId::SettingsRestore, "settings_restore", DynamicOptionKind::None},
|
||||
{SettingId::AdvDebug, "adv_debug", DynamicOptionKind::None},
|
||||
{SettingId::ChatResetMesh, "chat_reset_mesh", DynamicOptionKind::None},
|
||||
{SettingId::ChatResetNodes, "chat_reset_nodes", DynamicOptionKind::None},
|
||||
@@ -391,19 +388,6 @@ bool is_firmware_update_setting(SettingId id)
|
||||
}
|
||||
}
|
||||
|
||||
bool is_settings_backup_setting(SettingId id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case SettingId::SettingsBackupStatus:
|
||||
case SettingId::SettingsBackup:
|
||||
case SettingId::SettingsRestore:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool is_wireless_companion_setting(SettingId id)
|
||||
{
|
||||
switch (id)
|
||||
@@ -552,10 +536,6 @@ bool should_show(SettingId id, const VisibilityContext& context)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (is_settings_backup_setting(id) && !context.settings_backup_supported)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (is_wireless_companion_setting(id) && !context.wireless_companion_supported)
|
||||
{
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user