nfc_scene_debug_menu.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "nfc_scene_debug_menu.h"
  2. #include "../nfc_i.h"
  3. #include <furi.h>
  4. #include <gui/modules/submenu.h>
  5. #include <gui/view_dispatcher.h>
  6. typedef enum {
  7. SubmenuIndexDetect,
  8. SubmenuIndexEmulate,
  9. SubmenuIndexReadEmv,
  10. SubmenuIndexReadMifareUl,
  11. } SubmenuIndex;
  12. void nfc_scene_debug_menu_submenu_callback(void* context, uint32_t index) {
  13. Nfc* nfc = (Nfc*)context;
  14. view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, index);
  15. }
  16. const void nfc_scene_debug_menu_on_enter(void* context) {
  17. Nfc* nfc = (Nfc*)context;
  18. Submenu* submenu = nfc->submenu;
  19. submenu_add_item(
  20. submenu, "Detect", SubmenuIndexDetect, nfc_scene_debug_menu_submenu_callback, nfc);
  21. submenu_add_item(
  22. submenu, "Emulate", SubmenuIndexEmulate, nfc_scene_debug_menu_submenu_callback, nfc);
  23. submenu_add_item(
  24. submenu, "Read EMV", SubmenuIndexReadEmv, nfc_scene_debug_menu_submenu_callback, nfc);
  25. submenu_add_item(
  26. submenu,
  27. "Read Mifare Ultralight",
  28. SubmenuIndexReadMifareUl,
  29. nfc_scene_debug_menu_submenu_callback,
  30. nfc);
  31. view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewMenu);
  32. }
  33. const bool nfc_scene_debug_menu_on_event(void* context, uint32_t event) {
  34. Nfc* nfc = (Nfc*)context;
  35. if(event == SubmenuIndexDetect) {
  36. view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_debug_detect);
  37. view_dispatcher_send_navigation_event(
  38. nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
  39. return true;
  40. } else if(event == SubmenuIndexEmulate) {
  41. view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_debug_emulate);
  42. view_dispatcher_send_navigation_event(
  43. nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
  44. return true;
  45. } else if(event == SubmenuIndexReadEmv) {
  46. view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_debug_read_emv);
  47. view_dispatcher_send_navigation_event(
  48. nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
  49. return true;
  50. } else if(event == SubmenuIndexReadMifareUl) {
  51. view_dispatcher_add_scene(
  52. nfc->nfc_common.view_dispatcher, nfc->scene_debug_read_mifare_ul);
  53. view_dispatcher_send_navigation_event(
  54. nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
  55. return true;
  56. }
  57. return false;
  58. }
  59. const void nfc_scene_debug_menu_on_exit(void* context) {
  60. Nfc* nfc = (Nfc*)context;
  61. submenu_clean(nfc->submenu);
  62. }
  63. AppScene* nfc_scene_debug_menu_alloc() {
  64. AppScene* scene = furi_alloc(sizeof(AppScene));
  65. scene->id = NfcSceneDebugMenu;
  66. scene->on_enter = nfc_scene_debug_menu_on_enter;
  67. scene->on_event = nfc_scene_debug_menu_on_event;
  68. scene->on_exit = nfc_scene_debug_menu_on_exit;
  69. return scene;
  70. }
  71. void nfc_scene_debug_menu_free(AppScene* scene) {
  72. free(scene);
  73. }