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