From 37d943da645f754f0770ff6c5b547d7d397cf56d Mon Sep 17 00:00:00 2001 From: Olivier Matz Date: Thu, 18 Sep 2014 19:46:28 +0200 Subject: [PATCH] imuboard/cmdline: read chars per burst this enhance reactivity when we are logging on sdcard --- imuboard/cmdline.c | 42 +++++++++++++++++++++--------------------- imuboard/cmdline.h | 2 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/imuboard/cmdline.c b/imuboard/cmdline.c index 91360a9..4eee061 100644 --- a/imuboard/cmdline.c +++ b/imuboard/cmdline.c @@ -192,34 +192,34 @@ static void flush_logs_cb(struct callout_mgr *cm, struct callout *tim, } -int cmdline_poll(void) +void cmdline_poll(void) { const char *history, *buffer; int8_t ret, same = 0; int16_t c; - c = cmdline_dev_recv(NULL); - if (c < 0) - return -1; - - ret = rdline_char_in(&imuboard.rdl, c); - if (ret == 1) { - buffer = rdline_get_buffer(&imuboard.rdl); - history = rdline_get_history_item(&imuboard.rdl, 0); - if (history) { - same = !memcmp(buffer, history, strlen(history)) && - buffer[strlen(history)] == '\n'; + while (1) { + c = cmdline_dev_recv(NULL); + if (c < 0) + break; + + ret = rdline_char_in(&imuboard.rdl, c); + if (ret == 1) { + buffer = rdline_get_buffer(&imuboard.rdl); + history = rdline_get_history_item(&imuboard.rdl, 0); + if (history) { + same = !memcmp(buffer, history, strlen(history)) && + buffer[strlen(history)] == '\n'; + } + else + same = 0; + if (strlen(buffer) > 1 && !same) + rdline_add_history(&imuboard.rdl, buffer); + + if (imuboard.rdl.status != RDLINE_STOPPED) + rdline_newline(&imuboard.rdl, imuboard.prompt); } - else - same = 0; - if (strlen(buffer) > 1 && !same) - rdline_add_history(&imuboard.rdl, buffer); - - if (imuboard.rdl.status != RDLINE_STOPPED) - rdline_newline(&imuboard.rdl, imuboard.prompt); } - - return 0; } void cmdline_init(void) diff --git a/imuboard/cmdline.h b/imuboard/cmdline.h index 034244a..0adfa0e 100644 --- a/imuboard/cmdline.h +++ b/imuboard/cmdline.h @@ -35,7 +35,7 @@ void emergency(char c); void mylog(struct error * e, ...); /* poll cmdline */ -int cmdline_poll(void); +void cmdline_poll(void); int cmdline_dev_send(char c, FILE* f); int cmdline_dev_recv(FILE* f); -- 2.39.5