-
Notifications
You must be signed in to change notification settings - Fork 0
/
nfc_magic_gen4.c
177 lines (140 loc) · 5.75 KB
/
nfc_magic_gen4.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "nfc_magic_gen4_i.h"
bool nfc_magic_gen4_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
NfcMagic* nfc_magic = context;
return scene_manager_handle_custom_event(nfc_magic->scene_manager, event);
}
bool nfc_magic_gen4_back_event_callback(void* context) {
furi_assert(context);
NfcMagic* nfc_magic = context;
return scene_manager_handle_back_event(nfc_magic->scene_manager);
}
void nfc_magic_gen4_tick_event_callback(void* context) {
furi_assert(context);
NfcMagic* nfc_magic = context;
scene_manager_handle_tick_event(nfc_magic->scene_manager);
}
void nfc_magic_gen4_show_loading_popup(void* context, bool show) {
NfcMagic* nfc_magic = context;
TaskHandle_t timer_task = xTaskGetHandle(configTIMER_SERVICE_TASK_NAME);
if(show) {
// Raise timer priority so that animations can play
vTaskPrioritySet(timer_task, configMAX_PRIORITIES - 1);
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewLoading);
} else {
// Restore default timer priority
vTaskPrioritySet(timer_task, configTIMER_TASK_PRIORITY);
}
}
NfcMagic* nfc_magic_gen4_alloc() {
NfcMagic* nfc_magic = malloc(sizeof(NfcMagic));
nfc_magic->worker = nfc_magic_gen4_worker_alloc();
nfc_magic->view_dispatcher = view_dispatcher_alloc();
nfc_magic->scene_manager = scene_manager_alloc(&nfc_magic_gen4_scene_handlers, nfc_magic);
view_dispatcher_enable_queue(nfc_magic->view_dispatcher);
view_dispatcher_set_event_callback_context(nfc_magic->view_dispatcher, nfc_magic);
view_dispatcher_set_custom_event_callback(
nfc_magic->view_dispatcher, nfc_magic_gen4_custom_event_callback);
view_dispatcher_set_navigation_event_callback(
nfc_magic->view_dispatcher, nfc_magic_gen4_back_event_callback);
view_dispatcher_set_tick_event_callback(
nfc_magic->view_dispatcher, nfc_magic_gen4_tick_event_callback, 100);
// Nfc device
nfc_magic->nfc_dev = nfc_device_alloc();
furi_string_set(nfc_magic->nfc_dev->folder, NFC_APP_FOLDER);
// Open GUI record
nfc_magic->gui = furi_record_open(RECORD_GUI);
view_dispatcher_attach_to_gui(
nfc_magic->view_dispatcher, nfc_magic->gui, ViewDispatcherTypeFullscreen);
// Open Notification record
nfc_magic->notifications = furi_record_open(RECORD_NOTIFICATION);
// Submenu
nfc_magic->submenu = submenu_alloc();
view_dispatcher_add_view(
nfc_magic->view_dispatcher, NfcMagicViewMenu, submenu_get_view(nfc_magic->submenu));
// Popup
nfc_magic->popup = popup_alloc();
view_dispatcher_add_view(
nfc_magic->view_dispatcher, NfcMagicViewPopup, popup_get_view(nfc_magic->popup));
// Loading
nfc_magic->loading = loading_alloc();
view_dispatcher_add_view(
nfc_magic->view_dispatcher, NfcMagicViewLoading, loading_get_view(nfc_magic->loading));
// Text Input
nfc_magic->text_input = text_input_alloc();
view_dispatcher_add_view(
nfc_magic->view_dispatcher,
NfcMagicViewTextInput,
text_input_get_view(nfc_magic->text_input));
// Custom Widget
nfc_magic->widget = widget_alloc();
view_dispatcher_add_view(
nfc_magic->view_dispatcher, NfcMagicViewWidget, widget_get_view(nfc_magic->widget));
nfc_magic->byte_input = byte_input_alloc();
view_dispatcher_add_view(
nfc_magic->view_dispatcher,
NfcMagicViewByteInput,
byte_input_get_view(nfc_magic->byte_input));
nfc_magic->persisted_state = malloc(sizeof(NfcMagic4State));
LOAD_MAGIC4_SETTINGS(nfc_magic->persisted_state);
return nfc_magic;
}
void nfc_magic_gen4_free(NfcMagic* nfc_magic) {
furi_assert(nfc_magic);
// Nfc device
nfc_device_free(nfc_magic->nfc_dev);
// Submenu
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewMenu);
submenu_free(nfc_magic->submenu);
// Popup
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewPopup);
popup_free(nfc_magic->popup);
// Loading
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewLoading);
loading_free(nfc_magic->loading);
// TextInput
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewTextInput);
text_input_free(nfc_magic->text_input);
// Custom Widget
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewWidget);
widget_free(nfc_magic->widget);
// Worker
nfc_magic_gen4_worker_stop(nfc_magic->worker);
nfc_magic_gen4_worker_free(nfc_magic->worker);
// View Dispatcher
view_dispatcher_free(nfc_magic->view_dispatcher);
// Scene Manager
scene_manager_free(nfc_magic->scene_manager);
// GUI
furi_record_close(RECORD_GUI);
nfc_magic->gui = NULL;
// Notifications
furi_record_close(RECORD_NOTIFICATION);
nfc_magic->notifications = NULL;
free(nfc_magic->persisted_state);
free(nfc_magic);
}
static const NotificationSequence nfc_magic_gen4_sequence_blink_start_cyan = {
&message_blink_start_10,
&message_blink_set_color_cyan,
&message_do_not_reset,
NULL,
};
static const NotificationSequence nfc_magic_gen4_sequence_blink_stop = {
&message_blink_stop,
NULL,
};
void nfc_magic_gen4_blink_start(NfcMagic* nfc_magic) {
notification_message(nfc_magic->notifications, &nfc_magic_gen4_sequence_blink_start_cyan);
}
void nfc_magic_gen4_blink_stop(NfcMagic* nfc_magic) {
notification_message(nfc_magic->notifications, &nfc_magic_gen4_sequence_blink_stop);
}
int32_t nfc_magic_gen4_app(void* p) {
UNUSED(p);
NfcMagic* nfc_magic = nfc_magic_gen4_alloc();
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneStart);
view_dispatcher_run(nfc_magic->view_dispatcher);
nfc_magic_gen4_free(nfc_magic);
return 0;
}