Cli: insomnia safe flags and better insomnia handling in cli (#587)

This commit is contained in:
あく 2021-07-18 22:08:26 +03:00 committed by GitHub
parent ddfdbc0530
commit b6f6378628
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 20 deletions

View File

@ -142,6 +142,37 @@ static void cli_normalize_line(Cli* cli) {
cli->cursor_position = string_size(cli->line); cli->cursor_position = string_size(cli->line);
} }
static void cli_execute_command(Cli* cli, CliCommand* command, string_t args) {
if(!(command->flags & CliCommandFlagInsomniaSafe)) {
api_hal_power_insomnia_enter();
}
// Ensure that we running alone
if(!(command->flags & CliCommandFlagParallelSafe)) {
Loader* loader = furi_record_open("loader");
bool safety_lock = loader_lock(loader);
if(safety_lock) {
// Execute command
command->callback(cli, args, command->context);
loader_unlock(loader);
// Clear line
cli_reset(cli);
} else {
printf("Other application is running, close it first");
}
furi_record_close("loader");
} else {
// Execute command
command->callback(cli, args, command->context);
// Clear line
cli_reset(cli);
}
if(!(command->flags & CliCommandFlagInsomniaSafe)) {
api_hal_power_insomnia_exit();
}
}
static void cli_handle_enter(Cli* cli) { static void cli_handle_enter(Cli* cli) {
cli_normalize_line(cli); cli_normalize_line(cli);
@ -171,26 +202,7 @@ static void cli_handle_enter(Cli* cli) {
CliCommand* cli_command = CliCommandTree_get(cli->commands, command); CliCommand* cli_command = CliCommandTree_get(cli->commands, command);
if(cli_command) { if(cli_command) {
cli_nl(cli); cli_nl(cli);
// Ensure that we running alone cli_execute_command(cli, cli_command, args);
if(!(cli_command->flags & CliCommandFlagParallelSafe)) {
Loader* loader = furi_record_open("loader");
bool safety_lock = loader_lock(loader);
if(safety_lock) {
// Execute command
cli_command->callback(cli, args, cli_command->context);
loader_unlock(loader);
// Clear line
cli_reset(cli);
} else {
printf("Other application is running, close it first");
}
furi_record_close("loader");
} else {
// Execute command
cli_command->callback(cli, args, cli_command->context);
// Clear line
cli_reset(cli);
}
} else { } else {
cli_nl(cli); cli_nl(cli);
printf( printf(

View File

@ -24,6 +24,7 @@ typedef enum {
CliCommandFlagDefault = 0, /** Default, loader lock is used */ CliCommandFlagDefault = 0, /** Default, loader lock is used */
CliCommandFlagParallelSafe = CliCommandFlagParallelSafe =
(1 << 0), /** Safe to run in parallel with other apps, loader lock is not used */ (1 << 0), /** Safe to run in parallel with other apps, loader lock is not used */
CliCommandFlagInsomniaSafe = (1 << 1), /** Safe to run with insomnia mode on */
} CliCommandFlag; } CliCommandFlag;
/* Cli type /* Cli type