From 625ab3cc5625fdc2dbba12c0733304198c0afee9 Mon Sep 17 00:00:00 2001 From: UncleRus Date: Sat, 2 Dec 2017 13:59:11 +0500 Subject: [PATCH] Fix #472 --- examples/sysparam_editor/FreeRTOSConfig.h | 12 ++++++++++++ examples/sysparam_editor/sysparam_editor.c | 16 +++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 examples/sysparam_editor/FreeRTOSConfig.h diff --git a/examples/sysparam_editor/FreeRTOSConfig.h b/examples/sysparam_editor/FreeRTOSConfig.h new file mode 100644 index 0000000..0a9a6b7 --- /dev/null +++ b/examples/sysparam_editor/FreeRTOSConfig.h @@ -0,0 +1,12 @@ +/* Terminal FreeRTOSConfig overrides. + + This is intended as an example of overriding some of the default FreeRTOSConfig settings, + which are otherwise found in FreeRTOS/Source/include/FreeRTOSConfig.h +*/ + +/* The serial driver depends on counting semaphores */ +#define configUSE_COUNTING_SEMAPHORES 1 + +/* Use the defaults for everything else */ +#include_next + diff --git a/examples/sysparam_editor/sysparam_editor.c b/examples/sysparam_editor/sysparam_editor.c index 29bf78e..c3828d3 100644 --- a/examples/sysparam_editor/sysparam_editor.c +++ b/examples/sysparam_editor/sysparam_editor.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "espressif/esp_common.h" @@ -41,12 +42,12 @@ void usage(void) { size_t tty_readline(char *buffer, size_t buf_size, bool echo) { size_t i = 0; - int c; + char c; while (true) { - c = getchar(); + read(0, (void *)&c, 1); if (c == '\r' || c == '\n') { - if (echo) putchar('\n'); + if (echo) printf("\n"); break; } else if (c == '\b' || c == 0x7f) { if (i) { @@ -56,13 +57,15 @@ size_t tty_readline(char *buffer, size_t buf_size, bool echo) { } else if (c < 0x20) { /* Ignore other control characters */ } else if (i >= buf_size - 1) { - if (echo) putchar('\a'); + if (echo) printf("\a"); } else { buffer[i++] = c; - if (echo) putchar(c); + if (echo) printf("%c", c); } + fflush(stdout); } + fflush(stdout); buffer[i] = 0; return i; } @@ -175,8 +178,10 @@ void sysparam_editor_task(void *pvParameters) { num_sectors = DEFAULT_SYSPARAM_SECTORS; base_addr = sdk_flashchip.chip_size - (5 + num_sectors) * sdk_flashchip.sector_size; } + fflush(stdout); while (true) { printf("==> "); + fflush(stdout); len = tty_readline(cmd_buffer, CMD_BUF_SIZE, echo); status = 0; if (!len) continue; @@ -239,6 +244,7 @@ void sysparam_editor_task(void *pvParameters) { if (status != SYSPARAM_OK) { printf("! Operation returned status: %d (%s)\n", status, status_messages[status - status_base]); } + fflush(stdout); } }