nfc_scene_generate_info.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "../nfc_i.h"
  2. #include "lib/nfc/helpers/nfc_generators.h"
  3. void nfc_scene_generate_info_dialog_callback(DialogExResult result, void* context) {
  4. Nfc* nfc = context;
  5. view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
  6. }
  7. void nfc_scene_generate_info_on_enter(void* context) {
  8. Nfc* nfc = context;
  9. // Setup dialog view
  10. FuriHalNfcDevData* data = &nfc->dev->dev_data.nfc_data;
  11. DialogEx* dialog_ex = nfc->dialog_ex;
  12. dialog_ex_set_right_button_text(dialog_ex, "More");
  13. // Create info text
  14. FuriString* info_str = furi_string_alloc_printf(
  15. "%s\n%s\nUID:", nfc->generator->name, nfc_get_dev_type(data->type));
  16. // Append UID
  17. for(int i = 0; i < data->uid_len; ++i) {
  18. furi_string_cat_printf(info_str, " %02X", data->uid[i]);
  19. }
  20. nfc_text_store_set(nfc, furi_string_get_cstr(info_str));
  21. furi_string_free(info_str);
  22. dialog_ex_set_text(dialog_ex, nfc->text_store, 0, 0, AlignLeft, AlignTop);
  23. dialog_ex_set_context(dialog_ex, nfc);
  24. dialog_ex_set_result_callback(dialog_ex, nfc_scene_generate_info_dialog_callback);
  25. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDialogEx);
  26. }
  27. bool nfc_scene_generate_info_on_event(void* context, SceneManagerEvent event) {
  28. Nfc* nfc = context;
  29. bool consumed = false;
  30. if(event.type == SceneManagerEventTypeCustom) {
  31. if(event.event == DialogExResultRight) {
  32. // Switch either to NfcSceneMfClassicMenu or NfcSceneMfUltralightMenu
  33. if(nfc->dev->dev_data.protocol == NfcDeviceProtocolMifareClassic) {
  34. scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicMenu);
  35. } else if(nfc->dev->dev_data.protocol == NfcDeviceProtocolMifareUl) {
  36. scene_manager_next_scene(nfc->scene_manager, NfcSceneMfUltralightMenu);
  37. }
  38. consumed = true;
  39. }
  40. }
  41. return consumed;
  42. }
  43. void nfc_scene_generate_info_on_exit(void* context) {
  44. Nfc* nfc = context;
  45. // Clean views
  46. dialog_ex_reset(nfc->dialog_ex);
  47. }