[FL-3783] Asynchronous Infrared remote manipulation (#3503)

* Introduce ConcurrentRunner, load universal and regular remotes concurrently
* Perform all lengthy operations in a ConcurrentRunner
* Fix python formatting
* Clean up code
* Add usage warning
* Remove ConcurrentRunner, use a plain FuriThread instead
* Load remotes asynchronously in RPC mode as well
* Reorder code for clarity
* Clean up, use thread return code to report errors
* Improve wording
* Fix logical error
This commit is contained in:
Georgii Surkov
2024-03-11 20:35:51 +03:00
committed by GitHub
parent adbe4d44f4
commit 022fccf0d7
13 changed files with 269 additions and 200 deletions

View File

@@ -1,5 +1,17 @@
#include "../infrared_app_i.h"
static int32_t infrared_scene_edit_move_task_callback(void* context) {
InfraredApp* infrared = context;
const bool success = infrared_remote_move_signal(
infrared->remote,
infrared->app_state.prev_button_index,
infrared->app_state.current_button_index);
view_dispatcher_send_custom_event(
infrared->view_dispatcher, InfraredCustomEventTypeTaskFinished);
return success;
}
static void infrared_scene_edit_move_button_callback(
uint32_t index_old,
uint32_t index_new,
@@ -38,25 +50,21 @@ bool infrared_scene_edit_move_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == InfraredCustomEventTypeButtonSelected) {
infrared_show_loading_popup(infrared, true);
const bool button_moved = infrared_remote_move_signal(
infrared->remote,
infrared->app_state.prev_button_index,
infrared->app_state.current_button_index);
infrared_show_loading_popup(infrared, false);
// Move the button in a separate thread
infrared_blocking_task_start(infrared, infrared_scene_edit_move_task_callback);
if(!button_moved) {
infrared_show_error_message(
infrared,
"Failed to move\n\"%s\"",
infrared_remote_get_signal_name(
infrared->remote, infrared->app_state.current_button_index));
} else if(event.event == InfraredCustomEventTypeTaskFinished) {
const bool task_success = infrared_blocking_task_finalize(infrared);
if(!task_success) {
const char* signal_name = infrared_remote_get_signal_name(
infrared->remote, infrared->app_state.current_button_index);
infrared_show_error_message(infrared, "Failed to move\n\"%s\"", signal_name);
scene_manager_search_and_switch_to_previous_scene(
infrared->scene_manager, InfraredSceneRemoteList);
}
consumed = true;
}
consumed = true;
}
return consumed;