passy_scene_read_error.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 {
  21. furi_string_printf(secondary_str, "%04x\nTry again?", passy->last_sw);
  22. }
  23. widget_add_button_element(
  24. widget, GuiButtonTypeLeft, "Retry", passy_scene_read_error_widget_callback, passy);
  25. widget_add_string_element(
  26. widget, 64, 5, AlignCenter, AlignCenter, FontPrimary, furi_string_get_cstr(primary_str));
  27. widget_add_string_element(
  28. widget,
  29. 64,
  30. 20,
  31. AlignCenter,
  32. AlignCenter,
  33. FontSecondary,
  34. furi_string_get_cstr(secondary_str));
  35. furi_string_free(primary_str);
  36. furi_string_free(secondary_str);
  37. view_dispatcher_switch_to_view(passy->view_dispatcher, PassyViewWidget);
  38. }
  39. bool passy_scene_read_error_on_event(void* context, SceneManagerEvent event) {
  40. Passy* passy = context;
  41. bool consumed = false;
  42. if(event.type == SceneManagerEventTypeCustom) {
  43. if(event.event == GuiButtonTypeLeft) {
  44. consumed = scene_manager_previous_scene(passy->scene_manager);
  45. }
  46. } else if(event.type == SceneManagerEventTypeBack) {
  47. scene_manager_search_and_switch_to_previous_scene(
  48. passy->scene_manager, PassySceneMainMenu);
  49. consumed = true;
  50. }
  51. return consumed;
  52. }
  53. void passy_scene_read_error_on_exit(void* context) {
  54. Passy* passy = context;
  55. // Clear view
  56. widget_reset(passy->widget);
  57. }