-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxremote.c
214 lines (172 loc) · 7.57 KB
/
xremote.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
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
#include "xremote.h"
bool xremote_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
XRemote* app = context;
return scene_manager_handle_custom_event(app->scene_manager, event);
}
void xremote_tick_event_callback(void* context) {
furi_assert(context);
XRemote* app = context;
scene_manager_handle_tick_event(app->scene_manager);
}
//leave app if back button pressed
bool xremote_navigation_event_callback(void* context) {
furi_assert(context);
XRemote* app = context;
return scene_manager_handle_back_event(app->scene_manager);
}
XRemote* xremote_app_alloc() {
XRemote* app = malloc(sizeof(XRemote));
app->gui = furi_record_open(RECORD_GUI);
app->notification = furi_record_open(RECORD_NOTIFICATION);
//Turn backlight on, believe me this makes testing your app easier
notification_message(app->notification, &sequence_display_backlight_on);
//Scene additions
app->view_dispatcher = view_dispatcher_alloc();
app->scene_manager = scene_manager_alloc(&xremote_scene_handlers, app);
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
view_dispatcher_set_navigation_event_callback(
app->view_dispatcher, xremote_navigation_event_callback);
view_dispatcher_set_tick_event_callback(
app->view_dispatcher, xremote_tick_event_callback, 100);
view_dispatcher_set_custom_event_callback(app->view_dispatcher, xremote_custom_event_callback);
app->submenu = submenu_alloc();
app->editmenu = submenu_alloc();
// Set defaults, in case no config loaded
app->haptic = 1;
app->speaker = 1;
app->led = 1;
app->save_settings = 1;
app->transmitting = 0;
app->ir_timing = 1000;
app->ir_timing_char = "1000";
app->sg_timing = 500;
app->sg_timing_char = "500";
app->stop_transmit = false;
app->loop_transmit = 0;
app->transmit_item = 0;
// Load configs
xremote_read_settings(app);
app->dialogs = furi_record_open(RECORD_DIALOGS);
app->file_path = furi_string_alloc();
app->ir_remote_buffer = xremote_ir_remote_alloc();
app->ir_worker = infrared_worker_alloc();
app->cross_remote = xremote_cross_remote_alloc();
app->sg_remote_buffer = xremote_sg_remote_alloc();
app->loading = loading_alloc();
app->subghz = subghz_alloc();
app->text_input = text_input_alloc();
app->number_input = number_input_alloc();
view_dispatcher_add_view(
app->view_dispatcher, XRemoteViewIdNumberInput, number_input_get_view(app->number_input));
view_dispatcher_add_view(
app->view_dispatcher, XRemoteViewIdTextInput, text_input_get_view(app->text_input));
view_dispatcher_add_view(
app->view_dispatcher, XRemoteViewIdMenu, submenu_get_view(app->submenu));
view_dispatcher_add_view(
app->view_dispatcher, XRemoteViewIdEditItem, submenu_get_view(app->editmenu));
app->xremote_infoscreen = xremote_infoscreen_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
XRemoteViewIdInfoscreen,
xremote_infoscreen_get_view(app->xremote_infoscreen));
app->xremote_transmit = xremote_transmit_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
XRemoteViewIdTransmit,
xremote_transmit_get_view(app->xremote_transmit));
app->xremote_pause_set = xremote_pause_set_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
XRemoteViewIdPauseSet,
xremote_pause_set_get_view(app->xremote_pause_set));
app->button_menu_create = button_menu_alloc();
view_dispatcher_add_view(
app->view_dispatcher, XRemoteViewIdCreate, button_menu_get_view(app->button_menu_create));
app->button_menu_create_add = button_menu_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
XRemoteViewIdCreateAdd,
button_menu_get_view(app->button_menu_create_add));
app->button_menu_ir = button_menu_alloc();
view_dispatcher_add_view(
app->view_dispatcher, XRemoteViewIdIrRemote, button_menu_get_view(app->button_menu_ir));
app->variable_item_list = variable_item_list_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
XRemoteViewIdSettings,
variable_item_list_get_view(app->variable_item_list));
app->popup = popup_alloc();
view_dispatcher_add_view(app->view_dispatcher, XRemoteViewIdWip, popup_get_view(app->popup));
app->view_stack = view_stack_alloc();
view_dispatcher_add_view(
app->view_dispatcher, XRemoteViewIdStack, view_stack_get_view(app->view_stack));
//End Scene Additions
return app;
}
void xremote_app_free(XRemote* app) {
furi_assert(app);
// Scene manager
scene_manager_free(app->scene_manager);
infrared_worker_free(app->ir_worker);
xremote_cross_remote_free(app->cross_remote);
subghz_free(app->subghz);
// View Dispatcher
view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdMenu);
view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdEditItem);
view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdInfoscreen);
view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdCreate);
view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdCreateAdd);
view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdSettings);
view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdWip);
view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdStack);
view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdTextInput);
view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdNumberInput);
view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdTransmit);
view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdPauseSet);
view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdIrRemote);
text_input_free(app->text_input);
number_input_free(app->number_input);
button_menu_free(app->button_menu_create);
button_menu_free(app->button_menu_create_add);
button_menu_free(app->button_menu_ir);
view_stack_free(app->view_stack);
popup_free(app->popup);
submenu_free(app->submenu);
xremote_infoscreen_free(app->xremote_infoscreen);
xremote_pause_set_free(app->xremote_pause_set);
xremote_transmit_free(app->xremote_transmit);
view_dispatcher_free(app->view_dispatcher);
furi_record_close(RECORD_GUI);
furi_record_close(RECORD_DIALOGS);
furi_string_free(app->file_path);
loading_free(app->loading);
app->gui = NULL;
app->notification = NULL;
//Remove whatever is left
free(app);
}
void xremote_popup_closed_callback(void* context) {
furi_assert(context);
XRemote* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, XRemoteCustomEventTypePopupClosed);
}
void xremote_text_input_callback(void* context) {
furi_assert(context);
XRemote* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, XRemoteCustomEventTextInput);
}
int32_t xremote_app(void* p) {
UNUSED(p);
XRemote* app = xremote_app_alloc();
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
//scene_manager_next_scene(app->scene_manager, XRemoteSceneInfoscreen); //Start with start screen
scene_manager_next_scene(
app->scene_manager, XRemoteSceneMenu); //if you want to directly start with Menu
furi_hal_power_suppress_charge_enter();
view_dispatcher_run(app->view_dispatcher);
xremote_save_settings(app);
furi_hal_power_suppress_charge_exit();
xremote_app_free(app);
return 0;
}