seader_scene_read_card_success.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include "../seader_i.h"
  2. #include <dolphin/dolphin.h>
  3. void seader_scene_read_card_success_widget_callback(
  4. GuiButtonType result,
  5. InputType type,
  6. void* context) {
  7. furi_assert(context);
  8. Seader* seader = context;
  9. if(type == InputTypeShort) {
  10. view_dispatcher_send_custom_event(seader->view_dispatcher, result);
  11. }
  12. }
  13. void seader_scene_read_card_success_on_enter(void* context) {
  14. Seader* seader = context;
  15. SeaderCredential* credential = seader->credential;
  16. Widget* widget = seader->widget;
  17. FuriString* type_str = furi_string_alloc();
  18. FuriString* bitlength_str = furi_string_alloc();
  19. FuriString* credential_str = furi_string_alloc();
  20. FuriString* sio_str = furi_string_alloc();
  21. dolphin_deed(DolphinDeedNfcReadSuccess);
  22. // Send notification
  23. notification_message(seader->notifications, &sequence_success);
  24. furi_string_set(credential_str, "");
  25. furi_string_set(bitlength_str, "");
  26. furi_string_set(sio_str, "");
  27. if(credential->bit_length > 0) {
  28. furi_string_cat_printf(bitlength_str, "%d bit", credential->bit_length);
  29. furi_string_cat_printf(credential_str, "0x%llX", credential->credential);
  30. if(credential->type == SeaderCredentialTypeNone) {
  31. furi_string_set(type_str, "Unknown");
  32. } else if(credential->type == SeaderCredentialTypeVirtual) {
  33. furi_string_set(type_str, "Virtual");
  34. } else if(credential->type == SeaderCredentialType14A) {
  35. furi_string_set(type_str, "14443A");
  36. } else if(credential->type == SeaderCredentialTypePicopass) {
  37. furi_string_set(type_str, "Picopass");
  38. } else {
  39. furi_string_set(type_str, "");
  40. }
  41. } else {
  42. furi_string_set(type_str, "Read error");
  43. }
  44. widget_add_button_element(
  45. widget, GuiButtonTypeLeft, "Retry", seader_scene_read_card_success_widget_callback, seader);
  46. widget_add_button_element(
  47. widget, GuiButtonTypeRight, "More", seader_scene_read_card_success_widget_callback, seader);
  48. widget_add_string_element(
  49. widget, 64, 5, AlignCenter, AlignCenter, FontPrimary, furi_string_get_cstr(type_str));
  50. widget_add_string_element(
  51. widget,
  52. 64,
  53. 24,
  54. AlignCenter,
  55. AlignCenter,
  56. FontSecondary,
  57. furi_string_get_cstr(bitlength_str));
  58. widget_add_string_element(
  59. widget,
  60. 64,
  61. 36,
  62. AlignCenter,
  63. AlignCenter,
  64. FontSecondary,
  65. furi_string_get_cstr(credential_str));
  66. if(credential->sio[0] == 0x30) {
  67. furi_string_set(sio_str, "+SIO");
  68. widget_add_string_element(
  69. widget, 64, 48, AlignCenter, AlignCenter, FontSecondary, furi_string_get_cstr(sio_str));
  70. }
  71. furi_string_free(credential_str);
  72. furi_string_free(bitlength_str);
  73. furi_string_free(type_str);
  74. furi_string_free(sio_str);
  75. view_dispatcher_switch_to_view(seader->view_dispatcher, SeaderViewWidget);
  76. }
  77. bool seader_scene_read_card_success_on_event(void* context, SceneManagerEvent event) {
  78. Seader* seader = context;
  79. bool consumed = false;
  80. if(event.type == SceneManagerEventTypeCustom) {
  81. if(event.event == GuiButtonTypeLeft) {
  82. consumed = scene_manager_previous_scene(seader->scene_manager);
  83. } else if(event.event == GuiButtonTypeRight) {
  84. scene_manager_next_scene(seader->scene_manager, SeaderSceneCardMenu);
  85. consumed = true;
  86. }
  87. } else if(event.type == SceneManagerEventTypeBack) {
  88. scene_manager_search_and_switch_to_previous_scene(
  89. seader->scene_manager, SeaderSceneSamPresent);
  90. consumed = true;
  91. }
  92. return consumed;
  93. }
  94. void seader_scene_read_card_success_on_exit(void* context) {
  95. Seader* seader = context;
  96. // Clear view
  97. widget_reset(seader->widget);
  98. }