diff --git a/include/shell.h b/include/shell.h index 8ad2e522bdc3d56f511161e845038188802356e4..2b7be9c1a8f670b903b44d6ad46ef8875ba1da4e 100644 --- a/include/shell.h +++ b/include/shell.h @@ -3,9 +3,9 @@ #define UI_SHELL_MODE 0 #define UI_GUI_MODE 1 -#define UI_STAT_MODE 2 extern int wrc_ui_mode; +extern int wrc_stat_running; const char *fromhex(const char *hex, int *v); const char *fromdec(const char *dec, int *v); diff --git a/shell/cmd_stat.c b/shell/cmd_stat.c index 4c895cdd1afab0d93ecfd03d7f03d23892e441d1..691b082e4224da1539c66c3437dbfb83d5de3464 100644 --- a/shell/cmd_stat.c +++ b/shell/cmd_stat.c @@ -2,15 +2,29 @@ #include "endpoint.h" #include <string.h> #include <wrc.h> +#include <errno.h> + +int wrc_stat_running; static int cmd_stat(const char *args[]) { + /* no arguments: invert */ + if (!args[0]) { + wrc_stat_running = !wrc_stat_running; + return 0; + } + + /* arguments: bts, on, off */ if (!strcasecmp(args[0], "bts")) mprintf("%d ps\n", ep_get_bitslide()); + else if (!strcasecmp(args[0], "on")) + wrc_stat_running = 1; + else if (!strcasecmp(args[0], "off")) + wrc_stat_running = 0; else - wrc_ui_mode = UI_STAT_MODE; - + return -EINVAL; return 0; + } DEFINE_WRC_COMMAND(stat) = { diff --git a/wrc_main.c b/wrc_main.c index d826099eb6295eb2e2ca40dba5f1b34129b73f51..fd28e3e07427627feb2b022de94798500ba3b5c9 100644 --- a/wrc_main.c +++ b/wrc_main.c @@ -148,15 +148,12 @@ static void ui_update(void) shell_init(); wrc_ui_mode = UI_SHELL_MODE; } - } else if (wrc_ui_mode == UI_STAT_MODE) { - wrc_log_stats(); - if (uart_read_byte() == 27 || wrc_ui_refperiod == 0) { - shell_init(); - wrc_ui_mode = UI_SHELL_MODE; - } - } else + } else { shell_interactive(); - + } + /* Stats is asynchronous now. It's not a different mode, but a flag */ + if (wrc_stat_running) + wrc_log_stats(); } /* initialize functions to be called after reset in check_reset function */