mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-29 06:24:45 -07:00
Merge remote-tracking branch 'upstream/dev' into mfkeyfour
This commit is contained in:
@@ -15,3 +15,18 @@ void cli_print_usage(const char* cmd, const char* usage, const char* arg) {
|
||||
|
||||
printf("%s: illegal option -- %s\r\nusage: %s %s", cmd, arg, cmd, usage);
|
||||
}
|
||||
|
||||
bool cli_sleep(PipeSide* side, uint32_t duration_in_ms) {
|
||||
uint32_t passed_time = 0;
|
||||
bool is_interrupted = false;
|
||||
|
||||
do {
|
||||
uint32_t left_time = duration_in_ms - passed_time;
|
||||
uint32_t check_interval = left_time >= 100 ? 100 : left_time;
|
||||
furi_delay_ms(check_interval);
|
||||
passed_time += check_interval;
|
||||
is_interrupted = cli_is_pipe_broken_or_is_etx_next_char(side);
|
||||
} while(!is_interrupted && passed_time < duration_in_ms);
|
||||
|
||||
return !is_interrupted;
|
||||
}
|
||||
|
||||
@@ -29,14 +29,14 @@ typedef enum {
|
||||
CliCommandFlagExternal = (1 << 4), /**< The command comes from a .fal file */
|
||||
} CliCommandFlag;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief CLI command execution callback pointer
|
||||
*
|
||||
*
|
||||
* This callback will be called from a separate thread spawned just for your
|
||||
* command. The pipe will be installed as the thread's stdio, so you can use
|
||||
* `printf`, `getchar` and other standard functions to communicate with the
|
||||
* user.
|
||||
*
|
||||
*
|
||||
* @param [in] pipe Pipe that can be used to send and receive data. If
|
||||
* `CliCommandFlagDontAttachStdio` was not set, you can
|
||||
* also use standard C functions (printf, getc, etc.) to
|
||||
@@ -64,7 +64,7 @@ typedef struct {
|
||||
|
||||
/**
|
||||
* @brief Detects if Ctrl+C has been pressed or session has been terminated
|
||||
*
|
||||
*
|
||||
* @param [in] side Pointer to pipe side given to the command thread
|
||||
* @warning This function also assumes that the pipe is installed as the
|
||||
* thread's stdio
|
||||
@@ -80,6 +80,21 @@ bool cli_is_pipe_broken_or_is_etx_next_char(PipeSide* side);
|
||||
*/
|
||||
void cli_print_usage(const char* cmd, const char* usage, const char* arg);
|
||||
|
||||
/**
|
||||
* @brief Pause for a specified duration or until Ctrl+C is pressed or the
|
||||
* session is terminated.
|
||||
*
|
||||
* @param [in] side Pointer to pipe side given to the command thread.
|
||||
* @param [in] duration_in_ms Duration of sleep in milliseconds.
|
||||
* @return `true` if the sleep completed without interruption.
|
||||
* @return `false` if interrupted.
|
||||
*
|
||||
* @warning This function also assumes that the pipe is installed as the
|
||||
* thread's stdio.
|
||||
* @warning This function will consume 0 or 1 bytes from the pipe.
|
||||
*/
|
||||
bool cli_sleep(PipeSide* side, uint32_t duration_in_ms);
|
||||
|
||||
#define CLI_COMMAND_INTERFACE(name, execute_callback, flags, stack_depth, app_id) \
|
||||
static const CliCommandDescriptor cli_##name##_desc = { \
|
||||
#name, \
|
||||
|
||||
@@ -136,9 +136,9 @@ void cli_registry_reload_external_commands(
|
||||
FURI_LOG_T(TAG, "Plugin: %s", plugin_filename);
|
||||
furi_string_set_str(plugin_name, plugin_filename);
|
||||
|
||||
furi_check(furi_string_end_with_str(plugin_name, ".fal"));
|
||||
if(!furi_string_end_with_str(plugin_name, ".fal")) continue;
|
||||
furi_string_replace_all_str(plugin_name, ".fal", "");
|
||||
furi_check(furi_string_start_with_str(plugin_name, config->fal_prefix));
|
||||
if(!furi_string_start_with_str(plugin_name, config->fal_prefix)) continue;
|
||||
furi_string_replace_at(plugin_name, 0, strlen(config->fal_prefix), "");
|
||||
|
||||
CliRegistryCommand command = {
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
|
||||
#define TAG "CliShell"
|
||||
|
||||
#define ANSI_TIMEOUT_MS 10
|
||||
#define ANSI_TIMEOUT_MS 10
|
||||
#define TRANSIENT_SESSION_WINDOW_MS 100
|
||||
|
||||
typedef enum {
|
||||
CliShellComponentCompletions,
|
||||
@@ -415,10 +416,15 @@ static void cli_shell_deinit(CliShell* shell) {
|
||||
static int32_t cli_shell_thread(void* context) {
|
||||
CliShell* shell = context;
|
||||
|
||||
// Sometimes, the other side closes the pipe even before our thread is started. Although the
|
||||
// rest of the code will eventually find this out if this check is removed, there's no point in
|
||||
// wasting time.
|
||||
if(pipe_state(shell->pipe) == PipeStateBroken) return 0;
|
||||
// Sometimes, the other side (e.g. qFlipper) closes the pipe even before our thread is started.
|
||||
// Although the rest of the code will eventually find this out if this check is removed,
|
||||
// there's no point in wasting time. This gives qFlipper a chance to quickly close and re-open
|
||||
// the session.
|
||||
const size_t delay_step = 10;
|
||||
for(size_t i = 0; i < TRANSIENT_SESSION_WINDOW_MS / delay_step; i++) {
|
||||
furi_delay_ms(delay_step);
|
||||
if(pipe_state(shell->pipe) == PipeStateBroken) return 0;
|
||||
}
|
||||
|
||||
cli_shell_init(shell);
|
||||
FURI_LOG_D(TAG, "Started");
|
||||
@@ -436,7 +442,6 @@ static int32_t cli_shell_thread(void* context) {
|
||||
// ==========
|
||||
// Public API
|
||||
// ==========
|
||||
|
||||
CliShell* cli_shell_alloc(
|
||||
CliShellMotd motd,
|
||||
void* context,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "cli_shell_completions.h"
|
||||
|
||||
ARRAY_DEF(CommandCompletions, FuriString*, FURI_STRING_OPLIST); // -V524
|
||||
ARRAY_DEF(CommandCompletions, FuriString*, FURI_STRING_OPLIST); // -V524 //-V658
|
||||
#define M_OPL_CommandCompletions_t() ARRAY_OPLIST(CommandCompletions)
|
||||
|
||||
struct CliShellCompletions {
|
||||
|
||||
Reference in New Issue
Block a user