From bb860080de21a6e08fa3810e4087157bbde394ba Mon Sep 17 00:00:00 2001 From: DiSlord Live Date: Sat, 3 Dec 2022 17:53:47 +0300 Subject: [PATCH] Add SWEEP_UI_MODE flag for console command This allow run command if active thread in UI mode --- main.c | 13 ++++++++++--- nanovna.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 30c5e34..55f5c21 100644 --- a/main.c +++ b/main.c @@ -218,8 +218,11 @@ static THD_FUNCTION(Thread1, arg) } // START_PROFILE // Process UI inputs - if (!(sweep_mode & SWEEP_SELFTEST)) + if (!(sweep_mode & SWEEP_SELFTEST)) { + sweep_mode|= SWEEP_UI_MODE; ui_process(); + sweep_mode&=~SWEEP_UI_MODE; + } // Process collected data, calculate trace coordinates and plot only if scan // completed if (completed) { @@ -2011,6 +2014,7 @@ typedef struct { // Some commands can executed only in sweep thread, not in main cycle #define CMD_WAIT_MUTEX 1 #define CMD_RUN_IN_LOAD 2 +#define CMD_RUN_IN_UI 4 static const VNAShellCommand commands[] = { {"version" , cmd_version , 0}, @@ -2059,7 +2063,7 @@ static const VNAShellCommand commands[] = {"usart" , cmd_usart , CMD_WAIT_MUTEX}, {"usart_cfg" , cmd_usart_cfg , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD}, #endif - {"capture" , cmd_capture , CMD_WAIT_MUTEX}, + {"capture" , cmd_capture , CMD_WAIT_MUTEX | CMD_RUN_IN_UI}, #ifdef __REMOTE_DESKTOP__ {"refresh" , cmd_refresh , 0}, {"touch" , cmd_touch , 0}, @@ -2404,7 +2408,10 @@ static void VNAShell_executeLine(char *line) // Execute line const VNAShellCommand *scp = VNAShell_parceLine(line); if (scp) { - if (scp->flags & CMD_WAIT_MUTEX) { + uint16_t cmd_flag = scp->flags; + // Skip wait mutex if process UI + if ((cmd_flag & CMD_RUN_IN_UI) && (sweep_mode&SWEEP_UI_MODE)) cmd_flag&=~CMD_WAIT_MUTEX; + if (cmd_flag & CMD_WAIT_MUTEX) { 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 diff --git a/nanovna.h b/nanovna.h index f5be140..5fd9170 100644 --- a/nanovna.h +++ b/nanovna.h @@ -323,6 +323,7 @@ enum { #define SWEEP_CALIBRATE_HARMONIC 0x40 //#define SWEEP_FACTORY 0x20 #endif +#define SWEEP_UI_MODE 0x80 extern uint8_t sweep_mode; extern uint8_t completed;