@ -63,7 +63,22 @@ char shell_line[VNA_SHELL_MAX_LENGTH];
char * shell_args [ VNA_SHELL_MAX_ARGUMENTS + 1 ] ;
uint16_t shell_nargs ;
static volatile vna_shellcmd_t shell_function = 0 ;
static volatile bool shell_function_ui ; // shell_function may also run in a UI wait loop (CMD_RUN_IN_UI)
static volatile uint8_t shell_function_flags ; // CMD_xxx of shell_function: CMD_RUN_IN_UI also runs it in a UI wait loop
// 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
# ifdef __USE_USB_MSC__
# define CMD_DISK_OK 8 // allowed in USB DISK mode, does not use SPI1 or spi_buffer
# else
# define CMD_DISK_OK 0
# endif
# ifdef __UI_OFF__
# define CMD_UI_ON 16 // needs the user at the tinySA: ui on before it runs (with CMD_WAIT_MUTEX)
# else
# define CMD_UI_ON 0
# endif
//#define ENABLED_DUMP
// Allow get threads debug info
@ -90,6 +105,7 @@ void update_frequencies(void);
static void set_frequencies ( freq_t start , freq_t stop , uint16_t points ) ;
static bool sweep ( bool break_on_operation ) ;
static long_t my_atoi ( const char * p ) ;
static bool shell_check_connect ( void ) ;
uint8_t sweep_mode = SWEEP_ENABLE ;
uint16_t sweep_once_count = 1 ;
@ -152,11 +168,12 @@ void shell_run_pending(bool ui_wait)
{
chSysLock ( ) ;
vna_shellcmd_t local_func = shell_function ;
if ( ui_wait & & ! shell_function_ui )
uint8_t local_flags = shell_function_flags ;
if ( ui_wait & & ! ( local_flags & CMD_RUN_IN_UI ) )
local_func = 0 ;
else {
shell_function = 0 ;
shell_function_ ui = false ;
shell_function_ flags = 0 ;
// The shell sets OP_CONSOLE together with shell_function, a request without a
// command (direct command, timed out command) has done its job: the sweep stopped
operation_requested & = ~ OP_CONSOLE ;
@ -166,6 +183,10 @@ void shell_run_pending(bool ui_wait)
if ( local_func ) {
if ( ! ui_wait ) // a UI wait loop keeps a pending touch or lever event
operation_requested = OP_NONE ; // otherwise commands will be aborted
# ifdef __UI_OFF__
if ( local_flags & CMD_UI_ON ) // the command needs the user at the tinySA
set_ui ( true ) ;
# endif
local_func ( shell_nargs - 1 , & shell_args [ 1 ] ) ;
if ( ui_wait | | operation_requested = = OP_NONE ) // Don't prompt if aborted
@ -315,6 +336,12 @@ static THD_FUNCTION(Thread1, arg)
usb_disk_mode ( ) ;
}
# endif
# ifdef __UI_OFF__
if ( ui_off & & ! shell_check_connect ( ) ) { // an unplugged tinySA must not stay blind
set_ui ( true ) ;
ui_on_notice = false ; // no PC to tell
}
# endif
// START_PROFILE
// Process UI inputs
if ( ! ( sweep_mode & SWEEP_SELFTEST ) )
@ -1039,6 +1066,21 @@ VNA_SHELL_FUNCTION(cmd_release)
# endif
# ifdef __UI_OFF__
VNA_SHELL_FUNCTION ( cmd_ui )
{
if ( argc = = 0 ) {
shell_printf ( " ui %s " VNA_SHELL_NEWLINE_STR , ui_off ? " off " : " on " ) ;
return ;
}
int m = generic_option_cmd ( " ui " , " off|on " , argc , argv [ 0 ] ) ;
if ( m > = 0 ) {
set_ui ( m ) ;
ui_on_notice = false ; // the PC asked for it
}
}
# endif
# ifdef TINYSA4
// Row y of the screen for a capture, y counting up from 0: the screen is read as one DMA stream,
// the next row into the other half of buf (2 * LCD_WIDTH pixels) while the caller uses row y.
@ -2758,15 +2800,6 @@ typedef struct {
} VNAShellCommand ;
# pragma pack(pop)
// 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
# ifdef __USE_USB_MSC__
# define CMD_DISK_OK 8 // allowed in USB DISK mode, does not use SPI1 or spi_buffer
# else
# define CMD_DISK_OK 0
# endif
static const VNAShellCommand commands [ ] =
{
{ " version " , cmd_version , CMD_DISK_OK } ,
@ -2799,8 +2832,8 @@ static const VNAShellCommand commands[] =
{ " zero " , cmd_zero , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD } , // Will set the scanraw measured value offset (128 or 174)
{ " sweep " , cmd_sweep , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD } ,
{ " test " , cmd_test , 0 } ,
{ " touchcal " , cmd_touchcal , CMD_WAIT_MUTEX } ,
{ " touchtest " , cmd_touchtest , CMD_WAIT_MUTEX } ,
{ " touchcal " , cmd_touchcal , CMD_WAIT_MUTEX | CMD_UI_ON } ,
{ " touchtest " , cmd_touchtest , CMD_WAIT_MUTEX | CMD_UI_ON } ,
{ " pause " , cmd_pause , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD } ,
# ifdef TINYSA4
{ " restart " , cmd_restart , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD } ,
@ -2830,6 +2863,9 @@ static const VNAShellCommand commands[] =
{ " refresh " , cmd_refresh , CMD_DISK_OK } ,
{ " touch " , cmd_touch , CMD_DISK_OK } ,
{ " release " , cmd_release , CMD_DISK_OK } ,
# endif
# ifdef __UI_OFF__
{ " ui " , cmd_ui , CMD_WAIT_MUTEX } , // draws: runs in the sweep thread
# endif
{ " vbat " , cmd_vbat , CMD_WAIT_MUTEX } , // Uses same adc as touch!!!!!
# ifdef ENABLE_VBAT_OFFSET_COMMAND
@ -2876,10 +2912,14 @@ static const VNAShellCommand commands[] =
{ " ext_gain " , cmd_ext_gain , CMD_RUN_IN_LOAD } ,
{ " output " , cmd_output , CMD_RUN_IN_LOAD } ,
{ " deviceid " , cmd_deviceid , CMD_RUN_IN_LOAD } ,
# ifdef __UI_OFF__
{ " selftest " , cmd_selftest , CMD_WAIT_MUTEX | CMD_UI_ON } , // ui on: in the sweep thread
# else
{ " selftest " , cmd_selftest , 0 } ,
# endif
{ " correction " , cmd_correction , CMD_RUN_IN_LOAD } ,
{ " calc " , cmd_calc , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD } ,
{ " menu " , cmd_menu , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD } ,
{ " menu " , cmd_menu , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD | CMD_UI_ON } ,
{ " text " , cmd_text , CMD_RUN_IN_LOAD } ,
{ " remark " , cmd_remark , CMD_RUN_IN_LOAD } ,
# ifdef ENABLE_SD_CARD_CMD
@ -3198,6 +3238,14 @@ static int VNAShell_readLine(char *line, int max_size)
//
static void VNAShell_executeLine ( char * line )
{
# ifdef __UI_OFF__
// The UI came back without "ui on" (touch, jog, a command that needs the user): tell the PC
// here, in this thread before the reply, so it never splits other console output
if ( ui_on_notice ) {
ui_on_notice = false ;
shell_printf ( " ui on " VNA_SHELL_NEWLINE_STR ) ;
}
# endif
// Execute line
const VNAShellCommand * scp = VNAShell_parceLine ( line ) ;
if ( scp ) {
@ -3232,7 +3280,7 @@ static void VNAShell_executeLine(char *line)
}
if ( cmd_flag & CMD_WAIT_MUTEX ) {
chSysLock ( ) ;
shell_function_ ui = cmd_flag & CMD_RUN_IN_UI ;
shell_function_ flags = cmd_flag ;
shell_function = scp - > sc_function ;
operation_requested | = OP_CONSOLE ; // this will abort current sweep to give priority to the new request
chSysUnlock ( ) ;