From 61b8b889cc9f6b66c6460321beb3dc8b2acb28da Mon Sep 17 00:00:00 2001 From: Yves Quemener Date: Fri, 6 Feb 2015 16:43:57 +0900 Subject: [PATCH] Added flags to toggle visibility of the prompts on the serial line --- chibi.cpp | 12 ++++++++++++ chibi.h | 1 + src/chb_cmd.c | 21 ++++++++++++++++++--- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/chibi.cpp b/chibi.cpp index 1ee9de6..0185c5a 100644 --- a/chibi.cpp +++ b/chibi.cpp @@ -71,6 +71,18 @@ void chibiInit() chb_init(); } +/**************************************************************************/ +/*! + Initialize the command echo and prompt display settings +*/ +/**************************************************************************/ + +void chibiDisplayFlags(char prompt, char echo) +{ + cmd_prompt_flag = prompt; + cmd_echo_flag = echo; +} + /**************************************************************************/ /*! Set the short address of the wireless node. This is the 16-bit "nickname" diff --git a/chibi.h b/chibi.h index fb582ba..eb1c97e 100644 --- a/chibi.h +++ b/chibi.h @@ -53,6 +53,7 @@ #define BROADCAST_ADDR 0xFFFF void chibiInit(); +void chibiDisplayFlags(char prompt, char echo); void chibiSetShortAddr(uint16_t addr); uint16_t chibiGetShortAddr(); void chibiSetIEEEAddr(uint8_t *ieee_addr); diff --git a/src/chb_cmd.c b/src/chb_cmd.c index 6791e3d..6cb212b 100644 --- a/src/chb_cmd.c +++ b/src/chb_cmd.c @@ -61,6 +61,9 @@ const char cmd_banner[] PROGMEM = "*************** CHIBI *******************"; const char cmd_prompt[] PROGMEM = "CHIBI >> "; const char cmd_unrecog[] PROGMEM = "CHIBI: Command not recognized."; +int cmd_prompt_flag = 1; +int cmd_echo_flag = 1; + /**************************************************************************/ /*! Generate the main command prompt @@ -68,6 +71,9 @@ const char cmd_unrecog[] PROGMEM = "CHIBI: Command not recognized."; /**************************************************************************/ static void chb_cmd_display() { + if(cmd_prompt_flag==0) + return; + char buf[50]; Serial.println(); @@ -142,14 +148,20 @@ static void chb_cmd_handler() // terminate the msg and reset the msg ptr. then send // it to the handler for processing. *msg_ptr = '\0'; - Serial.print("\r\n"); + if(cmd_echo_flag==1) + { + Serial.print("\r\n"); + } chb_cmd_parse((char *)msg); msg_ptr = msg; break; case '\b': // backspace - Serial.print(c); + if(cmd_echo_flag==1) + { + Serial.print(c); + } if (msg_ptr > msg) { msg_ptr--; @@ -162,7 +174,10 @@ static void chb_cmd_handler() if ((msg_ptr - msg) < (MAX_MSG_SIZE - 1)) { // normal character entered. add it to the buffer - Serial.print(c); + if(cmd_echo_flag==1) + { + Serial.print(c); + } *msg_ptr++ = c; } break;