diff --git a/main.c b/main.c index f3949cf..9d3c034 100644 --- a/main.c +++ b/main.c @@ -8,6 +8,7 @@ #include #include #include +#include #include RTCDateTime timespec; @@ -52,7 +53,7 @@ static THD_FUNCTION(Thread1, arg) chRegSetThreadName("blink"); - palSetPadMode(GPIOC, 13, PAL_MODE_OUTPUT_PUSHPULL); + //palSetPadMode(GPIOC, 13, PAL_MODE_OUTPUT_PUSHPULL); while (1) { #if 0 @@ -224,6 +225,18 @@ wait_dsp(int count) ; } +static void +duplicate_buffer_to_dump(int16_t *p) +{ + if (dump_selection == 1) + p = samp_buf; + else if (dump_selection == 2) + p = ref_buf; + else if (dump_selection == 3) + p = refiq_buf; + memcpy(dump_buffer, p, sizeof dump_buffer); +} + void i2s_end_callback(I2SDriver *i2sp, size_t offset, size_t n) { #if PORT_SUPPORTS_RT @@ -233,19 +246,12 @@ void i2s_end_callback(I2SDriver *i2sp, size_t offset, size_t n) int16_t *p = &rx_buffer[offset]; (void)i2sp; (void)n; - //palClearPad(GPIOC, GPIOC_LED); dsp_process(p, n); if (wait_count > 0) { - if (dump_selection == 1) - p = samp_buf; - else if (dump_selection == 2) - p = ref_buf; - else if (dump_selection == 3) - p = refiq_buf; if (wait_count == 1) - memcpy(dump_buffer, p, sizeof dump_buffer); + duplicate_buffer_to_dump(p); --wait_count; } @@ -256,7 +262,6 @@ void i2s_end_callback(I2SDriver *i2sp, size_t offset, size_t n) stat.last_counter_value = cnt_s; #endif stat.callback_count++; - //palSetPad(GPIOC, GPIOC_LED); } static const I2SConfig i2sconfig = { @@ -301,7 +306,6 @@ static void cmd_dump(BaseSequentialStream *chp, int argc, char *argv[]) if (argc == 1) dump_selection = atoi(argv[0]); - //palClearPad(GPIOC, GPIOC_LED); wait_dsp(3); len = AUDIO_BUFFER_LEN; @@ -313,7 +317,6 @@ static void cmd_dump(BaseSequentialStream *chp, int argc, char *argv[]) } chprintf(chp, "\r\n"); } - //palSetPad(GPIOC, GPIOC_LED); } static void cmd_gamma(BaseSequentialStream *chp, int argc, char *argv[]) @@ -445,7 +448,7 @@ static void cmd_scan_lcd(BaseSequentialStream *chp, int argc, char *argv[]) #endif void -set_frequencies(void) +update_frequencies(void) { int i; int32_t span = (freq_stop - freq_start)/100; @@ -488,7 +491,7 @@ static void cmd_sweep(BaseSequentialStream *chp, int argc, char *argv[]) sweep_points = x; } - set_frequencies(); + update_frequencies(); set_sweep(freq_start, freq_stop); } @@ -853,6 +856,43 @@ void set_trace_type(int t, int type) force_set_markmap(); } +static float +my_atof(const char *p) +{ + int neg = FALSE; + if (*p == '-') + neg = TRUE; + if (*p == '-' || *p == '+') + p++; + float x = atoi(p); + while (isdigit(*p)) + p++; + if (*p == '.') { + float d = 1.0f; + p++; + while (isdigit(*p)) { + d /= 10; + x += d * (*p - '0'); + p++; + } + } + if (*p == 'e' || *p == 'E') { + p++; + int exp = atoi(p); + while (exp > 0) { + x *= 10; + exp--; + } + while (exp < 0) { + x /= 10; + exp++; + } + } + if (neg) + x = -x; + return x; +} + static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[]) { int t; @@ -903,7 +943,7 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[]) } else if (strcmp(argv[1], "off") == 0) { set_trace_type(t, TRC_OFF); } else if (strcmp(argv[1], "scale") == 0 && argc >= 3) { - trace[t].scale = atoi(argv[2]); + trace[t].scale = my_atof(argv[2]); goto exit; } } @@ -1156,7 +1196,7 @@ int main(void) plot_init(); /* initial frequencies */ - set_frequencies(); + update_frequencies(); /* restore config and calibration data from flash memory */ caldata_recall(0); diff --git a/nanovna.h b/nanovna.h index 3e8b06d..4543959 100644 --- a/nanovna.h +++ b/nanovna.h @@ -232,6 +232,8 @@ void ui_init(void); void ui_show(void); void ui_hide(void); +extern uint8_t operation_requested; + /* * misclinous diff --git a/plot.c b/plot.c index fe7afdb..192ff7c 100644 --- a/plot.c +++ b/plot.c @@ -487,7 +487,7 @@ trace_into_index(int x, int t, int i, float coeff[2]) v = 1 - logmag(coeff); break; case TRC_PHASE: - v = 4 + phase(coeff); + v = 4 - phase(coeff); break; case TRC_LINEAR: v = 8 + linear(coeff); @@ -1122,6 +1122,8 @@ draw_cell_all(void) if (is_mapmarked(m, n)) draw_cell(m, n); //ui_process(); + //if (operation_requested) + // return; } // keep current map for update diff --git a/ui.c b/ui.c index ca62be1..7b80e0f 100644 --- a/ui.c +++ b/ui.c @@ -37,9 +37,9 @@ struct { #define EVT_DOWN 0x20 #define EVT_REPEAT 0x40 -#define BUTTON_DOWN_LONG_TICKS 1000 -#define BUTTON_DOUBLE_TICKS 500 -#define BUTTON_DEBOUNCE_TICKS 2 +#define BUTTON_DOWN_LONG_TICKS 10000 /* 1sec */ +#define BUTTON_DOUBLE_TICKS 5000 /* 500ms */ +#define BUTTON_DEBOUNCE_TICKS 10 /* lever switch assignment */ #define BIT_UP1 3 @@ -59,7 +59,6 @@ int ui_status = FALSE; int selection = 1; - static int btn_check(void) { int cur_button = READ_PORT() & BUTTON_MASK; @@ -242,6 +241,12 @@ menu_format_cb(int item) ui_hide(); } +static void +menu_format2_cb(int item) +{ + menu_format_cb(item + 5); +} + static void choose_active_marker(void) { @@ -299,13 +304,22 @@ const menuitem_t menu_trace[] = { { MT_NONE, NULL, NULL } // sentinel }; +const menuitem_t menu_format2[] = { + { MT_CALLBACK, "LINEAR", menu_format2_cb }, + { MT_CALLBACK, "SWR", menu_format2_cb }, + { MT_CANCEL, "BACK", NULL }, + { MT_NONE, NULL, NULL } // sentinel +}; + const menuitem_t menu_format[] = { { MT_CALLBACK, "LOGMAG", menu_format_cb }, { MT_CALLBACK, "PHASE", menu_format_cb }, { MT_CALLBACK, "SMITH", menu_format_cb }, { MT_CALLBACK, "ADMIT", menu_format_cb }, - { MT_CALLBACK, "DELAY", menu_format_cb }, - { MT_CALLBACK, "SWR", menu_format_cb }, + { MT_CALLBACK, "POLAR", menu_format_cb }, + { MT_SUBMENU, "NEXT", menu_format2 }, + //{ MT_CALLBACK, "LINEAR", menu_format_cb }, + //{ MT_CALLBACK, "SWR", menu_format_cb }, { MT_CANCEL, "BACK", NULL }, { MT_NONE, NULL, NULL } // sentinel }; @@ -524,19 +538,7 @@ static void extcb1(EXTDriver *extp, expchannel_t channel) { (void)extp; (void)channel; operation_requested = TRUE; - -#if 0 - if (channel == 1) - ui_status = TRUE; - else if (channel == 2) - ui_status = !ui_status; - else if (channel == 3) - ui_status = FALSE; - if (ui_status) - ui_show(); - else - ui_hide(); -#endif + //cur_button = READ_PORT() & BUTTON_MASK; } static const EXTConfig extcfg = {