application: use terminal prompt
This commit is contained in:
parent
f759017192
commit
c3a5aa6540
|
@ -43,6 +43,7 @@
|
|||
#include "print.h" // printing utilities
|
||||
#include "uart.h" // USART utilities
|
||||
#include "usb_cdcacm.h" // USB CDC ACM utilities
|
||||
#include "terminal.h" // handle the terminal interface
|
||||
|
||||
//#include "rs485.h" // RS-485 utilities
|
||||
//#include "rs232.h" // RS-232 utilities
|
||||
|
@ -137,26 +138,18 @@ static bool busvoodoo_full = false;
|
|||
size_t putc(char c)
|
||||
{
|
||||
size_t length = 0; // number of characters printed
|
||||
static char newline = 0; // to remember on which character we sent the newline
|
||||
if (0==c) {
|
||||
length = 0; // don't print string termination character
|
||||
} else if ('\r' == c || '\n' == c) { // send CR+LF newline for most carriage return and line feed combination
|
||||
if (0==newline || c==newline) { // send newline only if not already send (and only once on \r\n or \n\r)
|
||||
static char last_c = 0; // to remember on which character we last sent
|
||||
if ('\n' == c) { // send carriage return (CR) + line feed (LF) newline for each LF
|
||||
if ('\r' != last_c) { // CR has not already been sent
|
||||
uart_putchar_nonblocking('\r'); // send CR over USART
|
||||
usb_cdcacm_putchar('\r'); // send CR over USB
|
||||
uart_putchar_nonblocking('\n'); // send LF over USART
|
||||
usb_cdcacm_putchar('\n'); // send LF over USB
|
||||
length += 2; // remember we printed 2 characters
|
||||
newline = c; // remember on which character we sent the newline
|
||||
} else {
|
||||
length = 0; // the \r or \n of \n\r or \r\n has already been printed
|
||||
length++; // remember we printed 1 character
|
||||
}
|
||||
} else {
|
||||
uart_putchar_nonblocking(c); // send byte over USART
|
||||
usb_cdcacm_putchar(c); // send byte over USB
|
||||
newline = 0; // clear new line
|
||||
length++; // remember we printed 1 character
|
||||
}
|
||||
uart_putchar_nonblocking(c); // send byte over USART
|
||||
usb_cdcacm_putchar(c); // send byte over USB
|
||||
length++; // remember we printed 1 character
|
||||
last_c = c; // remember last character
|
||||
return length; // return number of characters printed
|
||||
}
|
||||
|
||||
|
@ -868,16 +861,15 @@ error:
|
|||
return to_return;
|
||||
}
|
||||
|
||||
/** user input command */
|
||||
static char command[32] = {0};
|
||||
/** user input command index */
|
||||
uint8_t command_i = 0;
|
||||
|
||||
/** process user command
|
||||
* @param[in] str user command string (\0 ended)
|
||||
*/
|
||||
static void process_command(char* str)
|
||||
{
|
||||
// don't handle empty lines
|
||||
if (!str || 0==strlen(str)) {
|
||||
return;
|
||||
}
|
||||
// split command
|
||||
const char* delimiter = " ";
|
||||
char* word = strtok(str,delimiter);
|
||||
|
@ -886,7 +878,6 @@ static void process_command(char* str)
|
|||
}
|
||||
// parse command
|
||||
if (0==strcmp(word,"h") || 0==strcmp(word,"help") || 0==strcmp(word,"?")) {
|
||||
printf("unit ID: 0x%08x%08x%08x\n", DESIG_UNIQUE_ID0, DESIG_UNIQUE_ID1, DESIG_UNIQUE_ID2);
|
||||
printf("available commands:\n");
|
||||
printf("led [on|off|toggle]\n");
|
||||
} else if (0==strcmp(word,"l") || 0==strcmp(word,"led")) {
|
||||
|
@ -1069,7 +1060,8 @@ void main(void)
|
|||
const uint8_t oled_data[] = {0x40, 0, 254, 254, 0, 0, 0, 0, 0, 0, 254, 254, 0, 0, 224, 240, 56, 28, 14, 14, 28, 56, 240, 224, 0, 0, 254, 254, 134, 134, 134, 134, 134, 206, 252, 120, 0, 0, 6, 6, 6, 6, 254, 254, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 6, 254, 254, 6, 6, 6, 6, 0, 0, 30, 62, 112, 224, 192, 192, 224, 112, 62, 30, 0, 0, 254, 254, 134, 134, 134, 134, 134, 206, 252, 120, 0, 0, 30, 62, 112, 224, 192, 192, 224, 112, 62, 30, 0, 0, 31, 63, 112, 96, 96, 96, 96, 112, 63, 31, 0, 0, 127, 127, 6, 6, 6, 6, 6, 6, 127, 127, 0, 0, 127, 127, 1, 3, 7, 15, 29, 57, 112, 96, 0, 0, 0, 0, 0, 0, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 127, 0, 0, 0, 0, 0, 0, 120, 124, 14, 7, 3, 3, 7, 14, 124, 120, 0, 0, 127, 127, 1, 3, 7, 15, 29, 57, 112, 96, 0, 0, 120, 124, 14, 7, 3, 3, 7, 14, 124, 120, 0, 255, 255, 3, 3, 3, 3, 11, 19, 35, 67, 131, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 131, 67, 35, 19, 11, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 132, 72, 48, 48, 72, 132, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 255, 17, 17, 49, 209, 14, 0, 0, 1, 1, 1, 255, 1, 1, 1, 0, 142, 17, 17, 33, 33, 198, 0, 0, 0, 0, 0, 0, 255, 17, 17, 49, 209, 14, 0, 0, 3, 204, 48, 48, 204, 3, 0, 0, 0, 0, 0, 0, 134, 1, 17, 17, 17, 238, 0, 0, 7, 56, 192, 0, 192, 56, 7, 0, 134, 1, 17, 17, 17, 238, 0, 0, 254, 1, 1, 33, 33, 230, 0, 0, 255, 6, 24, 96, 128, 255, 0, 0, 255, 1, 1, 1, 2, 252, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 64, 32, 16, 8, 4, 2, 1, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1, 2, 2, 2, 2, 1, 0, 0, 1, 2, 2, 2, 1, 3, 0, 0, 3, 0, 0, 0, 1, 3, 0, 0, 3, 2, 2, 2, 1, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 2, 4, 8, 16, 32, 64, 128, 0, 0, 0, 0, 0, 0, 128, 64, 32, 16, 8, 4, 2, 0, 0, 0, 128, 64, 64, 64, 64, 128, 0, 0, 64, 64, 64, 192, 64, 64, 64, 0, 128, 64, 64, 64, 64, 128, 0, 0, 0, 0, 0, 0, 64, 64, 64, 192, 64, 64, 64, 0, 192, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 64, 64, 64, 64, 64, 0, 0, 192, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 64, 33, 18, 12, 12, 18, 33, 64, 128, 0, 0, 0, 0, 0, 0, 0, 0, 127, 128, 128, 128, 128, 97, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 99, 132, 132, 136, 136, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 192, 51, 12, 12, 51, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 195, 36, 24, 24, 36, 195, 0, 0, 1, 14, 48, 192, 48, 14, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 71, 132, 132, 132, 132, 120, 0, 0, 1, 14, 48, 192, 48, 14, 1, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 192, 192, 192, 192, 208, 200, 196, 194, 193, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 193, 194, 196, 200, 208, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 255};
|
||||
i2c_master_write(0x3c, oled_data, LENGTH(oled_data), NULL, 0);
|
||||
*/
|
||||
|
||||
|
||||
if (false) {
|
||||
// perform tests
|
||||
printf("performing self-test, please follow instructions\n");
|
||||
if (!test_self()) { // perform self-test
|
||||
|
@ -1086,6 +1078,7 @@ void main(void)
|
|||
led_blink(0, 1.0); // show blue OK LED
|
||||
printf("pin test succeeded\n"); // notify user
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
printf("testing RS-485 port\n");
|
||||
|
@ -1115,6 +1108,9 @@ void main(void)
|
|||
|
||||
// main loop
|
||||
printf("command input: ready\n");
|
||||
terminal_prefix = "BV: "; // set terminal prefix
|
||||
terminal_process = &process_command;
|
||||
terminal_setup(); // start terminal
|
||||
bool action = false; // if an action has been performed don't go to sleep
|
||||
button_flag = false; // reset button flag
|
||||
char c = '\0'; // to store received character
|
||||
|
@ -1136,19 +1132,8 @@ void main(void)
|
|||
while (char_flag) { // user data received
|
||||
char_flag = false; // reset flag
|
||||
action = true; // action has been performed
|
||||
printf("%c",c); // echo receive character
|
||||
if (c=='\r' || c=='\n') { // end of command received
|
||||
if (command_i>0) { // there is a command to process
|
||||
command[command_i] = 0; // end string
|
||||
command_i = 0; // prepare for next command
|
||||
process_command(command); // process user command
|
||||
}
|
||||
} else { // user command input
|
||||
command[command_i] = c; // save command input
|
||||
if (command_i<LENGTH(command)-2) { // verify if there is place to save next character
|
||||
command_i++; // save next character
|
||||
}
|
||||
}
|
||||
// printf("%02x\n", c);
|
||||
terminal_send(c); // send received character to terminal
|
||||
}
|
||||
while (button_flag) { // user pressed button
|
||||
action = true; // action has been performed
|
||||
|
|
Loading…
Reference in New Issue