uhf_scene_device_info.c 3.8 KB

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