mirror of
https://github.com/ravinrabbid/DonCon2040.git
synced 2024-11-20 11:47:07 +01:00
Add settings reset via on-screen menu
This commit is contained in:
parent
b278f76ba0
commit
753a1cd59f
@ -25,6 +25,7 @@ class Menu {
|
||||
TriggerThresholdKaRight,
|
||||
TriggerThresholdScaleLevel,
|
||||
LedBrightness,
|
||||
Reset,
|
||||
Bootsel,
|
||||
BootselMsg,
|
||||
};
|
||||
@ -44,6 +45,7 @@ class Menu {
|
||||
|
||||
enum class Action {
|
||||
None,
|
||||
GotoParent,
|
||||
|
||||
GotoPageDeviceMode,
|
||||
GotoPageTriggerThreshold,
|
||||
@ -53,6 +55,7 @@ class Menu {
|
||||
GotoPageTriggerThresholdKaRight,
|
||||
GotoPageTriggerThresholdScaleLevel,
|
||||
GotoPageLedBrightness,
|
||||
GotoPageReset,
|
||||
GotoPageBootsel,
|
||||
|
||||
ChangeUsbModeSwitchTatacon,
|
||||
@ -71,6 +74,7 @@ class Menu {
|
||||
SetLedBrightness,
|
||||
|
||||
DoRebootToBootsel,
|
||||
DoReset,
|
||||
};
|
||||
|
||||
Type type;
|
||||
|
@ -60,6 +60,7 @@ class SettingsStore {
|
||||
void scheduleReboot(const bool bootsel = false);
|
||||
|
||||
void store();
|
||||
void reset();
|
||||
};
|
||||
} // namespace Doncon::Utils
|
||||
|
||||
|
@ -9,6 +9,7 @@ const std::map<Menu::Page, const Menu::Descriptor> Menu::descriptors = {
|
||||
{{"Mode", Menu::Descriptor::Action::GotoPageDeviceMode}, //
|
||||
{"Brightness", Menu::Descriptor::Action::GotoPageLedBrightness}, //
|
||||
{"Sensitvty", Menu::Descriptor::Action::GotoPageTriggerThreshold}, //
|
||||
{"Reset", Menu::Descriptor::Action::GotoPageReset}, //
|
||||
{"BOOTSEL", Menu::Descriptor::Action::GotoPageBootsel}}, //
|
||||
0, //
|
||||
Menu::Page::None}}, //
|
||||
@ -79,6 +80,14 @@ const std::map<Menu::Page, const Menu::Descriptor> Menu::descriptors = {
|
||||
UINT8_MAX, //
|
||||
Menu::Page::Main}}, //
|
||||
|
||||
{Menu::Page::Reset, //
|
||||
{Menu::Descriptor::Type::Selection, //
|
||||
"Reset all Settings?", //
|
||||
{{"No", Menu::Descriptor::Action::GotoParent}, //
|
||||
{"Yes", Menu::Descriptor::Action::DoReset}}, //
|
||||
0, //
|
||||
Menu::Page::Main}}, //
|
||||
|
||||
{Menu::Page::Bootsel, //
|
||||
{Menu::Descriptor::Type::Selection, //
|
||||
"Reboot to BOOTSEL", //
|
||||
@ -204,6 +213,7 @@ uint16_t Menu::getCurrentSelection(Menu::Page page) {
|
||||
break;
|
||||
case Page::Main:
|
||||
case Page::TriggerThreshold:
|
||||
case Page::Reset:
|
||||
case Page::Bootsel:
|
||||
case Page::BootselMsg:
|
||||
case Page::None:
|
||||
@ -250,6 +260,9 @@ void Menu::performSelectionAction(Menu::Descriptor::Action action) {
|
||||
case Descriptor::Action::GotoPageLedBrightness:
|
||||
gotoPage(Page::LedBrightness);
|
||||
break;
|
||||
case Descriptor::Action::GotoPageReset:
|
||||
gotoPage(Page::Reset);
|
||||
break;
|
||||
case Descriptor::Action::GotoPageBootsel:
|
||||
gotoPage(Page::Bootsel);
|
||||
break;
|
||||
@ -291,10 +304,16 @@ void Menu::performSelectionAction(Menu::Descriptor::Action action) {
|
||||
case Descriptor::Action::SetLedBrightness:
|
||||
gotoPage(descriptor_it->second.parent);
|
||||
break;
|
||||
case Descriptor::Action::DoReset:
|
||||
m_store->reset();
|
||||
break;
|
||||
case Descriptor::Action::DoRebootToBootsel:
|
||||
m_store->scheduleReboot(true);
|
||||
gotoPage(Page::BootselMsg);
|
||||
break;
|
||||
case Descriptor::Action::GotoParent:
|
||||
gotoPage(descriptor_it->second.parent);
|
||||
break;
|
||||
case Descriptor::Action::None:
|
||||
break;
|
||||
}
|
||||
|
@ -118,6 +118,21 @@ void SettingsStore::store() {
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsStore::reset() {
|
||||
multicore_lockout_start_blocking();
|
||||
uint32_t interrupts = save_and_disable_interrupts();
|
||||
|
||||
flash_range_erase(m_flash_offset, m_flash_size);
|
||||
|
||||
restore_interrupts(interrupts);
|
||||
multicore_lockout_end_blocking();
|
||||
|
||||
m_dirty = false;
|
||||
|
||||
scheduleReboot();
|
||||
store();
|
||||
}
|
||||
|
||||
void SettingsStore::scheduleReboot(const bool bootsel) {
|
||||
if (m_scheduled_reboot != RebootType::Bootsel) {
|
||||
m_scheduled_reboot = (bootsel ? RebootType::Bootsel : RebootType::Normal);
|
||||
|
Loading…
Reference in New Issue
Block a user