mirror of
https://github.com/whowechina/mai_pico.git
synced 2024-11-11 23:27:10 +01:00
CLI welcome at connection
This commit is contained in:
parent
f59fecdbb3
commit
8c84a99134
@ -56,11 +56,12 @@ int cli_match_prefix(const char *str[], int num, const char *prefix)
|
||||
return match;
|
||||
}
|
||||
|
||||
const char *built_time = __DATE__ " " __TIME__;
|
||||
static void handle_help(int argc, char *argv[])
|
||||
{
|
||||
printf("%s", cli_logo);
|
||||
printf("\tSN: %016llx\n", board_id_64());
|
||||
printf("\tBuilt: %s %s\n\n", __DATE__, __TIME__);
|
||||
printf("\tBuilt: %s\n\n", built_time);
|
||||
printf("Available commands:\n");
|
||||
for (int i = 0; i < num_commands; i++) {
|
||||
printf("%*s: %s\n", max_cmd_len + 2, commands[i], helps[i]);
|
||||
@ -146,10 +147,33 @@ static void process_cmd()
|
||||
|
||||
void cli_run()
|
||||
{
|
||||
static bool was_connected = false;
|
||||
static uint64_t connect_time = 0;
|
||||
static bool welcomed = false;
|
||||
bool connected = stdio_usb_connected();
|
||||
bool just_connected = connected && !was_connected;
|
||||
was_connected = connected;
|
||||
if (!connected) {
|
||||
return;
|
||||
}
|
||||
if (just_connected) {
|
||||
connect_time = time_us_64();
|
||||
welcomed = false;
|
||||
return;
|
||||
}
|
||||
if (!welcomed && (time_us_64() - connect_time > 200000)) {
|
||||
welcomed = true;
|
||||
cmd_len = 0;
|
||||
handle_help(0, NULL);
|
||||
printf("\n%s", cli_prompt);
|
||||
}
|
||||
int c = getchar_timeout_us(0);
|
||||
if (c == EOF) {
|
||||
return;
|
||||
}
|
||||
if (c == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (c == '\b' || c == 127) { // both backspace and delete
|
||||
if (cmd_len > 0) {
|
||||
|
@ -17,4 +17,5 @@ void cli_fps_count(int core);
|
||||
int cli_extract_non_neg_int(const char *param, int len);
|
||||
int cli_match_prefix(const char *str[], int num, const char *prefix);
|
||||
|
||||
extern const char *built_time;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user