nfc_scene_mf_classic_read_success.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "../nfc_i.h"
  2. #include <dolphin/dolphin.h>
  3. void nfc_scene_mf_classic_read_success_widget_callback(
  4. GuiButtonType result,
  5. InputType type,
  6. void* context) {
  7. furi_assert(context);
  8. Nfc* nfc = context;
  9. if(type == InputTypeShort) {
  10. view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
  11. }
  12. }
  13. void nfc_scene_mf_classic_read_success_on_enter(void* context) {
  14. Nfc* nfc = context;
  15. NfcDeviceData* dev_data = &nfc->dev->dev_data;
  16. MfClassicData* mf_data = &dev_data->mf_classic_data;
  17. DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
  18. // Setup view
  19. Widget* widget = nfc->widget;
  20. widget_add_button_element(
  21. widget, GuiButtonTypeLeft, "Retry", nfc_scene_mf_classic_read_success_widget_callback, nfc);
  22. widget_add_button_element(
  23. widget, GuiButtonTypeRight, "More", nfc_scene_mf_classic_read_success_widget_callback, nfc);
  24. string_t temp_str;
  25. if(string_size(nfc->dev->dev_data.parsed_data)) {
  26. string_init_set(temp_str, nfc->dev->dev_data.parsed_data);
  27. } else {
  28. string_init_printf(temp_str, "\e#%s\n", nfc_mf_classic_type(mf_data->type));
  29. string_cat_printf(temp_str, "UID:");
  30. for(size_t i = 0; i < dev_data->nfc_data.uid_len; i++) {
  31. string_cat_printf(temp_str, " %02X", dev_data->nfc_data.uid[i]);
  32. }
  33. uint8_t sectors_total = mf_classic_get_total_sectors_num(mf_data->type);
  34. uint8_t keys_total = sectors_total * 2;
  35. uint8_t keys_found = 0;
  36. uint8_t sectors_read = 0;
  37. mf_classic_get_read_sectors_and_keys(mf_data, &sectors_read, &keys_found);
  38. string_cat_printf(temp_str, "\nKeys Found: %d/%d", keys_found, keys_total);
  39. string_cat_printf(temp_str, "\nSectors Read: %d/%d", sectors_read, sectors_total);
  40. }
  41. widget_add_text_scroll_element(widget, 0, 0, 128, 52, string_get_cstr(temp_str));
  42. string_clear(temp_str);
  43. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  44. }
  45. bool nfc_scene_mf_classic_read_success_on_event(void* context, SceneManagerEvent event) {
  46. Nfc* nfc = context;
  47. bool consumed = false;
  48. if(event.type == SceneManagerEventTypeCustom) {
  49. if(event.event == GuiButtonTypeLeft) {
  50. scene_manager_next_scene(nfc->scene_manager, NfcSceneRetryConfirm);
  51. consumed = true;
  52. } else if(event.event == GuiButtonTypeRight) {
  53. // Clear device name
  54. nfc_device_set_name(nfc->dev, "");
  55. scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicMenu);
  56. consumed = true;
  57. }
  58. } else if(event.type == SceneManagerEventTypeBack) {
  59. scene_manager_next_scene(nfc->scene_manager, NfcSceneExitConfirm);
  60. consumed = true;
  61. }
  62. return consumed;
  63. }
  64. void nfc_scene_mf_classic_read_success_on_exit(void* context) {
  65. Nfc* nfc = context;
  66. // Clear view
  67. widget_reset(nfc->widget);
  68. }