@@ -116,7 +116,7 @@ bool shell_init(shell_reader_t reader, shell_writer_t writer, char * msg) |
116 | 116 |
|
117 | 117 | bool shell_register(shell_program_t program, const char * string) |
118 | 118 | { |
119 | | - unsigned char i; |
| 119 | + uint8_t i; |
120 | 120 |
|
121 | 121 | for (i = 0; i < CONFIG_SHELL_MAX_COMMANDS; i++) { |
122 | 122 | if (list[i].shell_program != 0 || list[i].shell_command_string != 0) |
@@ -130,7 +130,7 @@ bool shell_register(shell_program_t program, const char * string) |
130 | 130 |
|
131 | 131 | void shell_unregister_all() |
132 | 132 | { |
133 | | - unsigned char i; |
| 133 | + uint8_t i; |
134 | 134 |
|
135 | 135 | for (i = 0; i < CONFIG_SHELL_MAX_COMMANDS; i++) { |
136 | 136 | list[i].shell_program = 0; |
@@ -140,14 +140,14 @@ void shell_unregister_all() |
140 | 140 |
|
141 | 141 | void shell_putc(char c) |
142 | 142 | { |
143 | | - if (initialized && shell_writer) |
| 143 | + if (initialized != false && shell_writer != 0) |
144 | 144 | shell_writer(c); |
145 | 145 | } |
146 | 146 |
|
147 | 147 | void shell_print(const char * string) |
148 | 148 | { |
149 | 149 | while (* string != '\0') |
150 | | - shell_writer(* string++); |
| 150 | + shell_putc(* string++); |
151 | 151 | } |
152 | 152 |
|
153 | 153 | void shell_println(const char * string) |
@@ -170,8 +170,12 @@ void shell_printf(const char * fmt, ...) |
170 | 170 |
|
171 | 171 | void shell_print_commands() |
172 | 172 | { |
173 | | - unsigned char i; |
174 | | - |
| 173 | + uint8_t i; |
| 174 | +#ifdef ARDUINO |
| 175 | + shell_println_pm(PSTR("Available Commands:")); |
| 176 | +#else |
| 177 | + shell_println((const char *) "Available Commands:"); |
| 178 | +#endif |
175 | 179 | for (i = 0; i < CONFIG_SHELL_MAX_COMMANDS; i++) { |
176 | 180 | if (list[i].shell_program != 0 || list[i].shell_command_string != 0) { |
177 | 181 | shell_println(list[i].shell_command_string); |
@@ -253,13 +257,13 @@ void shell_print_error(int error, const char * field) |
253 | 257 |
|
254 | 258 | void shell_task() |
255 | 259 | { |
256 | | - unsigned int i = 0, retval = 0; |
| 260 | + // Number of characters written to buffer (this should be static var) |
| 261 | + static uint16_t count = 0; |
| 262 | + uint8_t i = 0; |
| 263 | + bool cc = 0; |
| 264 | + int retval = 0; |
257 | 265 | int argc = 0; |
258 | 266 | char rxchar = 0; |
259 | | - char finished = 0; |
260 | | - |
261 | | - // Number of characters written to buffer (this should be static var) |
262 | | - static unsigned short count = 0; |
263 | 267 |
|
264 | 268 | if (!initialized) |
265 | 269 | return; |
@@ -273,38 +277,40 @@ void shell_task() |
273 | 277 | break; |
274 | 278 |
|
275 | 279 | case SHELL_ASCII_DEL: |
276 | | - shell_writer(SHELL_ASCII_BEL); |
| 280 | + shell_putc(SHELL_ASCII_BEL); |
277 | 281 | break; |
278 | 282 |
|
279 | 283 | case SHELL_ASCII_HT: |
280 | | - shell_writer(SHELL_ASCII_BEL); |
| 284 | + shell_putc(SHELL_ASCII_BEL); |
281 | 285 | break; |
282 | 286 |
|
283 | 287 | case SHELL_ASCII_CR: // Enter key pressed |
284 | 288 | shellbuf[count] = '\0'; |
285 | 289 | shell_println(""); |
286 | | - finished = 1; |
| 290 | + cc = true; |
287 | 291 | break; |
288 | 292 |
|
289 | 293 | case SHELL_ASCII_BS: // Backspace pressed |
290 | 294 | if (count > 0) { |
291 | 295 | count--; |
292 | | - shell_writer(SHELL_ASCII_BS); |
293 | | - shell_writer(SHELL_ASCII_SP); |
294 | | - shell_writer(SHELL_ASCII_BS); |
| 296 | + shell_putc(SHELL_ASCII_BS); |
| 297 | + shell_putc(SHELL_ASCII_SP); |
| 298 | + shell_putc(SHELL_ASCII_BS); |
295 | 299 | } else |
296 | | - shell_writer(SHELL_ASCII_BEL); |
| 300 | + shell_putc(SHELL_ASCII_BEL); |
297 | 301 | break; |
298 | 302 | default: |
299 | 303 | // Process printable characters, but ignore other ASCII chars |
300 | 304 | if (count < (CONFIG_SHELL_MAX_INPUT - 1) && rxchar >= 0x20 && rxchar < 0x7F) { |
301 | 305 | shellbuf[count] = rxchar; |
302 | | - shell_writer(rxchar); |
| 306 | + shell_putc(rxchar); |
303 | 307 | count++; |
| 308 | + } else { |
| 309 | + shell_putc(SHELL_ASCII_BEL); |
304 | 310 | } |
305 | 311 | } |
306 | 312 | // Check if a full command is available on the buffer to process |
307 | | - if (finished) { |
| 313 | + if (cc) { |
308 | 314 | argc = shell_parse(shellbuf, argv_list, CONFIG_SHELL_MAX_COMMAND_ARGS); |
309 | 315 | // Process escape sequences before giving args to command implementation |
310 | 316 | shell_process_escape(argc, argv_list); |
@@ -314,23 +320,26 @@ void shell_task() |
314 | 320 | continue; |
315 | 321 | // If string matches one on the list |
316 | 322 | #ifdef ARDUINO |
317 | | - if (!strcmp_P(argv_list[0], list[i].shell_command_string)) { |
| 323 | + if (!strcmp_P(argv_list[0], list[i].shell_command_string)) |
318 | 324 | #else |
319 | | - if (!strcmp(argv_list[0], list[i].shell_command_string)) { |
| 325 | + if (!strcmp(argv_list[0], list[i].shell_command_string)) |
320 | 326 | #endif |
| 327 | + { |
321 | 328 | // Run the appropriate function |
322 | 329 | retval = list[i].shell_program(argc, argv_list); |
323 | | - finished = 0; |
| 330 | + cc = false; |
324 | 331 | } |
325 | 332 | } |
326 | | - if (finished != 0 && count != 0) // If no command found and buffer not empty |
| 333 | + // If no command found and buffer not empty |
| 334 | + if (cc != false && count != 0) { |
327 | 335 | #ifdef ARDUINO |
328 | 336 | shell_println_pm(PSTR("Command NOT found.")); |
329 | 337 | #else |
330 | 338 | shell_println((const char *) "Command NOT found."); // Print not found!! |
331 | 339 | #endif |
332 | | - |
| 340 | + } |
333 | 341 | count = 0; |
| 342 | + cc = false; |
334 | 343 | shell_println(""); |
335 | 344 | shell_prompt(); |
336 | 345 | } |
@@ -346,7 +355,7 @@ void shell_print_pm(const char * string) |
346 | 355 | c = pgm_read_byte(string++); |
347 | 356 | if (!c) |
348 | 357 | break; |
349 | | - shell_writer(c); |
| 358 | + shell_putc(c); |
350 | 359 | } while (1); |
351 | 360 | } |
352 | 361 |
|
@@ -471,7 +480,6 @@ static void shell_prompt() |
471 | 480 | * Shell formatted print support * |
472 | 481 | *-------------------------------------------------------------*/ |
473 | 482 | #ifdef SHELL_PRINTF_LONG_SUPPORT |
474 | | - |
475 | 483 | static void uli2a(unsigned long int num, unsigned int base, int uc, char * bf) |
476 | 484 | { |
477 | 485 | int n = 0; |
@@ -561,9 +569,9 @@ static void putchw(int n, char z, char* bf) |
561 | 569 | while (*p++ && n > 0) |
562 | 570 | n--; |
563 | 571 | while (n-- > 0) |
564 | | - shell_writer(fc); |
| 572 | + shell_putc(fc); |
565 | 573 | while ((ch = *bf++)) |
566 | | - shell_writer(ch); |
| 574 | + shell_putc(ch); |
567 | 575 | } |
568 | 576 |
|
569 | 577 | static void shell_format(const char * fmt, va_list va) |
@@ -574,7 +582,7 @@ static void shell_format(const char * fmt, va_list va) |
574 | 582 |
|
575 | 583 | while ((ch = *(fmt++))) { |
576 | 584 | if (ch != '%') |
577 | | - shell_writer(ch); |
| 585 | + shell_putc(ch); |
578 | 586 | else { |
579 | 587 | char lz = 0; |
580 | 588 | #ifdef PRINTF_LONG_SUPPORT |
@@ -630,13 +638,13 @@ static void shell_format(const char * fmt, va_list va) |
630 | 638 | putchw(w, lz, bf); |
631 | 639 | break; |
632 | 640 | case 'c': |
633 | | - shell_writer((char) (va_arg(va, int))); |
| 641 | + shell_putc((char) (va_arg(va, int))); |
634 | 642 | break; |
635 | 643 | case 's': |
636 | 644 | putchw(w, 0, va_arg(va, char*)); |
637 | 645 | break; |
638 | 646 | case '%': |
639 | | - shell_writer(ch); |
| 647 | + shell_putc(ch); |
640 | 648 | default: |
641 | 649 | break; |
642 | 650 | } |
|