Skip to content

Commit d98abb6

Browse files
committed
feat: factory reset in LCD settings menu
Scroll to the last item in Setup menu to see '>> FACTORY RESET <<'. Press S to execute: clears all NV settings, shows confirmation, beeps, and returns to home screen. Accessible both from LCD (Setup menu) and serial ('factory reset').
1 parent 872b9d8 commit d98abb6

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/main.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,24 @@ static int32_t Main_Work(void) {
735735

736736
// Leave setup
737737
if (keyspressed & KEY_S) {
738+
if (Setup_isFactoryResetItem(selected)) {
739+
// Factory reset from UI
740+
NV_FactoryReset();
741+
Reflow_ValidateNV();
742+
Reflow_LoadCustomProfiles();
743+
LCD_FB_Clear();
744+
len = snprintf(buf, sizeof(buf), "FACTORY RESET OK");
745+
LCD_disp_str((uint8_t*)buf, len, 13, 28, FONT6X6);
746+
LCD_FB_Update();
747+
Buzzer_Beep(BUZZ_1KHZ, 255, TICKS_MS(100));
748+
// Brief pause so user sees the message
749+
int wait = 20; // ~2 seconds at 100ms ticks
750+
while (wait-- > 0) { retval = TICKS_MS(100); }
751+
mode = MAIN_HOME;
752+
Reflow_SetMode(REFLOW_STANDBY);
753+
retval = 0;
738754
// If on bang-bang rows and bang-bang is ON, go to BB Tune
739-
if (NV_GetConfig(REFLOW_BANGBANG_MODE) && selected >= 7 && selected <= 9) {
755+
} else if (NV_GetConfig(REFLOW_BANGBANG_MODE) && selected >= 7 && selected <= 9) {
740756
mode = MAIN_BBTUNE;
741757
Reflow_SetMode(REFLOW_STANDBY);
742758
retval = 0;

src/setup.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ static setupMenuStruct setupmenu[] = {
4848
};
4949

5050
#define NUM_SETUP_ITEMS (sizeof(setupmenu) / sizeof(setupmenu[0]))
51+
#define FACTORY_RESET_IDX NUM_SETUP_ITEMS // Virtual item after all real items
5152

5253
int Setup_getNumItems(void) {
53-
return NUM_SETUP_ITEMS;
54+
return NUM_SETUP_ITEMS + 1; // +1 for factory reset
55+
}
56+
57+
int Setup_isFactoryResetItem(int item) {
58+
return item == FACTORY_RESET_IDX;
5459
}
5560

5661
int _getRawValue(int item) {
@@ -75,6 +80,7 @@ void Setup_setRealValue(int item, float value) {
7580
}
7681

7782
void Setup_increaseValue(int item, int amount) {
83+
if (item >= (int)NUM_SETUP_ITEMS) return; // Factory reset item — no value
7884
int curval = _getRawValue(item) + amount;
7985
int maxval = setupmenu[item].maxval;
8086
if(curval > maxval)
@@ -83,6 +89,7 @@ void Setup_increaseValue(int item, int amount) {
8389
}
8490

8591
void Setup_decreaseValue(int item, int amount) {
92+
if (item >= (int)NUM_SETUP_ITEMS) return; // Factory reset item — no value
8693
int curval = _getRawValue(item) - amount;
8794
int minval = setupmenu[item].minval;
8895
if(curval < minval)
@@ -95,6 +102,9 @@ void Setup_printFormattedValue(int item) {
95102
}
96103

97104
int Setup_snprintFormattedValue(char* buf, int n, int item) {
105+
if (item >= (int)NUM_SETUP_ITEMS) {
106+
return snprintf(buf, n, ">> FACTORY RESET <<");
107+
}
98108
int curval = _getRawValue(item);
99109
int minval = setupmenu[item].minval;
100110
int maxval = setupmenu[item].maxval;

src/setup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ void Setup_increaseValue(int item, int amount);
2020
void Setup_decreaseValue(int item, int amount);
2121
void Setup_printFormattedValue(int item);
2222
int Setup_snprintFormattedValue(char* buf, int n, int item);
23+
int Setup_isFactoryResetItem(int item);
2324

2425
#endif /* SETUP_H_ */

0 commit comments

Comments
 (0)