uart_commands.c: Backspace/Delete capability
This commit is contained in:
parent
cc060261d4
commit
b9471a6637
|
@ -29,12 +29,13 @@ volatile unsigned char mode;
|
||||||
char const UART_STR_NOTIMPL[] PROGMEM = "\r\nnot implemented";
|
char const UART_STR_NOTIMPL[] PROGMEM = "\r\nnot implemented";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
char const UART_STR_BACKSPACE[] PROGMEM = "\033[D \033[D";
|
||||||
char const UART_STR_PROMPT[] PROGMEM = "\r\n> ";
|
char const UART_STR_PROMPT[] PROGMEM = "\r\n> ";
|
||||||
char const UART_STR_ERROR[] PROGMEM = "\r\ntransmission error";
|
char const UART_STR_ERROR[] PROGMEM = "\r\ntransmission error";
|
||||||
char const UART_STR_UNKNOWN[] PROGMEM = "\r\nunknown command";
|
char const UART_STR_UNKNOWN[] PROGMEM = "\r\nunknown command";
|
||||||
char const UART_STR_TOOLONG[] PROGMEM = "\r\ncommand to long";
|
char const UART_STR_TOOLONG[] PROGMEM = "\r\ncommand to long";
|
||||||
char const UART_STR_HELP[] PROGMEM = "\r\nallowed commands: "
|
char const UART_STR_HELP[] PROGMEM = "\r\nallowed commands: erase help "
|
||||||
"erase help msg next prev reset scroll";
|
"msg next prev reset scroll";
|
||||||
|
|
||||||
char const UART_CMD_ERASE[] PROGMEM = "erase";
|
char const UART_CMD_ERASE[] PROGMEM = "erase";
|
||||||
char const UART_CMD_HELP[] PROGMEM = "help";
|
char const UART_CMD_HELP[] PROGMEM = "help";
|
||||||
|
@ -164,14 +165,29 @@ static bool uartcmd_read_until_enter(void) {
|
||||||
|
|
||||||
switch (uart_result & 0xFF00u) {
|
switch (uart_result & 0xFF00u) {
|
||||||
case 0:
|
case 0:
|
||||||
if (!(uart_result == '\r' || uart_result == '\n')) {
|
switch ((char)uart_result) {
|
||||||
g_rx_buffer[g_rx_index++] = uart_result;
|
case '\r': // carriage return
|
||||||
uart_putc(uart_result);
|
case '\n': // line feed
|
||||||
} else {
|
if (g_rx_index != 0) {
|
||||||
g_rx_buffer[g_rx_index++] = 0;
|
g_rx_buffer[g_rx_index++] = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case '\b': // BS
|
||||||
|
case '\177': // DEL
|
||||||
|
if (g_rx_index != 0) {
|
||||||
|
g_rx_buffer[--g_rx_index] = 0;
|
||||||
|
uart_puts_p(UART_STR_BACKSPACE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 27: // ignore Esc
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
g_rx_buffer[g_rx_index++] = uart_result;
|
||||||
|
uart_putc(uart_result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case UART_FRAME_ERROR:
|
case UART_FRAME_ERROR:
|
||||||
case UART_OVERRUN_ERROR:
|
case UART_OVERRUN_ERROR:
|
||||||
|
@ -202,7 +218,7 @@ static bool uartcmd_read_until_enter(void) {
|
||||||
*/
|
*/
|
||||||
void uartcmd_process(void) {
|
void uartcmd_process(void) {
|
||||||
if (uartcmd_processing_allowed() && uartcmd_read_until_enter()) {
|
if (uartcmd_processing_allowed() && uartcmd_read_until_enter()) {
|
||||||
if (!strncmp_P(g_rx_buffer, UART_CMD_ERASE, 5)) {
|
if (!strncmp_P(g_rx_buffer, UART_CMD_ERASE, UART_BUFFER_SIZE)) {
|
||||||
uartcmd_erase_eeprom();
|
uartcmd_erase_eeprom();
|
||||||
} else if (!strncmp_P(g_rx_buffer, UART_CMD_HELP, UART_BUFFER_SIZE)) {
|
} else if (!strncmp_P(g_rx_buffer, UART_CMD_HELP, UART_BUFFER_SIZE)) {
|
||||||
uart_puts_p(UART_STR_HELP);
|
uart_puts_p(UART_STR_HELP);
|
||||||
|
|
Loading…
Reference in New Issue