From b6f63786284d55bd220162b5795b1604b21d16cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=82=E3=81=8F?= Date: Sun, 18 Jul 2021 22:08:26 +0300 Subject: [PATCH] Cli: insomnia safe flags and better insomnia handling in cli (#587) --- applications/cli/cli.c | 52 ++++++++++++++++++++++++++---------------- applications/cli/cli.h | 1 + 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/applications/cli/cli.c b/applications/cli/cli.c index 87ed8d10..fa424729 100644 --- a/applications/cli/cli.c +++ b/applications/cli/cli.c @@ -142,6 +142,37 @@ static void cli_normalize_line(Cli* cli) { 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) { cli_normalize_line(cli); @@ -171,26 +202,7 @@ static void cli_handle_enter(Cli* cli) { CliCommand* cli_command = CliCommandTree_get(cli->commands, command); if(cli_command) { cli_nl(cli); - // Ensure that we running alone - 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); - } + cli_execute_command(cli, cli_command, args); } else { cli_nl(cli); printf( diff --git a/applications/cli/cli.h b/applications/cli/cli.h index 5957cc37..c7322fdb 100644 --- a/applications/cli/cli.h +++ b/applications/cli/cli.h @@ -24,6 +24,7 @@ typedef enum { CliCommandFlagDefault = 0, /** Default, loader lock is used */ CliCommandFlagParallelSafe = (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; /* Cli type