From 857be0862a5b32156e7218473f8baeef219124c6 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Thu, 6 May 2021 18:51:19 +0200 Subject: [PATCH] Keypad freq input and sleep while waiting setting --- main.c | 2 ++ nanovna.h | 1 + si4468.c | 3 ++- ui.c | 15 ++++++++++++++- ui_sa.c | 38 +++++++++++++++++++++++++++----------- 5 files changed, 46 insertions(+), 13 deletions(-) diff --git a/main.c b/main.c index fe6f615..841db03 100644 --- a/main.c +++ b/main.c @@ -574,6 +574,8 @@ my_atof(const char *p) float x = my_atoi(p); while (_isdigit((int)*p)) p++; + if (*p == 'k' || *p == 'M' || *p == 'G') + p++; if (*p == '.') { float d = 1.0; p++; diff --git a/nanovna.h b/nanovna.h index 832587c..b8e651e 100644 --- a/nanovna.h +++ b/nanovna.h @@ -235,6 +235,7 @@ void set_sweep_frequency(int type, freq_t frequency); freq_t get_sweep_frequency(int type); void my_microsecond_delay(int t); float my_atof(const char *p); +freq_t my_atoui(const char *p); int shell_printf(const char *fmt, ...); #ifdef __REMOTE_DESKTOP__ void send_region(const char *t, int16_t x, int16_t y, int16_t w, int16_t h); diff --git a/si4468.c b/si4468.c index 9c57ff3..857a9a8 100644 --- a/si4468.c +++ b/si4468.c @@ -567,7 +567,8 @@ static void SI4463_set_state(si446x_state_t); #define SI4463_READ_CTS (palReadLine(LINE_RX_CTS)) #ifdef __WAIT_CTS_WHILE_SLEEPING__ -#define SI4463_WAIT_CTS while (!SI4463_READ_CTS) __WFI(); +extern int sleep; +#define SI4463_WAIT_CTS while (!SI4463_READ_CTS) if (sleep) __WFI(); #else #define SI4463_WAIT_CTS while (!SI4463_READ_CTS) ; #endif diff --git a/ui.c b/ui.c index dfb1920..ec295d1 100644 --- a/ui.c +++ b/ui.c @@ -2668,6 +2668,7 @@ keypad_click(int key) { int c = keypads[key].c; if ((c >= KP_X1 && c <= KP_G) || c == KP_m || c == KP_u || c == KP_n) { +#if 0 float scale = 1.0; if (c >= KP_X1 && c <= KP_G) { int n = c - KP_X1; @@ -2682,6 +2683,18 @@ keypad_click(int key) } /* numeric input done */ uistat.value = my_atof(kp_buf) * scale; +#else + char modifier = 0; + if (c == KP_K) modifier = 'k'; + else if (c == KP_M) modifier = 'M'; + else if (c == KP_G) modifier = 'G'; + else if (c == KP_m) modifier = 'm'; + else if (c == KP_u) modifier = 'u'; + else if (c == KP_n) modifier = 'n'; + if (modifier) kp_buf[kp_index++] = modifier; + kp_buf[kp_index++] = 0; + uistat.value = my_atof(kp_buf); +#endif set_numeric_value(); return KP_DONE; } else if (c <= 9 && kp_index < NUMINPUT_LEN) { @@ -2963,7 +2976,7 @@ made_screenshot(int touch_x, int touch_y) buf[i] = __REVSH(buf[i]); // swap byte order (example 0x10FF to 0xFF10) res = f_write(fs_file, buf, LCD_WIDTH*sizeof(uint16_t), &size); } - res = f_close(fs_file); +// res = f_close(fs_file); // shell_printf("Close %d\r\n", res); // testLog(); } diff --git a/ui_sa.c b/ui_sa.c index ac5d26e..789c11a 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1081,6 +1081,18 @@ static UI_FUNCTION_ADV_CALLBACK(menu_ultra_acb) ui_mode_normal(); } +int sleep = 0; +static UI_FUNCTION_ADV_CALLBACK(menu_sleep_acb) +{ + (void)data; + (void)item; + if (b){ + b->icon = sleep == 0 ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK; + return; + } + sleep = !sleep; +} + static UI_FUNCTION_ADV_CALLBACK(menu_debug_avoid_acb) @@ -2304,6 +2316,7 @@ static const menuitem_t menu_settings3[] = { MT_KEYPAD, KM_R, "R", "Set R"}, { MT_KEYPAD, KM_MOD, "MODULO", "Set MODULO"}, { MT_KEYPAD, KM_CP, "CP", "Set CP"}, + { MT_ADV_CALLBACK, 0, "SLEEP\nWAIT", menu_sleep_acb}, // { MT_ADV_CALLBACK | MT_LOW, 0, "ULTRA\nMODE", menu_settings_ultra_acb}, #ifdef __HAM_BAND__ { MT_ADV_CALLBACK, 0, "HAM\nBANDS", menu_settings_ham_bands}, @@ -2882,22 +2895,25 @@ static void fetch_numeric_target(void) static void set_numeric_value(void) { + if (kp_buf[0] == 0) + return; + freq_t freq = my_atoui(kp_buf); switch (keypad_mode) { case KM_START: - set_sweep_frequency(ST_START, (freq_t)uistat.value - (setting.frequency_offset - FREQUENCY_SHIFT)); + set_sweep_frequency(ST_START, freq - (setting.frequency_offset - FREQUENCY_SHIFT)); break; case KM_STOP: - set_sweep_frequency(ST_STOP, (freq_t)uistat.value - (setting.frequency_offset - FREQUENCY_SHIFT)); + set_sweep_frequency(ST_STOP, freq - (setting.frequency_offset - FREQUENCY_SHIFT)); break; case KM_CENTER: - set_sweep_frequency(ST_CENTER, (freq_t)uistat.value - (setting.frequency_offset - FREQUENCY_SHIFT)); + set_sweep_frequency(ST_CENTER, freq - (setting.frequency_offset - FREQUENCY_SHIFT)); break; case KM_SPAN: setting.modulation = MO_NONE; - set_sweep_frequency(ST_SPAN, (freq_t)uistat.value); + set_sweep_frequency(ST_SPAN, freq); break; case KM_CW: - set_sweep_frequency(ST_CW, (freq_t)uistat.value - (setting.frequency_offset - FREQUENCY_SHIFT)); + set_sweep_frequency(ST_CW, freq - (setting.frequency_offset - FREQUENCY_SHIFT)); break; case KM_SCALE: user_set_scale(uistat.value); @@ -2915,12 +2931,12 @@ set_numeric_value(void) break; case KM_IF: setting.auto_IF = false; - set_IF(uistat.value); + set_IF(freq); // config_save(); break; #ifdef TINYSA4 case KM_IF2: - set_IF2(uistat.value); + set_IF2(freq); // config_save(); break; case KM_R: @@ -2972,7 +2988,7 @@ set_numeric_value(void) break; #ifdef __LIMITS__ case KM_LIMIT_FREQ: - setting.limits[active_limit].frequency = uistat.value - (setting.frequency_offset - FREQUENCY_SHIFT); + setting.limits[active_limit].frequency = freq - (setting.frequency_offset - FREQUENCY_SHIFT); limits_update(); break; case KM_LIMIT_LEVEL: @@ -2985,11 +3001,11 @@ set_numeric_value(void) break; #ifdef TINYSA4 case KM_30MHZ: - set_30mhz(uistat.value); + set_30mhz(freq); break; #else case KM_10MHZ: - set_10mhz(uistat.value); + set_10mhz(freq); break; #endif case KM_EXT_GAIN: @@ -3014,7 +3030,7 @@ set_numeric_value(void) set_gridlines(uistat.value); break; case KM_MARKER: - set_marker_frequency(active_marker, (freq_t)uistat.value - (setting.frequency_offset - FREQUENCY_SHIFT)); + set_marker_frequency(active_marker, freq - (setting.frequency_offset - FREQUENCY_SHIFT)); break; case KM_MARKER_TIME: set_marker_time(active_marker, uistat.value);