[FL-1064] iButton CLI commands (#407)

* ibutton: add cli commands
* ibutton/scene: add cli event send
* ibutton: make separate scenes for cli commands
* ibutton/scene: add timeout to cli scenes
* ibutton: fix reading key data from cli
* cli: add cli_delete_command to API
* ibutton: delete cli command after app exit
* cli: free allocated string

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
gornekich
2021-04-14 17:24:33 +03:00
committed by GitHub
parent d1f523687e
commit cfcdff8346
10 changed files with 522 additions and 0 deletions

View File

@@ -176,6 +176,23 @@ void cli_add_command(Cli* cli, const char* name, CliCallback callback, void* con
string_clear(name_str);
}
void cli_delete_command(Cli* cli, const char* name) {
string_t name_str;
string_init_set_str(name_str, name);
string_strim(name_str);
size_t name_replace;
do {
name_replace = string_replace_str(name_str, " ", "_");
} while(name_replace != STRING_FAILURE);
furi_check(osMutexAcquire(cli->mutex, osWaitForever) == osOK);
CliCommandDict_erase(cli->commands, name_str);
furi_check(osMutexRelease(cli->mutex) == osOK);
string_clear(name_str);
}
int32_t cli_task(void* p) {
Cli* cli = cli_alloc();

View File

@@ -27,6 +27,12 @@ typedef void (*CliCallback)(string_t args, void* context);
*/
void cli_add_command(Cli* cli, const char* name, CliCallback callback, void* context);
/* Delete cli command
* @param cli - pointer to cli instance
* @param name - command name
*/
void cli_delete_command(Cli* cli, const char* name);
/* Read from terminal
* Do it only from inside of cli call.
* @param cli - Cli instance