uhf_scene_device_info.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include "../uhf_app_i.h"
  2. #include <dolphin/dolphin.h>
  3. typedef enum {
  4. EPC_INFO,
  5. TID_INFO,
  6. USER_INFO
  7. } UHFTagInfo;
  8. static UHFTagInfo current_info;
  9. char* get_current_bank_info_str() {
  10. switch(current_info) {
  11. case EPC_INFO:
  12. return "EPC Bank";
  13. case TID_INFO:
  14. return "TID Bank";
  15. case USER_INFO:
  16. return "User Bank";
  17. }
  18. return "";
  19. }
  20. char* get_next_bank_info_str() {
  21. switch(current_info) {
  22. case EPC_INFO:
  23. current_info = TID_INFO;
  24. return "TID";
  25. case TID_INFO:
  26. current_info = USER_INFO;
  27. return "USER";
  28. case USER_INFO:
  29. current_info = EPC_INFO;
  30. return "EPC";
  31. }
  32. return "";
  33. }
  34. void uhf_scene_device_info_widget_callback(GuiButtonType result, InputType type, void* context) {
  35. UHFApp* uhf_app = context;
  36. if(type == InputTypeShort) {
  37. view_dispatcher_send_custom_event(uhf_app->view_dispatcher, result);
  38. }
  39. }
  40. void change_view_on_event(UHFApp* uhf_app) {
  41. UHFTag* uhf_tag = uhf_app->uhf_device->uhf_tag_wrapper->uhf_tag;
  42. FuriString* furi_temp_str;
  43. furi_temp_str = furi_string_alloc();
  44. char* temp_str;
  45. size_t length;
  46. widget_reset(uhf_app->widget);
  47. widget_add_string_element(
  48. uhf_app->widget, 64, 5, AlignCenter, AlignCenter, FontPrimary, get_current_bank_info_str());
  49. switch(current_info) {
  50. case EPC_INFO:
  51. temp_str = convertToHexString(uhf_tag->epc->data, uhf_tag->epc->size);
  52. length = uhf_tag->epc->size;
  53. break;
  54. case TID_INFO:
  55. temp_str = convertToHexString(uhf_tag->tid->data, uhf_tag->tid->size);
  56. length = uhf_tag->tid->size;
  57. break;
  58. case USER_INFO:
  59. temp_str = convertToHexString(uhf_tag->user->data, uhf_tag->user->size);
  60. length = uhf_tag->user->size;
  61. break;
  62. default:
  63. temp_str = NULL;
  64. length = 0;
  65. break;
  66. }
  67. furi_string_cat_printf(furi_temp_str, "Length: %d bytes", length);
  68. widget_add_string_element(
  69. uhf_app->widget,
  70. 3,
  71. 12,
  72. AlignLeft,
  73. AlignTop,
  74. FontKeyboard,
  75. furi_string_get_cstr(furi_temp_str));
  76. widget_add_string_multiline_element(
  77. uhf_app->widget, 3, 24, AlignLeft, AlignTop, FontKeyboard, temp_str);
  78. widget_add_button_element(
  79. uhf_app->widget,
  80. GuiButtonTypeRight,
  81. get_next_bank_info_str(),
  82. uhf_scene_device_info_widget_callback,
  83. uhf_app);
  84. widget_add_button_element(
  85. uhf_app->widget, GuiButtonTypeLeft, "Back", uhf_scene_device_info_widget_callback, uhf_app);
  86. furi_string_free(furi_temp_str);
  87. free(temp_str);
  88. }
  89. void uhf_scene_device_info_on_enter(void* context) {
  90. UHFApp* uhf_app = context;
  91. current_info = EPC_INFO;
  92. dolphin_deed(DolphinDeedNfcReadSuccess);
  93. change_view_on_event(uhf_app);
  94. view_dispatcher_switch_to_view(uhf_app->view_dispatcher, UHFViewWidget);
  95. }
  96. bool uhf_scene_device_info_on_event(void* context, SceneManagerEvent event) {
  97. UHFApp* uhf_app = context;
  98. bool consumed = false;
  99. if(event.type == SceneManagerEventTypeTick) return false;
  100. if(event.type == SceneManagerEventTypeCustom) {
  101. if(event.event == GuiButtonTypeLeft) {
  102. consumed = scene_manager_previous_scene(uhf_app->scene_manager);
  103. } else if(event.event == GuiButtonTypeRight) {
  104. change_view_on_event(uhf_app);
  105. } else if(event.event == UHFCustomEventViewExit) {
  106. view_dispatcher_switch_to_view(uhf_app->view_dispatcher, UHFViewWidget);
  107. consumed = true;
  108. }
  109. } else if(event.type == SceneManagerEventTypeBack) {
  110. scene_manager_previous_scene(uhf_app->scene_manager);
  111. consumed = true;
  112. }
  113. return consumed;
  114. }
  115. void uhf_scene_device_info_on_exit(void* context) {
  116. UHFApp* uhf_app = context;
  117. // Clear views
  118. widget_reset(uhf_app->widget);
  119. }