CLI welcome at connection

This commit is contained in:
whowechina 2024-06-18 11:32:05 +08:00
parent f59fecdbb3
commit 8c84a99134
2 changed files with 46 additions and 21 deletions

View File

@ -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) {

View File

@ -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