diff --git a/extras/uart_repl/uart_repl.c b/extras/uart_repl/uart_repl.c index 7e9a585..3a8e6c9 100644 --- a/extras/uart_repl/uart_repl.c +++ b/extras/uart_repl/uart_repl.c @@ -380,8 +380,10 @@ top: #undef STATE +// local variable that holds the status +struct serial_terminal_status cc; + void uart_repl_task(void *pvParameters) { - struct serial_terminal_status cc; memset(&cc, 0, sizeof(cc)); cc.lineCb = pvParameters; MainStateMachine(&cc); @@ -393,3 +395,42 @@ void uart_repl_init(uart_repl_handler line_cb) { xTaskCreate(uart_repl_task, "uart_repl", 256, (void *)line_cb, 10, NULL); } +void error(const char* format, ...) { + va_list argptr; + va_start(argptr, format); + + // TODO preempt the console stuff + taskENTER_CRITICAL(); + printf("\x1b[1;31mERROR:\x1b[1m "); + vprintf(format, argptr); + printf("\x1b[0m"); + fflush(stdout); + taskEXIT_CRITICAL(); + va_end(argptr); +} + +// TODO some day replace this with a callback or something, so that it is not +// named statically +void response(const char* format, ...) { + va_list argptr; + va_start(argptr, format); + + // TODO preempt the console stuff + vprintf(format, argptr); + fflush(stdout); + va_end(argptr); + + // TODO track if the last character was a newline; if not, make sure + // prompt() handles it by adding a newline +} + +void debug(const char* format, ...) { + va_list argptr; + va_start(argptr, format); + + // TODO preempt the console stuff + vprintf(format, argptr); + fflush(stdout); + va_end(argptr); +} + diff --git a/extras/uart_repl/uart_repl.h b/extras/uart_repl/uart_repl.h index 3ad7b6f..9d0448c 100644 --- a/extras/uart_repl/uart_repl.h +++ b/extras/uart_repl/uart_repl.h @@ -1,6 +1,7 @@ #ifndef _SWC_UART_REPL_ #define _SWC_UART_REPL_ #include /* size_t */ +#include /* varargs */ #if 0 @@ -16,6 +17,11 @@ enum uart_repl_special_key { typedef void (*uart_repl_handler)(char const *); +/* various helpers to allow us to gracefully show output */ +void error(const char *, ...); +void debug(const char *, ...); +void response(const char *, ...); + struct serial_terminal_status { char line[80]; unsigned int lineCursorPosition; // this is the index of the next character to be written