-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdfc.c
More file actions
220 lines (166 loc) · 6.13 KB
/
Copy pathdfc.c
File metadata and controls
220 lines (166 loc) · 6.13 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include "dfc_i.h"
#define TAG "Dfc"
_Static_assert(
DFC_BUILD_PROFILE == DFC_PROFILE_FULL_EV1,
"The Flipper app must be built with the full EV1 profile");
bool dfc_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
Dfc* dfc = context;
return scene_manager_handle_custom_event(dfc->scene_manager, event);
}
bool dfc_back_event_callback(void* context) {
furi_assert(context);
Dfc* dfc = context;
return scene_manager_handle_back_event(dfc->scene_manager);
}
void dfc_tick_event_callback(void* context) {
furi_assert(context);
Dfc* dfc = context;
scene_manager_handle_tick_event(dfc->scene_manager);
}
Dfc* dfc_alloc() {
Dfc* dfc = malloc(sizeof(Dfc));
memset(dfc, 0, sizeof(Dfc));
dfc->view_dispatcher = view_dispatcher_alloc();
dfc->scene_manager = scene_manager_alloc(&dfc_scene_handlers, dfc);
view_dispatcher_set_event_callback_context(dfc->view_dispatcher, dfc);
view_dispatcher_set_custom_event_callback(dfc->view_dispatcher, dfc_custom_event_callback);
view_dispatcher_set_navigation_event_callback(dfc->view_dispatcher, dfc_back_event_callback);
view_dispatcher_set_tick_event_callback(dfc->view_dispatcher, dfc_tick_event_callback, 100);
dfc->nfc = nfc_alloc();
// Nfc device
dfc->nfc_device = nfc_device_alloc();
nfc_device_set_loading_callback(dfc->nfc_device, dfc_show_loading_popup, dfc);
// Open GUI record
dfc->gui = furi_record_open(RECORD_GUI);
view_dispatcher_attach_to_gui(dfc->view_dispatcher, dfc->gui, ViewDispatcherTypeFullscreen);
// Open Notification record
dfc->notifications = furi_record_open(RECORD_NOTIFICATION);
// Submenu
dfc->submenu = submenu_alloc();
view_dispatcher_add_view(dfc->view_dispatcher, DfcViewMenu, submenu_get_view(dfc->submenu));
// Popup
dfc->popup = popup_alloc();
view_dispatcher_add_view(dfc->view_dispatcher, DfcViewPopup, popup_get_view(dfc->popup));
// Loading
dfc->loading = loading_alloc();
view_dispatcher_add_view(dfc->view_dispatcher, DfcViewLoading, loading_get_view(dfc->loading));
// Text Input
dfc->text_input = text_input_alloc();
view_dispatcher_add_view(
dfc->view_dispatcher, DfcViewTextInput, text_input_get_view(dfc->text_input));
// TextBox
dfc->text_box = text_box_alloc();
view_dispatcher_add_view(
dfc->view_dispatcher, DfcViewTextBox, text_box_get_view(dfc->text_box));
dfc->text_box_store = furi_string_alloc();
// Custom Widget
dfc->widget = widget_alloc();
view_dispatcher_add_view(dfc->view_dispatcher, DfcViewWidget, widget_get_view(dfc->widget));
dfc_credential_storage_init();
dfc->credential = dfc_credential_alloc();
// File Browser
dfc->file_browser = file_browser_alloc(dfc_credential_storage_load_path());
view_dispatcher_add_view(
dfc->view_dispatcher, DfcViewFileBrowser, file_browser_get_view(dfc->file_browser));
return dfc;
}
void dfc_free(Dfc* dfc) {
furi_assert(dfc);
if(dfc->listener) {
nfc_listener_stop(dfc->listener);
nfc_listener_free(dfc->listener);
dfc->listener = NULL;
}
if(dfc->poller) {
nfc_poller_stop(dfc->poller);
nfc_poller_free(dfc->poller);
dfc->poller = NULL;
}
nfc_free(dfc->nfc);
// Nfc device
nfc_device_free(dfc->nfc_device);
// Submenu
view_dispatcher_remove_view(dfc->view_dispatcher, DfcViewMenu);
submenu_free(dfc->submenu);
// Popup
view_dispatcher_remove_view(dfc->view_dispatcher, DfcViewPopup);
popup_free(dfc->popup);
// Loading
view_dispatcher_remove_view(dfc->view_dispatcher, DfcViewLoading);
loading_free(dfc->loading);
// TextInput
view_dispatcher_remove_view(dfc->view_dispatcher, DfcViewTextInput);
text_input_free(dfc->text_input);
// TextBox
view_dispatcher_remove_view(dfc->view_dispatcher, DfcViewTextBox);
text_box_free(dfc->text_box);
furi_string_free(dfc->text_box_store);
// Custom Widget
view_dispatcher_remove_view(dfc->view_dispatcher, DfcViewWidget);
widget_free(dfc->widget);
// File Browser
view_dispatcher_remove_view(dfc->view_dispatcher, DfcViewFileBrowser);
file_browser_free(dfc->file_browser);
// View Dispatcher
view_dispatcher_free(dfc->view_dispatcher);
// Scene Manager
scene_manager_free(dfc->scene_manager);
// GUI
furi_record_close(RECORD_GUI);
dfc->gui = NULL;
// Notifications
furi_record_close(RECORD_NOTIFICATION);
dfc->notifications = NULL;
dfc_credential_free(dfc->credential);
dfc_credential_storage_deinit();
if(dfc->dfc_emulator) {
dfc_emulator_free(dfc->dfc_emulator);
dfc->dfc_emulator = NULL;
}
free(dfc);
}
void dfc_text_store_set(Dfc* dfc, const char* text, ...) {
va_list args;
va_start(args, text);
vsnprintf(dfc->text_store, sizeof(dfc->text_store), text, args);
va_end(args);
}
void dfc_text_store_clear(Dfc* dfc) {
memset(dfc->text_store, 0, sizeof(dfc->text_store));
}
static const NotificationSequence dfc_sequence_blink_start_blue = {
&message_blink_start_10,
&message_blink_set_color_blue,
&message_do_not_reset,
NULL,
};
static const NotificationSequence dfc_sequence_blink_stop = {
&message_blink_stop,
NULL,
};
void dfc_blink_start(Dfc* dfc) {
notification_message(dfc->notifications, &dfc_sequence_blink_start_blue);
}
void dfc_blink_stop(Dfc* dfc) {
notification_message(dfc->notifications, &dfc_sequence_blink_stop);
}
void dfc_show_loading_popup(void* context, bool show) {
Dfc* dfc = context;
if(show) {
// Raise timer priority so that animations can play
furi_timer_set_thread_priority(FuriTimerThreadPriorityElevated);
view_dispatcher_switch_to_view(dfc->view_dispatcher, DfcViewLoading);
} else {
// Restore default timer priority
furi_timer_set_thread_priority(FuriTimerThreadPriorityNormal);
}
}
int32_t dfc_app(void* p) {
UNUSED(p);
Dfc* dfc = dfc_alloc();
scene_manager_next_scene(dfc->scene_manager, DfcSceneMainMenu);
view_dispatcher_run(dfc->view_dispatcher);
dfc_free(dfc);
return 0;
}