diff --git a/picopass/scenes/picopass_scene_config.h b/picopass/scenes/picopass_scene_config.h index 6156ed689..98510c644 100644 --- a/picopass/scenes/picopass_scene_config.h +++ b/picopass/scenes/picopass_scene_config.h @@ -11,6 +11,7 @@ ADD_SCENE(picopass, delete, Delete) ADD_SCENE(picopass, delete_success, DeleteSuccess) ADD_SCENE(picopass, write_card, WriteCard) ADD_SCENE(picopass, write_card_success, WriteCardSuccess) +ADD_SCENE(picopass, write_card_failure, WriteCardFailure) ADD_SCENE(picopass, read_factory_success, ReadFactorySuccess) ADD_SCENE(picopass, write_key, WriteKey) ADD_SCENE(picopass, key_menu, KeyMenu) diff --git a/picopass/scenes/picopass_scene_start.c b/picopass/scenes/picopass_scene_start.c index cfd758ed5..d6b394b3f 100644 --- a/picopass/scenes/picopass_scene_start.c +++ b/picopass/scenes/picopass_scene_start.c @@ -58,7 +58,7 @@ bool picopass_scene_start_on_event(void* context, SceneManagerEvent event) { consumed = true; } else if(event.event == SubmenuIndexLoclass) { scene_manager_set_scene_state( - picopass->scene_manager, PicopassSceneLoclass, PicopassSceneLoclass); + picopass->scene_manager, PicopassSceneStart, PicopassSceneLoclass); scene_manager_next_scene(picopass->scene_manager, PicopassSceneLoclass); consumed = true; } diff --git a/picopass/scenes/picopass_scene_write_card.c b/picopass/scenes/picopass_scene_write_card.c index ce396fc10..3c6eae296 100644 --- a/picopass/scenes/picopass_scene_write_card.c +++ b/picopass/scenes/picopass_scene_write_card.c @@ -4,7 +4,7 @@ void picopass_write_card_worker_callback(PicopassWorkerEvent event, void* context) { UNUSED(event); Picopass* picopass = context; - view_dispatcher_send_custom_event(picopass->view_dispatcher, PicopassCustomEventWorkerExit); + view_dispatcher_send_custom_event(picopass->view_dispatcher, event); } void picopass_scene_write_card_on_enter(void* context) { @@ -33,7 +33,10 @@ bool picopass_scene_write_card_on_event(void* context, SceneManagerEvent event) bool consumed = false; if(event.type == SceneManagerEventTypeCustom) { - if(event.event == PicopassCustomEventWorkerExit) { + if(event.event == PicopassWorkerEventFail) { + scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteCardFailure); + consumed = true; + } else if(event.event == PicopassWorkerEventSuccess) { scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteCardSuccess); consumed = true; } diff --git a/picopass/scenes/picopass_scene_write_card_failure.c b/picopass/scenes/picopass_scene_write_card_failure.c new file mode 100644 index 000000000..4aae21996 --- /dev/null +++ b/picopass/scenes/picopass_scene_write_card_failure.c @@ -0,0 +1,65 @@ +#include "../picopass_i.h" +#include + +void picopass_scene_write_card_failure_widget_callback( + GuiButtonType result, + InputType type, + void* context) { + furi_assert(context); + Picopass* picopass = context; + + if(type == InputTypeShort) { + view_dispatcher_send_custom_event(picopass->view_dispatcher, result); + } +} + +void picopass_scene_write_card_failure_on_enter(void* context) { + Picopass* picopass = context; + Widget* widget = picopass->widget; + FuriString* str = furi_string_alloc_set("Write Failure!"); + + widget_add_button_element( + widget, + GuiButtonTypeLeft, + "Retry", + picopass_scene_write_card_failure_widget_callback, + picopass); + + widget_add_button_element( + widget, + GuiButtonTypeRight, + "Menu", + picopass_scene_write_card_failure_widget_callback, + picopass); + + widget_add_string_element( + widget, 64, 5, AlignCenter, AlignCenter, FontSecondary, furi_string_get_cstr(str)); + + furi_string_free(str); + + view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewWidget); +} + +bool picopass_scene_write_card_failure_on_event(void* context, SceneManagerEvent event) { + Picopass* picopass = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == GuiButtonTypeLeft) { + consumed = scene_manager_previous_scene(picopass->scene_manager); + } else if(event.event == GuiButtonTypeRight) { + // Clear device name + picopass_device_set_name(picopass->dev, ""); + consumed = scene_manager_search_and_switch_to_previous_scene( + picopass->scene_manager, PicopassSceneStart); + } + } + return consumed; +} + +void picopass_scene_write_card_failure_on_exit(void* context) { + Picopass* picopass = context; + + // Clear view + widget_reset(picopass->widget); +} diff --git a/picopass/scenes/picopass_scene_write_card_success.c b/picopass/scenes/picopass_scene_write_card_success.c index cd760272f..52b403cfe 100644 --- a/picopass/scenes/picopass_scene_write_card_success.c +++ b/picopass/scenes/picopass_scene_write_card_success.c @@ -55,8 +55,8 @@ bool picopass_scene_write_card_success_on_event(void* context, SceneManagerEvent } else if(event.event == GuiButtonTypeRight) { // Clear device name picopass_device_set_name(picopass->dev, ""); - scene_manager_next_scene(picopass->scene_manager, PicopassSceneCardMenu); - consumed = true; + consumed = scene_manager_search_and_switch_to_previous_scene( + picopass->scene_manager, PicopassSceneStart); } } return consumed;