Skip to content

Commit 872b9d8

Browse files
committed
feat: add factory reset serial command
'factory reset' clears all NV settings to 0xFF and writes to EEPROM immediately, then re-initializes defaults via Reflow_ValidateNV(). Essential when upgrading from stock or pre-v2.0 firmware where the EEPROM layout is different and values would be misinterpreted.
1 parent ed5db4a commit 872b9d8

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static char* help_text = \
9898
" pidtune Run PID auto-tune\n" \
9999
" tccal Run TC offset auto-calibration\n" \
100100
" values Dump currently measured values\n" \
101+
" factory reset Reset all settings to defaults\n" \
101102
"\n";
102103

103104

@@ -616,6 +617,12 @@ static int32_t Main_Work(void) {
616617
} else if (strcmp(serial_cmd, "backup") == 0) {
617618
FlashProfiles_BackupAll();
618619

620+
} else if (strcmp(serial_cmd, "factory reset") == 0) {
621+
NV_FactoryReset();
622+
Reflow_ValidateNV();
623+
Reflow_LoadCustomProfiles();
624+
printf("\nReboot recommended.\n");
625+
619626
} else {
620627
printf("\nCannot understand command, ? for help\n");
621628
}

src/nvstorage.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,9 @@ int32_t NV_Work(void) {
9494
}
9595
return nvupdatepending ? (TICKS_SECS(2)) : -1;
9696
}
97+
98+
void NV_FactoryReset(void) {
99+
memset(myNV.config, 0xff, NVITEM_NUM_ITEMS);
100+
EEPROM_Write(NV_STORAGE_OFFSET, (uint8_t*)&myNV, sizeof(myNV));
101+
printf("\nFactory reset complete — all settings cleared to defaults.\n");
102+
}

src/nvstorage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ void NV_Init(void);
4545
uint8_t NV_GetConfig(NVItem_t item);
4646
void NV_SetConfig(NVItem_t item, uint8_t value);
4747
int32_t NV_Work(void);
48+
void NV_FactoryReset(void);
4849

4950
#endif /* NVSTORAGE_H_ */

0 commit comments

Comments
 (0)