nfc_scene_generate_info.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "../nfc_i.h"
  2. #include "../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. string_t info_str;
  15. string_init_printf(
  16. info_str, "%s\n%s\nUID:", nfc->generator->name, nfc_get_dev_type(data->type));
  17. // Append UID
  18. for(int i = 0; i < data->uid_len; ++i) {
  19. string_cat_printf(info_str, " %02X", data->uid[i]);
  20. }
  21. nfc_text_store_set(nfc, string_get_cstr(info_str));
  22. string_clear(info_str);
  23. dialog_ex_set_text(dialog_ex, nfc->text_store, 0, 0, AlignLeft, AlignTop);
  24. dialog_ex_set_context(dialog_ex, nfc);
  25. dialog_ex_set_result_callback(dialog_ex, nfc_scene_generate_info_dialog_callback);
  26. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDialogEx);
  27. }
  28. bool nfc_scene_generate_info_on_event(void* context, SceneManagerEvent event) {
  29. Nfc* nfc = context;
  30. bool consumed = false;
  31. if(event.type == SceneManagerEventTypeCustom) {
  32. if(event.event == DialogExResultRight) {
  33. scene_manager_next_scene(nfc->scene_manager, nfc->generator->next_scene);
  34. consumed = true;
  35. }
  36. }
  37. return consumed;
  38. }
  39. void nfc_scene_generate_info_on_exit(void* context) {
  40. Nfc* nfc = context;
  41. // Clean views
  42. dialog_ex_reset(nfc->dialog_ex);
  43. }