From 6148013c545399cf14ad4f733b9876c433b3c151 Mon Sep 17 00:00:00 2001 From: DiSlord Live Date: Sun, 11 Dec 2022 13:53:42 +0300 Subject: [PATCH] Rewrite progress bar update/remove dead code/use buffering in cmd_scanraw cmd_vbat now run in sweep thread --- main.c | 9 ++++----- sa_cmd.c | 46 ++++++++++++++++++++++++---------------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/main.c b/main.c index 74fbbd4..f0896e5 100644 --- a/main.c +++ b/main.c @@ -2069,7 +2069,7 @@ static const VNAShellCommand commands[] = {"touch" , cmd_touch , 0}, {"release" , cmd_release , 0}, #endif - {"vbat" , cmd_vbat , 0}, // Uses same adc as touch!!!!! + {"vbat" , cmd_vbat , CMD_WAIT_MUTEX}, // Uses same adc as touch!!!!! #ifdef ENABLE_VBAT_OFFSET_COMMAND {"vbat_offset" , cmd_vbat_offset , CMD_RUN_IN_LOAD}, #endif @@ -2415,10 +2415,9 @@ static void VNAShell_executeLine(char *line) shell_function = scp->sc_function; operation_requested|=OP_CONSOLE; // this will abort current sweep to give priority to the new request // Wait execute command in sweep thread - osalThreadEnqueueTimeoutS(&shell_thread, TIME_INFINITE); -// do { -// osalThreadSleepMilliseconds(10); -// } while (shell_function); + do { + osalThreadEnqueueTimeoutS(&shell_thread, TIME_INFINITE); + } while (shell_function); } else { operation_requested = false; // otherwise commands will be aborted scp->sc_function(shell_nargs - 1, &shell_args[1]); diff --git a/sa_cmd.c b/sa_cmd.c index c4f5155..2da7f5e 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -1245,37 +1245,39 @@ VNA_SHELL_FUNCTION(cmd_scanraw) float f_step = (stop-start)/ points; setting.frequency_step = (freq_t)f_step; - streamPut(shell_stream, '{'); - static freq_t old_start=0, old_stop=0; - static uint32_t old_points=0; - if (old_start != start || old_stop != stop || old_points != points) { // To prevent dirty for every sweep - dirty = true; - old_start = start; - old_stop = stop; - old_points = points; - } operation_requested = false; dirty = true; - - for (uint32_t i = 0; iusbp->state != USB_ACTIVE) // break on operation in perform break; - streamPut(shell_stream, 'x'); - streamPut(shell_stream, (uint8_t)(val & 0xFF)); - streamPut(shell_stream, (uint8_t)((val>>8) & 0xFF)); - if ((i & 0x07) == 0) { // if required - int pos = i * (WIDTH+1) / points; - ili9341_set_background(LCD_SWEEP_LINE_COLOR); - ili9341_fill(OFFSETX, CHART_BOTTOM+1, pos, 1); // update sweep progress bar - ili9341_set_background(LCD_BG_COLOR); - ili9341_fill(OFFSETX+pos, CHART_BOTTOM+1, WIDTH-pos, 1); + buf[idx++] = 'x'; + buf[idx++] = (uint8_t)(val & 0xFF); + buf[idx++] = (uint8_t)((val>>8) & 0xFF); + if (idx >= BUFFER_SIZE - 4) { + streamWrite(shell_stream, buf, idx); + idx = 0; + } + int pos = i * (WIDTH+1) / points; + if (pos - oldpos > 8) { + ili9341_fill(OFFSETX + oldpos, CHART_BOTTOM+1, pos - oldpos, 1); // update sweep progress bar + oldpos = pos; } - } + buf[idx++] = '}'; + streamWrite(shell_stream, buf, idx); +// adc_start_analog_watchdog(); ili9341_set_background(LCD_BG_COLOR); ili9341_fill(OFFSETX, CHART_BOTTOM+1, WIDTH, 1); - streamPut(shell_stream, '}'); setting.frequency_step = old_step; dirty = true; redraw_request = 0; // disable screen update in this mode