nfc_rfid_detector_app.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_set_event_callback_context(app->view_dispatcher, app);
  27. view_dispatcher_set_custom_event_callback(
  28. app->view_dispatcher, nfc_rfid_detector_app_custom_event_callback);
  29. view_dispatcher_set_navigation_event_callback(
  30. app->view_dispatcher, nfc_rfid_detector_app_back_event_callback);
  31. view_dispatcher_set_tick_event_callback(
  32. app->view_dispatcher, nfc_rfid_detector_app_tick_event_callback, 100);
  33. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  34. // Open Notification record
  35. app->notifications = furi_record_open(RECORD_NOTIFICATION);
  36. // SubMenu
  37. app->submenu = submenu_alloc();
  38. view_dispatcher_add_view(
  39. app->view_dispatcher, NfcRfidDetectorViewSubmenu, submenu_get_view(app->submenu));
  40. // Widget
  41. app->widget = widget_alloc();
  42. view_dispatcher_add_view(
  43. app->view_dispatcher, NfcRfidDetectorViewWidget, widget_get_view(app->widget));
  44. // Field Presence
  45. app->nfc_rfid_detector_field_presence = nfc_rfid_detector_view_field_presence_alloc();
  46. view_dispatcher_add_view(
  47. app->view_dispatcher,
  48. NfcRfidDetectorViewFieldPresence,
  49. nfc_rfid_detector_view_field_presence_get_view(app->nfc_rfid_detector_field_presence));
  50. scene_manager_next_scene(app->scene_manager, NfcRfidDetectorSceneFieldPresence);
  51. return app;
  52. }
  53. void nfc_rfid_detector_app_free(NfcRfidDetectorApp* app) {
  54. furi_assert(app);
  55. // Submenu
  56. view_dispatcher_remove_view(app->view_dispatcher, NfcRfidDetectorViewSubmenu);
  57. submenu_free(app->submenu);
  58. // Widget
  59. view_dispatcher_remove_view(app->view_dispatcher, NfcRfidDetectorViewWidget);
  60. widget_free(app->widget);
  61. // Field Presence
  62. view_dispatcher_remove_view(app->view_dispatcher, NfcRfidDetectorViewFieldPresence);
  63. nfc_rfid_detector_view_field_presence_free(app->nfc_rfid_detector_field_presence);
  64. // View dispatcher
  65. view_dispatcher_free(app->view_dispatcher);
  66. scene_manager_free(app->scene_manager);
  67. // Notifications
  68. furi_record_close(RECORD_NOTIFICATION);
  69. app->notifications = NULL;
  70. // Close records
  71. furi_record_close(RECORD_GUI);
  72. free(app);
  73. }
  74. int32_t nfc_rfid_detector_app(void* p) {
  75. UNUSED(p);
  76. NfcRfidDetectorApp* nfc_rfid_detector_app = nfc_rfid_detector_app_alloc();
  77. view_dispatcher_run(nfc_rfid_detector_app->view_dispatcher);
  78. nfc_rfid_detector_app_free(nfc_rfid_detector_app);
  79. return 0;
  80. }