mirror of
https://github.com/ravinrabbid/DonCon2040.git
synced 2024-11-20 03:37: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,
|
TriggerThresholdKaRight,
|
||||||
TriggerThresholdScaleLevel,
|
TriggerThresholdScaleLevel,
|
||||||
LedBrightness,
|
LedBrightness,
|
||||||
|
Reset,
|
||||||
Bootsel,
|
Bootsel,
|
||||||
BootselMsg,
|
BootselMsg,
|
||||||
};
|
};
|
||||||
@ -44,6 +45,7 @@ class Menu {
|
|||||||
|
|
||||||
enum class Action {
|
enum class Action {
|
||||||
None,
|
None,
|
||||||
|
GotoParent,
|
||||||
|
|
||||||
GotoPageDeviceMode,
|
GotoPageDeviceMode,
|
||||||
GotoPageTriggerThreshold,
|
GotoPageTriggerThreshold,
|
||||||
@ -53,6 +55,7 @@ class Menu {
|
|||||||
GotoPageTriggerThresholdKaRight,
|
GotoPageTriggerThresholdKaRight,
|
||||||
GotoPageTriggerThresholdScaleLevel,
|
GotoPageTriggerThresholdScaleLevel,
|
||||||
GotoPageLedBrightness,
|
GotoPageLedBrightness,
|
||||||
|
GotoPageReset,
|
||||||
GotoPageBootsel,
|
GotoPageBootsel,
|
||||||
|
|
||||||
ChangeUsbModeSwitchTatacon,
|
ChangeUsbModeSwitchTatacon,
|
||||||
@ -71,6 +74,7 @@ class Menu {
|
|||||||
SetLedBrightness,
|
SetLedBrightness,
|
||||||
|
|
||||||
DoRebootToBootsel,
|
DoRebootToBootsel,
|
||||||
|
DoReset,
|
||||||
};
|
};
|
||||||
|
|
||||||
Type type;
|
Type type;
|
||||||
|
@ -60,6 +60,7 @@ class SettingsStore {
|
|||||||
void scheduleReboot(const bool bootsel = false);
|
void scheduleReboot(const bool bootsel = false);
|
||||||
|
|
||||||
void store();
|
void store();
|
||||||
|
void reset();
|
||||||
};
|
};
|
||||||
} // namespace Doncon::Utils
|
} // namespace Doncon::Utils
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ const std::map<Menu::Page, const Menu::Descriptor> Menu::descriptors = {
|
|||||||
{{"Mode", Menu::Descriptor::Action::GotoPageDeviceMode}, //
|
{{"Mode", Menu::Descriptor::Action::GotoPageDeviceMode}, //
|
||||||
{"Brightness", Menu::Descriptor::Action::GotoPageLedBrightness}, //
|
{"Brightness", Menu::Descriptor::Action::GotoPageLedBrightness}, //
|
||||||
{"Sensitvty", Menu::Descriptor::Action::GotoPageTriggerThreshold}, //
|
{"Sensitvty", Menu::Descriptor::Action::GotoPageTriggerThreshold}, //
|
||||||
|
{"Reset", Menu::Descriptor::Action::GotoPageReset}, //
|
||||||
{"BOOTSEL", Menu::Descriptor::Action::GotoPageBootsel}}, //
|
{"BOOTSEL", Menu::Descriptor::Action::GotoPageBootsel}}, //
|
||||||
0, //
|
0, //
|
||||||
Menu::Page::None}}, //
|
Menu::Page::None}}, //
|
||||||
@ -79,6 +80,14 @@ const std::map<Menu::Page, const Menu::Descriptor> Menu::descriptors = {
|
|||||||
UINT8_MAX, //
|
UINT8_MAX, //
|
||||||
Menu::Page::Main}}, //
|
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::Page::Bootsel, //
|
||||||
{Menu::Descriptor::Type::Selection, //
|
{Menu::Descriptor::Type::Selection, //
|
||||||
"Reboot to BOOTSEL", //
|
"Reboot to BOOTSEL", //
|
||||||
@ -204,6 +213,7 @@ uint16_t Menu::getCurrentSelection(Menu::Page page) {
|
|||||||
break;
|
break;
|
||||||
case Page::Main:
|
case Page::Main:
|
||||||
case Page::TriggerThreshold:
|
case Page::TriggerThreshold:
|
||||||
|
case Page::Reset:
|
||||||
case Page::Bootsel:
|
case Page::Bootsel:
|
||||||
case Page::BootselMsg:
|
case Page::BootselMsg:
|
||||||
case Page::None:
|
case Page::None:
|
||||||
@ -250,6 +260,9 @@ void Menu::performSelectionAction(Menu::Descriptor::Action action) {
|
|||||||
case Descriptor::Action::GotoPageLedBrightness:
|
case Descriptor::Action::GotoPageLedBrightness:
|
||||||
gotoPage(Page::LedBrightness);
|
gotoPage(Page::LedBrightness);
|
||||||
break;
|
break;
|
||||||
|
case Descriptor::Action::GotoPageReset:
|
||||||
|
gotoPage(Page::Reset);
|
||||||
|
break;
|
||||||
case Descriptor::Action::GotoPageBootsel:
|
case Descriptor::Action::GotoPageBootsel:
|
||||||
gotoPage(Page::Bootsel);
|
gotoPage(Page::Bootsel);
|
||||||
break;
|
break;
|
||||||
@ -291,10 +304,16 @@ void Menu::performSelectionAction(Menu::Descriptor::Action action) {
|
|||||||
case Descriptor::Action::SetLedBrightness:
|
case Descriptor::Action::SetLedBrightness:
|
||||||
gotoPage(descriptor_it->second.parent);
|
gotoPage(descriptor_it->second.parent);
|
||||||
break;
|
break;
|
||||||
|
case Descriptor::Action::DoReset:
|
||||||
|
m_store->reset();
|
||||||
|
break;
|
||||||
case Descriptor::Action::DoRebootToBootsel:
|
case Descriptor::Action::DoRebootToBootsel:
|
||||||
m_store->scheduleReboot(true);
|
m_store->scheduleReboot(true);
|
||||||
gotoPage(Page::BootselMsg);
|
gotoPage(Page::BootselMsg);
|
||||||
break;
|
break;
|
||||||
|
case Descriptor::Action::GotoParent:
|
||||||
|
gotoPage(descriptor_it->second.parent);
|
||||||
|
break;
|
||||||
case Descriptor::Action::None:
|
case Descriptor::Action::None:
|
||||||
break;
|
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) {
|
void SettingsStore::scheduleReboot(const bool bootsel) {
|
||||||
if (m_scheduled_reboot != RebootType::Bootsel) {
|
if (m_scheduled_reboot != RebootType::Bootsel) {
|
||||||
m_scheduled_reboot = (bootsel ? RebootType::Bootsel : RebootType::Normal);
|
m_scheduled_reboot = (bootsel ? RebootType::Bootsel : RebootType::Normal);
|
||||||
|
Loading…
Reference in New Issue
Block a user