nfc_rfid_detector_app.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include "nfc_rfid_detector_app_i.h"
  2. #include <furi.h>
  3. #include <furi_hal.h>
  4. static bool nfc_rfid_detector_app_custom_event_callback(void* context, uint32_t event) {
  5. furi_assert(context);
  6. NfcRfidDetectorApp* app = context;
  7. return scene_manager_handle_custom_event(app->scene_manager, event);
  8. }
  9. static bool nfc_rfid_detector_app_back_event_callback(void* context) {
  10. furi_assert(context);
  11. NfcRfidDetectorApp* app = context;
  12. return scene_manager_handle_back_event(app->scene_manager);
  13. }
  14. static void nfc_rfid_detector_app_tick_event_callback(void* context) {
  15. furi_assert(context);
  16. NfcRfidDetectorApp* app = context;
  17. scene_manager_handle_tick_event(app->scene_manager);
  18. }
  19. NfcRfidDetectorApp* nfc_rfid_detector_app_alloc() {
  20. NfcRfidDetectorApp* app = malloc(sizeof(NfcRfidDetectorApp));
  21. // GUI
  22. app->gui = furi_record_open(RECORD_GUI);
  23. // View Dispatcher
  24. app->view_dispatcher = view_dispatcher_alloc();
  25. app->scene_manager = scene_manager_alloc(&nfc_rfid_detector_scene_handlers, app);
  26. view_dispatcher_enable_queue(app->view_dispatcher);
  27. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  28. view_dispatcher_set_custom_event_callback(
  29. app->view_dispatcher, nfc_rfid_detector_app_custom_event_callback);
  30. view_dispatcher_set_navigation_event_callback(
  31. app->view_dispatcher, nfc_rfid_detector_app_back_event_callback);
  32. view_dispatcher_set_tick_event_callback(
  33. app->view_dispatcher, nfc_rfid_detector_app_tick_event_callback, 100);
  34. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  35. // Open Notification record
  36. app->notifications = furi_record_open(RECORD_NOTIFICATION);
  37. // SubMenu
  38. app->submenu = submenu_alloc();
  39. view_dispatcher_add_view(
  40. app->view_dispatcher, NfcRfidDetectorViewSubmenu, submenu_get_view(app->submenu));
  41. // Widget
  42. app->widget = widget_alloc();
  43. view_dispatcher_add_view(
  44. app->view_dispatcher, NfcRfidDetectorViewWidget, widget_get_view(app->widget));
  45. // Field Presence
  46. app->nfc_rfid_detector_field_presence = nfc_rfid_detector_view_field_presence_alloc();
  47. view_dispatcher_add_view(
  48. app->view_dispatcher,
  49. NfcRfidDetectorViewFieldPresence,
  50. nfc_rfid_detector_view_field_presence_get_view(app->nfc_rfid_detector_field_presence));
  51. scene_manager_next_scene(app->scene_manager, NfcRfidDetectorSceneFieldPresence);
  52. return app;
  53. }
  54. void nfc_rfid_detector_app_free(NfcRfidDetectorApp* app) {
  55. furi_assert(app);
  56. // Submenu
  57. view_dispatcher_remove_view(app->view_dispatcher, NfcRfidDetectorViewSubmenu);
  58. submenu_free(app->submenu);
  59. // Widget
  60. view_dispatcher_remove_view(app->view_dispatcher, NfcRfidDetectorViewWidget);
  61. widget_free(app->widget);
  62. // Field Presence
  63. view_dispatcher_remove_view(app->view_dispatcher, NfcRfidDetectorViewFieldPresence);
  64. nfc_rfid_detector_view_field_presence_free(app->nfc_rfid_detector_field_presence);
  65. // View dispatcher
  66. view_dispatcher_free(app->view_dispatcher);
  67. scene_manager_free(app->scene_manager);
  68. // Notifications
  69. furi_record_close(RECORD_NOTIFICATION);
  70. app->notifications = NULL;
  71. // Close records
  72. furi_record_close(RECORD_GUI);
  73. free(app);
  74. }
  75. int32_t nfc_rfid_detector_app(void* p) {
  76. UNUSED(p);
  77. NfcRfidDetectorApp* nfc_rfid_detector_app = nfc_rfid_detector_app_alloc();
  78. view_dispatcher_run(nfc_rfid_detector_app->view_dispatcher);
  79. nfc_rfid_detector_app_free(nfc_rfid_detector_app);
  80. return 0;
  81. }