passy_scene_read_error.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "../passy_i.h"
  2. #include <dolphin/dolphin.h>
  3. #define TAG "PassySceneReadCardSuccess"
  4. void passy_scene_read_error_widget_callback(GuiButtonType result, InputType type, void* context) {
  5. furi_assert(context);
  6. Passy* passy = context;
  7. if(type == InputTypeShort) {
  8. view_dispatcher_send_custom_event(passy->view_dispatcher, result);
  9. }
  10. }
  11. void passy_scene_read_error_on_enter(void* context) {
  12. Passy* passy = context;
  13. Widget* widget = passy->widget;
  14. FuriString* primary_str = furi_string_alloc_set("Read Error");
  15. FuriString* secondary_str = furi_string_alloc();
  16. // Send notification
  17. notification_message(passy->notifications, &sequence_error);
  18. if(passy->last_sw == 0x6a82) {
  19. furi_string_printf(secondary_str, "File not found\nTry again?");
  20. } else if(passy->last_sw == 0x9000) {
  21. furi_string_printf(secondary_str, "Try again?");
  22. } else {
  23. furi_string_printf(secondary_str, "%04x\nTry again?", passy->last_sw);
  24. }
  25. widget_add_button_element(
  26. widget, GuiButtonTypeLeft, "Retry", passy_scene_read_error_widget_callback, passy);
  27. widget_add_string_element(
  28. widget, 64, 5, AlignCenter, AlignCenter, FontPrimary, furi_string_get_cstr(primary_str));
  29. widget_add_string_element(
  30. widget,
  31. 64,
  32. 20,
  33. AlignCenter,
  34. AlignCenter,
  35. FontSecondary,
  36. furi_string_get_cstr(secondary_str));
  37. furi_string_free(primary_str);
  38. furi_string_free(secondary_str);
  39. view_dispatcher_switch_to_view(passy->view_dispatcher, PassyViewWidget);
  40. }
  41. bool passy_scene_read_error_on_event(void* context, SceneManagerEvent event) {
  42. Passy* passy = context;
  43. bool consumed = false;
  44. if(event.type == SceneManagerEventTypeCustom) {
  45. if(event.event == GuiButtonTypeLeft) {
  46. consumed = scene_manager_previous_scene(passy->scene_manager);
  47. }
  48. } else if(event.type == SceneManagerEventTypeBack) {
  49. scene_manager_search_and_switch_to_previous_scene(
  50. passy->scene_manager, PassySceneMainMenu);
  51. consumed = true;
  52. }
  53. return consumed;
  54. }
  55. void passy_scene_read_error_on_exit(void* context) {
  56. Passy* passy = context;
  57. // Clear view
  58. widget_reset(passy->widget);
  59. }