mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 04:34:43 +04:00
RC fixes (#4192)
* cli_shell: fix FL-3983 * fix formatting and submodules * loader: fix FL-3986 * fix submodules --------- Co-authored-by: hedger <hedger@users.noreply.github.com>
This commit is contained in:
@@ -31,10 +31,18 @@ CliShellKeyComboSet* component_key_combo_sets[] = {
|
||||
static_assert(CliShellComponentMAX == COUNT_OF(component_key_combo_sets));
|
||||
|
||||
typedef enum {
|
||||
CliShellStorageEventMount,
|
||||
CliShellStorageEventUnmount,
|
||||
CliShellStorageEventMount = (1 << 0),
|
||||
CliShellStorageEventUnmount = (1 << 1),
|
||||
} CliShellStorageEvent;
|
||||
|
||||
#define CliShellStorageEventAll (CliShellStorageEventMount | CliShellStorageEventUnmount)
|
||||
|
||||
typedef struct {
|
||||
Storage* storage;
|
||||
FuriPubSubSubscription* subscription;
|
||||
FuriEventFlag* event_flag;
|
||||
} CliShellStorage;
|
||||
|
||||
struct CliShell {
|
||||
// Set and freed by external thread
|
||||
CliShellMotd motd;
|
||||
@@ -49,11 +57,7 @@ struct CliShell {
|
||||
FuriEventLoop* event_loop;
|
||||
CliAnsiParser* ansi_parser;
|
||||
FuriEventLoopTimer* ansi_parsing_timer;
|
||||
|
||||
Storage* storage;
|
||||
FuriPubSubSubscription* storage_subscription;
|
||||
FuriMessageQueue* storage_event_queue;
|
||||
|
||||
CliShellStorage storage;
|
||||
void* components[CliShellComponentMAX];
|
||||
};
|
||||
|
||||
@@ -256,31 +260,32 @@ const char* cli_shell_get_prompt(CliShell* cli_shell) {
|
||||
// Event handlers
|
||||
// ==============
|
||||
|
||||
static void cli_shell_signal_storage_event(CliShell* cli_shell, CliShellStorageEvent event) {
|
||||
furi_check(!(furi_event_flag_set(cli_shell->storage.event_flag, event) & FuriFlagError));
|
||||
}
|
||||
|
||||
static void cli_shell_storage_event(const void* message, void* context) {
|
||||
CliShell* cli_shell = context;
|
||||
const StorageEvent* event = message;
|
||||
|
||||
if(event->type == StorageEventTypeCardMount) {
|
||||
CliShellStorageEvent cli_event = CliShellStorageEventMount;
|
||||
furi_check(
|
||||
furi_message_queue_put(cli_shell->storage_event_queue, &cli_event, 0) == FuriStatusOk);
|
||||
cli_shell_signal_storage_event(cli_shell, CliShellStorageEventMount);
|
||||
} else if(event->type == StorageEventTypeCardUnmount) {
|
||||
CliShellStorageEvent cli_event = CliShellStorageEventUnmount;
|
||||
furi_check(
|
||||
furi_message_queue_put(cli_shell->storage_event_queue, &cli_event, 0) == FuriStatusOk);
|
||||
cli_shell_signal_storage_event(cli_shell, CliShellStorageEventUnmount);
|
||||
}
|
||||
}
|
||||
|
||||
static void cli_shell_storage_internal_event(FuriEventLoopObject* object, void* context) {
|
||||
CliShell* cli_shell = context;
|
||||
FuriMessageQueue* queue = object;
|
||||
CliShellStorageEvent event;
|
||||
furi_check(furi_message_queue_get(queue, &event, 0) == FuriStatusOk);
|
||||
FuriEventFlag* event_flag = object;
|
||||
CliShellStorageEvent event =
|
||||
furi_event_flag_wait(event_flag, FuriFlagWaitAll, FuriFlagWaitAny, 0);
|
||||
furi_check(!(event & FuriFlagError));
|
||||
|
||||
if(event == CliShellStorageEventMount) {
|
||||
cli_registry_reload_external_commands(cli_shell->registry, cli_shell->ext_config);
|
||||
} else if(event == CliShellStorageEventUnmount) {
|
||||
if(event & CliShellStorageEventUnmount) {
|
||||
cli_registry_remove_external_commands(cli_shell->registry);
|
||||
} else if(event & CliShellStorageEventMount) {
|
||||
cli_registry_reload_external_commands(cli_shell->registry, cli_shell->ext_config);
|
||||
} else {
|
||||
furi_crash();
|
||||
}
|
||||
@@ -377,25 +382,26 @@ static void cli_shell_init(CliShell* shell) {
|
||||
shell->ansi_parsing_timer = furi_event_loop_timer_alloc(
|
||||
shell->event_loop, cli_shell_timer_expired, FuriEventLoopTimerTypeOnce, shell);
|
||||
|
||||
shell->storage_event_queue = furi_message_queue_alloc(1, sizeof(CliShellStorageEvent));
|
||||
furi_event_loop_subscribe_message_queue(
|
||||
shell->storage.event_flag = furi_event_flag_alloc();
|
||||
furi_event_loop_subscribe_event_flag(
|
||||
shell->event_loop,
|
||||
shell->storage_event_queue,
|
||||
shell->storage.event_flag,
|
||||
FuriEventLoopEventIn,
|
||||
cli_shell_storage_internal_event,
|
||||
shell);
|
||||
shell->storage = furi_record_open(RECORD_STORAGE);
|
||||
shell->storage_subscription =
|
||||
furi_pubsub_subscribe(storage_get_pubsub(shell->storage), cli_shell_storage_event, shell);
|
||||
shell->storage.storage = furi_record_open(RECORD_STORAGE);
|
||||
shell->storage.subscription = furi_pubsub_subscribe(
|
||||
storage_get_pubsub(shell->storage.storage), cli_shell_storage_event, shell);
|
||||
|
||||
cli_shell_install_pipe(shell);
|
||||
}
|
||||
|
||||
static void cli_shell_deinit(CliShell* shell) {
|
||||
furi_pubsub_unsubscribe(storage_get_pubsub(shell->storage), shell->storage_subscription);
|
||||
furi_pubsub_unsubscribe(
|
||||
storage_get_pubsub(shell->storage.storage), shell->storage.subscription);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
furi_event_loop_unsubscribe(shell->event_loop, shell->storage_event_queue);
|
||||
furi_message_queue_free(shell->storage_event_queue);
|
||||
furi_event_loop_unsubscribe(shell->event_loop, shell->storage.event_flag);
|
||||
furi_event_flag_free(shell->storage.event_flag);
|
||||
|
||||
cli_shell_completions_free(shell->components[CliShellComponentCompletions]);
|
||||
cli_shell_line_free(shell->components[CliShellComponentLine]);
|
||||
|
||||
Reference in New Issue
Block a user