nfc_scene_mf_desfire_read_success.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "../nfc_i.h"
  2. #include <dolphin/dolphin.h>
  3. void nfc_scene_mf_desfire_read_success_widget_callback(
  4. GuiButtonType result,
  5. InputType type,
  6. void* context) {
  7. Nfc* nfc = context;
  8. if(type == InputTypeShort) {
  9. view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
  10. }
  11. }
  12. void nfc_scene_mf_desfire_read_success_on_enter(void* context) {
  13. Nfc* nfc = context;
  14. FuriHalNfcDevData* nfc_data = &nfc->dev->dev_data.nfc_data;
  15. MifareDesfireData* data = &nfc->dev->dev_data.mf_df_data;
  16. Widget* widget = nfc->widget;
  17. // Prepare string for data display
  18. string_t temp_str;
  19. string_init_printf(temp_str, "\e#MIFARE DESfire\n");
  20. string_cat_printf(temp_str, "UID:");
  21. for(size_t i = 0; i < nfc_data->uid_len; i++) {
  22. string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
  23. }
  24. uint32_t bytes_total = 1 << (data->version.sw_storage >> 1);
  25. uint32_t bytes_free = data->free_memory ? data->free_memory->bytes : 0;
  26. string_cat_printf(temp_str, "\n%d", bytes_total);
  27. if(data->version.sw_storage & 1) {
  28. string_push_back(temp_str, '+');
  29. }
  30. string_cat_printf(temp_str, " bytes, %d bytes free\n", bytes_free);
  31. uint16_t n_apps = 0;
  32. uint16_t n_files = 0;
  33. for(MifareDesfireApplication* app = data->app_head; app; app = app->next) {
  34. n_apps++;
  35. for(MifareDesfireFile* file = app->file_head; file; file = file->next) {
  36. n_files++;
  37. }
  38. }
  39. string_cat_printf(temp_str, "%d Application", n_apps);
  40. if(n_apps != 1) {
  41. string_push_back(temp_str, 's');
  42. }
  43. string_cat_printf(temp_str, ", %d file", n_files);
  44. if(n_files != 1) {
  45. string_push_back(temp_str, 's');
  46. }
  47. // Add text scroll element
  48. widget_add_text_scroll_element(widget, 0, 0, 128, 52, string_get_cstr(temp_str));
  49. string_clear(temp_str);
  50. // Add button elements
  51. widget_add_button_element(
  52. widget, GuiButtonTypeLeft, "Retry", nfc_scene_mf_desfire_read_success_widget_callback, nfc);
  53. widget_add_button_element(
  54. widget, GuiButtonTypeRight, "More", nfc_scene_mf_desfire_read_success_widget_callback, nfc);
  55. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  56. }
  57. bool nfc_scene_mf_desfire_read_success_on_event(void* context, SceneManagerEvent event) {
  58. Nfc* nfc = context;
  59. bool consumed = false;
  60. if(event.type == SceneManagerEventTypeCustom) {
  61. if(event.event == GuiButtonTypeLeft) {
  62. scene_manager_next_scene(nfc->scene_manager, NfcSceneRetryConfirm);
  63. consumed = true;
  64. } else if(event.event == GuiButtonTypeRight) {
  65. scene_manager_next_scene(nfc->scene_manager, NfcSceneMfDesfireMenu);
  66. consumed = true;
  67. }
  68. } else if(event.type == SceneManagerEventTypeBack) {
  69. scene_manager_next_scene(nfc->scene_manager, NfcSceneExitConfirm);
  70. consumed = true;
  71. }
  72. return consumed;
  73. }
  74. void nfc_scene_mf_desfire_read_success_on_exit(void* context) {
  75. Nfc* nfc = context;
  76. // Clean dialog
  77. widget_reset(nfc->widget);
  78. }