diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml
index 25405c1..abc65ba 100644
--- a/.settings/language.settings.xml
+++ b/.settings/language.settings.xml
@@ -5,7 +5,7 @@
-
+
@@ -17,7 +17,7 @@
-
+
diff --git a/main.c b/main.c
index 5fddee9..9feddc9 100644
--- a/main.c
+++ b/main.c
@@ -109,6 +109,14 @@ int32_t scan_after_dirty = 0;
uint8_t completed = false;
uint8_t enable_after_complete = 0;
+void clear_backup(void) {
+ uint32_t *f = &backup; // Clear backup when no valid config data
+ int i = USED_BACKUP_SIZE;
+ while (i--)
+ *f++ = 0;
+}
+
+
#ifdef TINYSA4
static THD_WORKING_AREA(waThread1, 1224);
#else
@@ -2645,10 +2653,7 @@ int main(void)
config.switch_offset = -5.0;
#endif
if(config_recall()) {
- uint32_t *f = &backup; // Clear backup when no valid config data
- int i = USED_BACKUP_SIZE;
- while (i--)
- *f++ = 0;
+ clear_backup();
}
config.cor_am = 0; // Should be removed from config
config.cor_nfm = 0;
@@ -2703,7 +2708,7 @@ int main(void)
load_LCD_properties();
}
ui_mode_normal();
- {
+ if (!(config._mode & _MODE_DONT_SAVE_STATE)) {
backup_t b;
uint32_t *f = &backup;
uint32_t *t = (uint32_t *)&b;
diff --git a/nanovna.h b/nanovna.h
index e006d91..0f1bd76 100644
--- a/nanovna.h
+++ b/nanovna.h
@@ -18,7 +18,7 @@
*/
#include "ch.h"
-//#ifdef TINYSA_F303
+#ifdef TINYSA_F303
#ifdef TINYSA_F072
#error "Remove comment for #ifdef TINYSA_F303"
#endif
@@ -26,7 +26,7 @@
#define TINYSA4
#endif
#define TINYSA4_PROTO
-//#endif
+#endif
#ifdef TINYSA_F072
#ifdef TINYSA_F303
@@ -248,6 +248,7 @@ float my_atof(const char *p);
freq_t my_atoui(const char *p);
int shell_printf(const char *fmt, ...);
int usage_printf(const char *fmt, ...);
+void clear_backup(void);
#ifdef __REMOTE_DESKTOP__
extern uint8_t remote_mouse_down;
@@ -718,6 +719,8 @@ float marker_to_value(const int i);
#define _MODE_SERIAL 0x04
#define _MODE_USB 0x00
+#define _MODE_DONT_SAVE_STATE 0x08
+
#pragma pack(push, 4)
typedef struct config {
int32_t magic;
diff --git a/ui.c b/ui.c
index d595e7c..e70593c 100644
--- a/ui.c
+++ b/ui.c
@@ -1773,10 +1773,11 @@ static UI_FUNCTION_ADV_CALLBACK(menu_store_preset_acb)
b->param_1.u = data;
return;
}
- if (data == 100) {
+ if (data >= 100) {
reset_settings(M_LOW); // Restore all defaults in Low mode
set_refer_output(-1);
// setting.mode = -1;
+ if (data == 101) clear_backup();
data = 0;
}
caldata_save(data);
@@ -3287,6 +3288,17 @@ static UI_FUNCTION_ADV_CALLBACK(menu_settings_pulse_acb){
toggle_pulse();
}
+static UI_FUNCTION_ADV_CALLBACK(menu_save_state_acb){
+ (void)item;
+ (void)data;
+ if(b){
+ b->icon = (config._mode & _MODE_DONT_SAVE_STATE) ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK;
+ return;
+ }
+ config._mode ^= _MODE_DONT_SAVE_STATE;
+ config_save();
+}
+
#ifdef __DRAW_LINE__
static UI_FUNCTION_ADV_CALLBACK(menu_settings_draw_line_acb){
(void)item;
@@ -3511,7 +3523,6 @@ static const menuitem_t menu_store_preset[] =
{
{ MT_ADV_CALLBACK, 0, "STORE AS\nSTARTUP",menu_store_preset_acb},
{ MT_ADV_CALLBACK |MT_REPEATS, DATA_STARTS_REPEATS(1,4), "STORE %d", menu_store_preset_acb},
- { MT_ADV_CALLBACK, 100,"FACTORY\nDEFAULTS",menu_store_preset_acb},
{ MT_NONE, 0, NULL,menu_back} // next-> menu_back
};
@@ -3519,6 +3530,8 @@ static const menuitem_t menu_load_preset[] =
{
{ MT_ADV_CALLBACK, 0, "LOAD\nSTARTUP", menu_load_preset_acb},
{ MT_ADV_CALLBACK|MT_REPEATS, DATA_STARTS_REPEATS(1,4), MT_CUSTOM_LABEL, menu_load_preset_acb},
+ { MT_ADV_CALLBACK, 101, "LOAD\nDEFAULTS",menu_store_preset_acb},
+ { MT_ADV_CALLBACK, _MODE_DONT_SAVE_STATE, "SAVE\nSTATE", menu_save_state_acb},
{ MT_SUBMENU, 0, "STORE" , menu_store_preset},
{ MT_NONE, 0, NULL, menu_back} // next-> menu_back
};