mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-20 04:54:45 -07:00
[FL-3890] Infrared button operation fails now shows more informative messages (#3859)
* Error codes enum added * Adjusted signal api to return error codes instead of bool * Remote api adjusted to work with error codes * Brute force logic adjusted to work with error codes * Other application functions adjust to work with error codes * All task callbacks now return ErrorCode through int32t, which belongs to thread * All scenes now work with error codes * More api functions now return error code * Now signal names are buffered and restored in case of error. * New error code enumeration added. Now least significant byte is left for the button index * Some macro to simplify error setup and error check * Error code checks replaced by macro * Different message is now shown when move failed * Comments updated * Fixed error check * Fixed navigation issue while openning broken files from Favorites * Now search by index also returns index in addition to error code * Remote loading logic adjusted * New error codes added and numbers adjusted * New error message when loading library file instead of signal one * Some more remote loading logic adjusted * New error message on rename fail * Grammar mistake fix * Function signature changed * Function usage adjusted according to new signature Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -34,12 +34,12 @@ static void infrared_scene_universal_common_hide_popup(InfraredApp* infrared) {
|
||||
|
||||
static int32_t infrared_scene_universal_common_task_callback(void* context) {
|
||||
InfraredApp* infrared = context;
|
||||
const bool success = infrared_brute_force_calculate_messages(infrared->brute_force);
|
||||
const InfraredErrorCode error = infrared_brute_force_calculate_messages(infrared->brute_force);
|
||||
view_dispatcher_send_custom_event(
|
||||
infrared->view_dispatcher,
|
||||
infrared_custom_event_pack(InfraredCustomEventTypeTaskFinished, 0));
|
||||
|
||||
return success;
|
||||
return error;
|
||||
}
|
||||
|
||||
void infrared_scene_universal_common_on_enter(void* context) {
|
||||
@@ -93,9 +93,9 @@ bool infrared_scene_universal_common_on_event(void* context, SceneManagerEvent e
|
||||
scene_manager_next_scene(scene_manager, InfraredSceneErrorDatabases);
|
||||
}
|
||||
} else if(event_type == InfraredCustomEventTypeTaskFinished) {
|
||||
const bool task_success = infrared_blocking_task_finalize(infrared);
|
||||
const InfraredErrorCode task_error = infrared_blocking_task_finalize(infrared);
|
||||
|
||||
if(!task_success) {
|
||||
if(INFRARED_ERROR_PRESENT(task_error)) {
|
||||
scene_manager_next_scene(infrared->scene_manager, InfraredSceneErrorDatabases);
|
||||
} else {
|
||||
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewStack);
|
||||
|
||||
@@ -11,12 +11,12 @@ static int32_t infrared_scene_edit_delete_task_callback(void* context) {
|
||||
InfraredAppState* app_state = &infrared->app_state;
|
||||
const InfraredEditTarget edit_target = app_state->edit_target;
|
||||
|
||||
bool success;
|
||||
InfraredErrorCode error = InfraredErrorCodeNone;
|
||||
if(edit_target == InfraredEditTargetButton) {
|
||||
furi_assert(app_state->current_button_index != InfraredButtonIndexNone);
|
||||
success = infrared_remote_delete_signal(infrared->remote, app_state->current_button_index);
|
||||
error = infrared_remote_delete_signal(infrared->remote, app_state->current_button_index);
|
||||
} else if(edit_target == InfraredEditTargetRemote) {
|
||||
success = infrared_remote_remove(infrared->remote);
|
||||
error = infrared_remote_remove(infrared->remote);
|
||||
} else {
|
||||
furi_crash();
|
||||
}
|
||||
@@ -24,7 +24,7 @@ static int32_t infrared_scene_edit_delete_task_callback(void* context) {
|
||||
view_dispatcher_send_custom_event(
|
||||
infrared->view_dispatcher, InfraredCustomEventTypeTaskFinished);
|
||||
|
||||
return success;
|
||||
return error;
|
||||
}
|
||||
|
||||
void infrared_scene_edit_delete_on_enter(void* context) {
|
||||
@@ -39,11 +39,15 @@ void infrared_scene_edit_delete_on_enter(void* context) {
|
||||
const int32_t current_button_index = infrared->app_state.current_button_index;
|
||||
furi_check(current_button_index != InfraredButtonIndexNone);
|
||||
|
||||
if(!infrared_remote_load_signal(remote, infrared->current_signal, current_button_index)) {
|
||||
InfraredErrorCode error =
|
||||
infrared_remote_load_signal(remote, infrared->current_signal, current_button_index);
|
||||
if(INFRARED_ERROR_PRESENT(error)) {
|
||||
const char* format =
|
||||
(INFRARED_ERROR_CHECK(error, InfraredErrorCodeSignalRawUnableToReadTooLongData)) ?
|
||||
"Failed to delete\n\"%s\" is too long.\nTry to edit file from pc" :
|
||||
"Failed to load\n\"%s\"";
|
||||
infrared_show_error_message(
|
||||
infrared,
|
||||
"Failed to load\n\"%s\"",
|
||||
infrared_remote_get_signal_name(remote, current_button_index));
|
||||
infrared, format, infrared_remote_get_signal_name(remote, current_button_index));
|
||||
scene_manager_previous_scene(infrared->scene_manager);
|
||||
return;
|
||||
}
|
||||
@@ -107,18 +111,30 @@ bool infrared_scene_edit_delete_on_event(void* context, SceneManagerEvent event)
|
||||
infrared_blocking_task_start(infrared, infrared_scene_edit_delete_task_callback);
|
||||
|
||||
} else if(event.event == InfraredCustomEventTypeTaskFinished) {
|
||||
const bool task_success = infrared_blocking_task_finalize(infrared);
|
||||
const InfraredErrorCode task_error = infrared_blocking_task_finalize(infrared);
|
||||
|
||||
InfraredAppState* app_state = &infrared->app_state;
|
||||
|
||||
if(task_success) {
|
||||
if(!INFRARED_ERROR_PRESENT(task_error)) {
|
||||
scene_manager_next_scene(scene_manager, InfraredSceneEditDeleteDone);
|
||||
} else {
|
||||
const char* edit_target_text =
|
||||
app_state->edit_target == InfraredEditTargetButton ? "button" : "file";
|
||||
infrared_show_error_message(infrared, "Failed to\ndelete %s", edit_target_text);
|
||||
if(INFRARED_ERROR_CHECK(
|
||||
task_error, InfraredErrorCodeSignalRawUnableToReadTooLongData)) {
|
||||
const uint8_t index = INFRARED_ERROR_GET_INDEX(task_error);
|
||||
const char* format =
|
||||
"Failed to delete\n\"%s\" is too long.\nTry to edit file from pc";
|
||||
infrared_show_error_message(
|
||||
infrared,
|
||||
format,
|
||||
infrared_remote_get_signal_name(infrared->remote, index));
|
||||
} else {
|
||||
const char* edit_target_text =
|
||||
app_state->edit_target == InfraredEditTargetButton ? "button" : "file";
|
||||
infrared_show_error_message(
|
||||
infrared, "Failed to\ndelete %s", edit_target_text);
|
||||
}
|
||||
|
||||
const uint32_t possible_scenes[] = {InfraredSceneRemoteList, InfraredSceneStart};
|
||||
const uint32_t possible_scenes[] = {InfraredSceneRemoteList, InfraredSceneRemote};
|
||||
scene_manager_search_and_switch_to_previous_scene_one_of(
|
||||
scene_manager, possible_scenes, COUNT_OF(possible_scenes));
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
static int32_t infrared_scene_edit_move_task_callback(void* context) {
|
||||
InfraredApp* infrared = context;
|
||||
const bool success = infrared_remote_move_signal(
|
||||
const InfraredErrorCode error = 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;
|
||||
return error;
|
||||
}
|
||||
|
||||
static void infrared_scene_edit_move_button_callback(
|
||||
@@ -51,14 +51,26 @@ bool infrared_scene_edit_move_on_event(void* context, SceneManagerEvent event) {
|
||||
infrared_blocking_task_start(infrared, infrared_scene_edit_move_task_callback);
|
||||
|
||||
} else if(event.event == InfraredCustomEventTypeTaskFinished) {
|
||||
const bool task_success = infrared_blocking_task_finalize(infrared);
|
||||
const InfraredErrorCode task_error = 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);
|
||||
if(INFRARED_ERROR_PRESENT(task_error)) {
|
||||
const char* format = "Failed to move\n\"%s\"";
|
||||
uint8_t signal_index = infrared->app_state.prev_button_index;
|
||||
|
||||
if(INFRARED_ERROR_CHECK(
|
||||
task_error, InfraredErrorCodeSignalRawUnableToReadTooLongData)) {
|
||||
signal_index = INFRARED_ERROR_GET_INDEX(task_error);
|
||||
format = "Failed to move\n\"%s\" is too long.\nTry to edit file from pc";
|
||||
}
|
||||
furi_assert(format);
|
||||
|
||||
const char* signal_name =
|
||||
infrared_remote_get_signal_name(infrared->remote, signal_index);
|
||||
infrared_show_error_message(infrared, format, signal_name);
|
||||
|
||||
const uint32_t possible_scenes[] = {InfraredSceneRemoteList, InfraredSceneRemote};
|
||||
scene_manager_search_and_switch_to_previous_scene_one_of(
|
||||
infrared->scene_manager, possible_scenes, COUNT_OF(possible_scenes));
|
||||
} else {
|
||||
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewMove);
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ static int32_t infrared_scene_edit_rename_task_callback(void* context) {
|
||||
InfraredAppState* app_state = &infrared->app_state;
|
||||
const InfraredEditTarget edit_target = app_state->edit_target;
|
||||
|
||||
bool success;
|
||||
InfraredErrorCode error = InfraredErrorCodeNone;
|
||||
if(edit_target == InfraredEditTargetButton) {
|
||||
furi_assert(app_state->current_button_index != InfraredButtonIndexNone);
|
||||
success = infrared_remote_rename_signal(
|
||||
error = infrared_remote_rename_signal(
|
||||
infrared->remote, app_state->current_button_index, infrared->text_store[0]);
|
||||
} else if(edit_target == InfraredEditTargetRemote) {
|
||||
success = infrared_rename_current_remote(infrared, infrared->text_store[0]);
|
||||
error = infrared_rename_current_remote(infrared, infrared->text_store[0]);
|
||||
} else {
|
||||
furi_crash();
|
||||
}
|
||||
@@ -22,7 +22,7 @@ static int32_t infrared_scene_edit_rename_task_callback(void* context) {
|
||||
view_dispatcher_send_custom_event(
|
||||
infrared->view_dispatcher, InfraredCustomEventTypeTaskFinished);
|
||||
|
||||
return success;
|
||||
return error;
|
||||
}
|
||||
|
||||
void infrared_scene_edit_rename_on_enter(void* context) {
|
||||
@@ -89,17 +89,30 @@ bool infrared_scene_edit_rename_on_event(void* context, SceneManagerEvent event)
|
||||
infrared_blocking_task_start(infrared, infrared_scene_edit_rename_task_callback);
|
||||
|
||||
} else if(event.event == InfraredCustomEventTypeTaskFinished) {
|
||||
const bool task_success = infrared_blocking_task_finalize(infrared);
|
||||
const InfraredErrorCode task_error = infrared_blocking_task_finalize(infrared);
|
||||
InfraredAppState* app_state = &infrared->app_state;
|
||||
|
||||
if(task_success) {
|
||||
if(!INFRARED_ERROR_PRESENT(task_error)) {
|
||||
scene_manager_next_scene(scene_manager, InfraredSceneEditRenameDone);
|
||||
} else {
|
||||
const char* edit_target_text =
|
||||
app_state->edit_target == InfraredEditTargetButton ? "button" : "file";
|
||||
infrared_show_error_message(infrared, "Failed to\nrename %s", edit_target_text);
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
scene_manager, InfraredSceneRemoteList);
|
||||
bool long_signal = INFRARED_ERROR_CHECK(
|
||||
task_error, InfraredErrorCodeSignalRawUnableToReadTooLongData);
|
||||
|
||||
const char* format = "Failed to rename\n%s";
|
||||
const char* target = infrared->app_state.edit_target == InfraredEditTargetButton ?
|
||||
"button" :
|
||||
"file";
|
||||
if(long_signal) {
|
||||
format = "Failed to rename\n\"%s\" is too long.\nTry to edit file from pc";
|
||||
target = infrared_remote_get_signal_name(
|
||||
infrared->remote, INFRARED_ERROR_GET_INDEX(task_error));
|
||||
}
|
||||
|
||||
infrared_show_error_message(infrared, format, target);
|
||||
|
||||
const uint32_t possible_scenes[] = {InfraredSceneRemoteList, InfraredSceneRemote};
|
||||
scene_manager_search_and_switch_to_previous_scene_one_of(
|
||||
scene_manager, possible_scenes, COUNT_OF(possible_scenes));
|
||||
}
|
||||
|
||||
app_state->current_button_index = InfraredButtonIndexNone;
|
||||
|
||||
@@ -41,12 +41,12 @@ bool infrared_scene_learn_enter_name_on_event(void* context, SceneManagerEvent e
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == InfraredCustomEventTypeTextEditDone) {
|
||||
const char* signal_name = infrared->text_store[0];
|
||||
const bool success =
|
||||
const InfraredErrorCode error =
|
||||
infrared->app_state.is_learning_new_remote ?
|
||||
infrared_add_remote_with_button(infrared, signal_name, signal) :
|
||||
infrared_remote_append_signal(infrared->remote, signal, signal_name);
|
||||
|
||||
if(success) {
|
||||
if(!INFRARED_ERROR_PRESENT(error)) {
|
||||
scene_manager_next_scene(scene_manager, InfraredSceneLearnDone);
|
||||
dolphin_deed(DolphinDeedIrSave);
|
||||
} else {
|
||||
|
||||
@@ -85,7 +85,8 @@ bool infrared_scene_remote_on_event(void* context, SceneManagerEvent event) {
|
||||
|
||||
if(custom_type == InfraredCustomEventTypeTransmitStarted) {
|
||||
furi_assert(button_index >= 0);
|
||||
if(!infrared_tx_start_button_index(infrared, button_index)) {
|
||||
InfraredErrorCode error = infrared_tx_start_button_index(infrared, button_index);
|
||||
if(INFRARED_ERROR_PRESENT(error)) {
|
||||
infrared_show_error_message(
|
||||
infrared,
|
||||
"Failed to load\n\"%s\"",
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
static int32_t infrared_scene_remote_list_task_callback(void* context) {
|
||||
InfraredApp* infrared = context;
|
||||
const bool success =
|
||||
const InfraredErrorCode error =
|
||||
infrared_remote_load(infrared->remote, furi_string_get_cstr(infrared->file_path));
|
||||
view_dispatcher_send_custom_event(
|
||||
infrared->view_dispatcher, InfraredCustomEventTypeTaskFinished);
|
||||
return success;
|
||||
return error;
|
||||
}
|
||||
|
||||
static void infrared_scene_remote_list_select_and_load(InfraredApp* infrared) {
|
||||
@@ -38,13 +38,19 @@ bool infrared_scene_remote_list_on_event(void* context, SceneManagerEvent event)
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == InfraredCustomEventTypeTaskFinished) {
|
||||
const bool task_success = infrared_blocking_task_finalize(infrared);
|
||||
const InfraredErrorCode task_error = infrared_blocking_task_finalize(infrared);
|
||||
|
||||
if(task_success) {
|
||||
if(!INFRARED_ERROR_PRESENT(task_error)) {
|
||||
scene_manager_next_scene(infrared->scene_manager, InfraredSceneRemote);
|
||||
} else {
|
||||
bool wrong_file_type =
|
||||
INFRARED_ERROR_CHECK(task_error, InfraredErrorCodeWrongFileType);
|
||||
const char* format = wrong_file_type ?
|
||||
"Library file\n\"%s\" can't be openned as a remote" :
|
||||
"Failed to load\n\"%s\"";
|
||||
|
||||
infrared_show_error_message(
|
||||
infrared, "Failed to load\n\"%s\"", furi_string_get_cstr(infrared->file_path));
|
||||
infrared, format, furi_string_get_cstr(infrared->file_path));
|
||||
infrared_scene_remote_list_select_and_load(infrared);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ typedef enum {
|
||||
|
||||
static int32_t infrared_scene_rpc_task_callback(void* context) {
|
||||
InfraredApp* infrared = context;
|
||||
const bool success =
|
||||
const InfraredErrorCode error =
|
||||
infrared_remote_load(infrared->remote, furi_string_get_cstr(infrared->file_path));
|
||||
view_dispatcher_send_custom_event(
|
||||
infrared->view_dispatcher, InfraredCustomEventTypeTaskFinished);
|
||||
return success;
|
||||
return error;
|
||||
}
|
||||
|
||||
void infrared_scene_rpc_on_enter(void* context) {
|
||||
@@ -57,8 +57,11 @@ bool infrared_scene_rpc_on_event(void* context, SceneManagerEvent event) {
|
||||
}
|
||||
|
||||
} else if(event.event == InfraredCustomEventTypeTaskFinished) {
|
||||
const bool task_success = infrared_blocking_task_finalize(infrared);
|
||||
if(task_success) {
|
||||
const InfraredErrorCode task_error = infrared_blocking_task_finalize(infrared);
|
||||
|
||||
if(!INFRARED_ERROR_PRESENT(task_error)) {
|
||||
const char* remote_name = infrared_remote_get_name(infrared->remote);
|
||||
infrared_text_store_set(infrared, 0, "loaded\n%s", remote_name);
|
||||
scene_manager_set_scene_state(
|
||||
infrared->scene_manager, InfraredSceneRpc, InfraredRpcStateLoaded);
|
||||
} else {
|
||||
@@ -71,7 +74,7 @@ bool infrared_scene_rpc_on_event(void* context, SceneManagerEvent event) {
|
||||
|
||||
furi_string_free(str);
|
||||
}
|
||||
rpc_system_app_confirm(infrared->rpc_ctx, task_success);
|
||||
rpc_system_app_confirm(infrared->rpc_ctx, !INFRARED_ERROR_PRESENT(task_error));
|
||||
} else if(
|
||||
event.event == InfraredCustomEventTypeRpcButtonPressName ||
|
||||
event.event == InfraredCustomEventTypeRpcButtonPressIndex) {
|
||||
@@ -90,7 +93,9 @@ bool infrared_scene_rpc_on_event(void* context, SceneManagerEvent event) {
|
||||
TAG, "Sending signal with index \"%ld\"", app_state->current_button_index);
|
||||
}
|
||||
if(infrared->app_state.current_button_index != InfraredButtonIndexNone) {
|
||||
if(infrared_tx_start_button_index(infrared, app_state->current_button_index)) {
|
||||
InfraredErrorCode error =
|
||||
infrared_tx_start_button_index(infrared, app_state->current_button_index);
|
||||
if(!INFRARED_ERROR_PRESENT(error)) {
|
||||
const char* remote_name = infrared_remote_get_name(infrared->remote);
|
||||
infrared_text_store_set(infrared, 0, "emulating\n%s", remote_name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user