busvoodoo: add quit mode command
This commit is contained in:
parent
8b7b262065
commit
e1259c6cdc
|
@ -38,6 +38,9 @@
|
|||
#include "busvoodoo_global.h" // BusVoodoo definitions
|
||||
#include "busvoodoo_hiz.h" // BusVoodoo HiZ mode utilities
|
||||
|
||||
/** current BusVoodoo mode */
|
||||
static struct busvoodoo_mode_t* busvoodoo_mode = NULL;
|
||||
|
||||
size_t putc(char c)
|
||||
{
|
||||
size_t length = 0; // number of characters printed
|
||||
|
@ -81,6 +84,10 @@ bool wait_space(void)
|
|||
* @param[in] argument no argument required
|
||||
*/
|
||||
static void command_help(void* argument);
|
||||
/** command to quit current BusVoodoo mode
|
||||
* @param[in] argument no argument required
|
||||
*/
|
||||
static void command_quit(void* argument);
|
||||
/** command to switch LED
|
||||
* @param[in] argument on, off, toggle to switch LED, or NULL to display LED status
|
||||
*/
|
||||
|
@ -108,6 +115,14 @@ static const struct menu_command_t menu_commands[] = {
|
|||
NULL,
|
||||
&command_help,
|
||||
},
|
||||
{
|
||||
'q',
|
||||
"quit",
|
||||
"quit current mode",
|
||||
MENU_ARGUMENT_NONE,
|
||||
NULL,
|
||||
&command_quit,
|
||||
},
|
||||
{
|
||||
'l',
|
||||
"led",
|
||||
|
@ -148,7 +163,16 @@ static void command_help(void* argument)
|
|||
printf("available commands:\n");
|
||||
menu_print_commands(menu_commands, LENGTH(menu_commands)); // print global commands
|
||||
menu_print_commands(busvoodoo_global_commands, LENGTH(busvoodoo_global_commands)); // print BusVoodoo global commands
|
||||
menu_print_commands(busvoodoo_hiz_mode.commands, busvoodoo_hiz_mode.commands_nb); // print BusVoodoo HiZ commands
|
||||
menu_print_commands(busvoodoo_mode->commands, busvoodoo_mode->commands_nb); // print BusVoodoo mode commands
|
||||
}
|
||||
|
||||
static void command_quit(void* argument)
|
||||
{
|
||||
(void)argument; // we won't use the argument
|
||||
(*busvoodoo_mode->exit)(); // exit current mode
|
||||
busvoodoo_mode = &busvoodoo_hiz_mode; // set HiZ mode as current mode
|
||||
(*busvoodoo_mode->setup)(&terminal_prefix, NULL); // setup BusVoodoo mode
|
||||
terminal_send(0); // update the terminal prompt
|
||||
}
|
||||
|
||||
static void command_led(void* argument)
|
||||
|
@ -210,7 +234,7 @@ static void process_command(char* str)
|
|||
return;
|
||||
}
|
||||
// handle user input
|
||||
if (!menu_handle_command(str, busvoodoo_hiz_mode.commands, busvoodoo_hiz_mode.commands_nb)) {
|
||||
if (!menu_handle_command(str, busvoodoo_mode->commands, busvoodoo_mode->commands_nb)) {
|
||||
if (!menu_handle_command(str, busvoodoo_global_commands, LENGTH(busvoodoo_global_commands))) {
|
||||
if (!menu_handle_command(str, menu_commands, LENGTH(menu_commands))) {
|
||||
printf("command not recognized. enter help to list commands\n");
|
||||
|
@ -248,13 +272,16 @@ void main(void)
|
|||
}
|
||||
printf(" version)\n");
|
||||
|
||||
// setup default HiZ mode
|
||||
(*busvoodoo_hiz_mode.setup)(&terminal_prefix, NULL);
|
||||
|
||||
// setup terminal
|
||||
terminal_prefix = "BV: "; // set default prefix
|
||||
terminal_process = &process_command; // set central function to process commands
|
||||
terminal_setup(); // start terminal
|
||||
|
||||
// setup default HiZ mode
|
||||
busvoodoo_mode = &busvoodoo_hiz_mode; // set HiZ mode as current mode
|
||||
(*busvoodoo_mode->setup)(&terminal_prefix, NULL); // setup BusVoodoo mode
|
||||
terminal_send(0); // update the terminal prompt
|
||||
|
||||
// main loop
|
||||
bool action = false; // if an action has been performed don't go to sleep
|
||||
button_flag = false; // reset button flag
|
||||
|
@ -274,7 +301,11 @@ void main(void)
|
|||
while (char_flag) { // user data received
|
||||
char_flag = false; // reset flag
|
||||
action = true; // action has been performed
|
||||
terminal_send(c); // send received character to terminal
|
||||
if (0x04==c) { // CTRL+D is used to quit the mode
|
||||
command_quit(NULL); // quit current mode
|
||||
} else {
|
||||
terminal_send(c); // send received character to terminal
|
||||
}
|
||||
}
|
||||
while (button_flag) { // user pressed button
|
||||
action = true; // action has been performed
|
||||
|
|
|
@ -693,7 +693,7 @@ static const struct menu_command_t busvoodoo_hiz_commands[] = {
|
|||
},
|
||||
};
|
||||
|
||||
const struct busvoodoo_mode_t busvoodoo_hiz_mode = {
|
||||
struct busvoodoo_mode_t busvoodoo_hiz_mode = {
|
||||
&busvoodoo_hiz_setup,
|
||||
busvoodoo_hiz_commands,
|
||||
LENGTH(busvoodoo_hiz_commands),
|
||||
|
|
|
@ -19,4 +19,4 @@
|
|||
*/
|
||||
|
||||
/** HiZ mode interface definition */
|
||||
extern const struct busvoodoo_mode_t busvoodoo_hiz_mode;
|
||||
extern struct busvoodoo_mode_t busvoodoo_hiz_mode;
|
||||
|
|
Loading…
Reference in New Issue