From 425221aa10a6cd4b2c4e75e18447243c19a3b473 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Wed, 24 Jun 2020 23:36:51 +0300 Subject: [PATCH] Use better button input debounce and input process (this used in last NanoVNA firmwares) more compact and simple Replace POINTS_COUNT to sweep_points this more correct --- plot.c | 24 +++++-------- si4432.c | 4 +-- ui.c | 104 ++++++++++++++++++++++++------------------------------- 3 files changed, 57 insertions(+), 75 deletions(-) diff --git a/plot.c b/plot.c index 4dc1950..4c44bec 100644 --- a/plot.c +++ b/plot.c @@ -863,7 +863,7 @@ static void trace_get_value_string( if (FREQ_IS_CW()) { float t = ii*(setting.actual_sweep_time)*1000.0/290.0; #if 1 - plot_printf(&buf2[1], sizeof(buf2) -1, "%.3FS" , t/1000000.0); + plot_printf(&buf2[1], sizeof(buf2) -1, "%.3Fs" , t/1000000.0); #else if (t>1000000.0){ plot_printf(&buf2[1], sizeof(buf2) -1, "%4f" , t/1000000.0); @@ -884,22 +884,17 @@ static void trace_get_value_string( } #endif } else { - uint32_t resolution = get_sweep_frequency(ST_SPAN)/290; -#if 0 - if (resolution <= 2000) +#if 1 + uint32_t resolution = get_sweep_frequency(ST_SPAN); + if (resolution <= 2000*290) plot_printf(&buf2[1], sizeof(buf2) -1, "%3.3f" , (dfreq + 500) / 1000000.0); - else if (resolution <= 20000) + else if (resolution <= 20000*290) plot_printf(&buf2[1], sizeof(buf2) -1, "%3.2f" , (dfreq + 5000) / 1000000.0); else plot_printf(&buf2[1], sizeof(buf2) -1, "%3.1f" , (dfreq + 50000) / 1000000.0); } #else - int digits = 1; - if (resolution <= 2000) - digits = 3; - else if (resolution <= 20000) - digits = 2; - plot_printf(&buf2[1], sizeof(buf2) -1, "%3.*f" , digits, (dfreq + 50000) / 1000000.0); + plot_printf(&buf2[1], sizeof(buf2) -1, "%.8qHz" , dfreq); } #endif // frequency_string(&buf2[1], sizeof(buf2) -1, dfreq); @@ -1906,7 +1901,7 @@ cell_draw_marker_info(int x0, int y0) #endif static void cell_draw_marker_info(int x0, int y0) { - char buf[25]; + char buf[32]; int t; int ref_marker = 0; int j = 0; @@ -1991,16 +1986,15 @@ static void cell_draw_marker_info(int x0, int y0) if (markers[i].mtype & M_NOISE) buf[k++] = 'N'; buf[k++] = ' '; - buf[k++] = 0; +// buf[k++] = 0; ili9341_set_background(DEFAULT_BG_COLOR); ili9341_set_foreground(marker_color(markers[i].mtype)); // if (setting.unit) // cell_drawstring(buf, xpos, ypos); // else // cell_drawstring_7x13(buf, xpos, ypos); - int offs = strlen(buf); trace_get_value_string( - t, &buf[offs], (sizeof buf) - offs, + t, &buf[k], (sizeof buf) - k, idx, measured[trace[t].channel], frequencies, sweep_points, ridx, markers[i].mtype); if (/* strlen(buf)*7> WIDTH/2 && */active > 1) cell_drawstring(buf, xpos, ypos); diff --git a/si4432.c b/si4432.c index 4a7ff90..daea334 100644 --- a/si4432.c +++ b/si4432.c @@ -327,7 +327,7 @@ void SI4432_Fill(int s, int start) if (t < 0) t = 0; int ti = t * 1000 / 290.0; // Now in uS per point if (t < 30000) - for (int i=start; i= last_button_down_ticks + BUTTON_DEBOUNCE_TICKS) { - // button released - status |= EVT_BUTTON_SINGLE_CLICK; - if (inhibit_until_release) { - status = 0; - inhibit_until_release = FALSE; - } - } - } - if (changed & (1<= last_button_down_ticks + BUTTON_DEBOUNCE_TICKS)) { - status |= EVT_UP; - } - } - if (changed & (1<= last_button_down_ticks + BUTTON_DEBOUNCE_TICKS)) { - status |= EVT_DOWN; - } - } - last_button_down_ticks = ticks; - last_button = cur_button; - - return status; + systime_t ticks; + // Debounce input + while(TRUE){ + ticks = chVTGetSystemTimeX(); + if(ticks - last_button_down_ticks > BUTTON_DEBOUNCE_TICKS) + break; + chThdSleepMilliseconds(10); + } + int status = 0; + uint16_t cur_button = READ_PORT() & BUTTON_MASK; + // Detect only changed and pressed buttons + uint16_t button_set = (last_button ^ cur_button) & cur_button; + last_button_down_ticks = ticks; + last_button = cur_button; + + if (button_set & (1<= last_button_down_ticks + BUTTON_DOWN_LONG_TICKS) { - inhibit_until_release = TRUE; - return EVT_BUTTON_DOWN_LONG; - } - if ((changed & (1<= BUTTON_DOWN_LONG_TICKS && (cur_button & (1<= last_button_down_ticks + BUTTON_DOWN_LONG_TICKS - && ticks >= last_button_repeat_ticks + BUTTON_REPEAT_TICKS) { + if (dt > BUTTON_DOWN_LONG_TICKS && + ticks > last_button_repeat_ticks) { + int status = 0; if (cur_button & (1< POINTS_COUNT-1) - markers[active_marker].index = POINTS_COUNT-1 ; + if (markers[active_marker].index > sweep_points-1) + markers[active_marker].index = sweep_points-1 ; markers[active_marker].frequency = frequencies[markers[active_marker].index]; redraw_marker(active_marker); }