-
Notifications
You must be signed in to change notification settings - Fork 2
/
ublox.c
143 lines (106 loc) · 4.82 KB
/
ublox.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
#include "ublox_i.h"
const NotificationSequence sequence_new_reading = {
&message_green_255,
&message_delay_100,
&message_green_0,
NULL,
};
bool ublox_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
Ublox* ublox = context;
return scene_manager_handle_custom_event(ublox->scene_manager, event);
}
bool ublox_back_event_callback(void* context) {
furi_assert(context);
Ublox* ublox = context;
return scene_manager_handle_back_event(ublox->scene_manager);
}
Ublox* ublox_alloc() {
Ublox* ublox = malloc(sizeof(Ublox));
ublox->view_dispatcher = view_dispatcher_alloc();
ublox->scene_manager = scene_manager_alloc(&ublox_scene_handlers, ublox);
view_dispatcher_set_event_callback_context(ublox->view_dispatcher, ublox);
view_dispatcher_set_custom_event_callback(ublox->view_dispatcher, ublox_custom_event_callback);
view_dispatcher_set_navigation_event_callback(
ublox->view_dispatcher, ublox_back_event_callback);
ublox->worker = ublox_worker_alloc();
ublox->gui = furi_record_open(RECORD_GUI);
view_dispatcher_attach_to_gui(
ublox->view_dispatcher, ublox->gui, ViewDispatcherTypeFullscreen);
ublox->submenu = submenu_alloc();
view_dispatcher_add_view(
ublox->view_dispatcher, UbloxViewMenu, submenu_get_view(ublox->submenu));
ublox->widget = widget_alloc();
view_dispatcher_add_view(
ublox->view_dispatcher, UbloxViewWidget, widget_get_view(ublox->widget));
ublox->variable_item_list = variable_item_list_alloc();
view_dispatcher_add_view(
ublox->view_dispatcher,
UbloxViewVariableItemList,
variable_item_list_get_view(ublox->variable_item_list));
ublox->text_input = text_input_alloc();
view_dispatcher_add_view(
ublox->view_dispatcher, UbloxViewTextInput, text_input_get_view(ublox->text_input));
ublox->data_display = data_display_alloc();
view_dispatcher_add_view(
ublox->view_dispatcher, UbloxViewDataDisplay, data_display_get_view(ublox->data_display));
ublox->notifications = furi_record_open(RECORD_NOTIFICATION);
ublox->storage = furi_record_open(RECORD_STORAGE);
ublox->log_state = UbloxLogStateNone;
// files do actually belong here
ublox->logfile_folder = furi_string_alloc_set(STORAGE_APP_DATA_PATH_PREFIX);
// Establish default data display state
(ublox->data_display_state).view_mode = UbloxDataDisplayViewModeHandheld;
(ublox->data_display_state).refresh_rate = 2;
(ublox->data_display_state).notify_mode = UbloxDataDisplayNotifyOn;
(ublox->data_display_state).backlight_mode = UbloxDataDisplayBacklightDefault;
(ublox->data_display_state).log_format = UbloxLogFormatKML;
(ublox->device_state).odometer_mode = UbloxOdometerModeRunning;
// "suitable for most applications" according to u-blox.
(ublox->device_state).platform_model = UbloxPlatformModelPortable;
ublox->gps_initted = false;
return ublox;
}
void ublox_free(Ublox* ublox) {
furi_assert(ublox);
// no need to stop the worker, plus it causes the app to crash by NULL
// pointer dereference from context in the worker struct
ublox_worker_free(ublox->worker);
view_dispatcher_remove_view(ublox->view_dispatcher, UbloxViewMenu);
submenu_free(ublox->submenu);
view_dispatcher_remove_view(ublox->view_dispatcher, UbloxViewWidget);
widget_free(ublox->widget);
view_dispatcher_remove_view(ublox->view_dispatcher, UbloxViewDataDisplay);
data_display_free(ublox->data_display);
view_dispatcher_remove_view(ublox->view_dispatcher, UbloxViewVariableItemList);
variable_item_list_free(ublox->variable_item_list);
view_dispatcher_remove_view(ublox->view_dispatcher, UbloxViewTextInput);
text_input_free(ublox->text_input);
view_dispatcher_free(ublox->view_dispatcher);
scene_manager_free(ublox->scene_manager);
furi_record_close(RECORD_GUI);
ublox->gui = NULL;
furi_record_close(RECORD_NOTIFICATION);
ublox->notifications = NULL;
furi_record_close(RECORD_STORAGE);
ublox->storage = NULL;
if(ublox->logfile_folder != NULL) {
furi_string_free(ublox->logfile_folder);
}
free(ublox);
}
int32_t ublox_app(void* p) {
UNUSED(p);
Ublox* ublox = ublox_alloc();
scene_manager_next_scene(ublox->scene_manager, UbloxSceneStart);
view_dispatcher_run(ublox->view_dispatcher);
// force restore the default backlight on exit
// TODO: this is breaking the backlight timeout for everything
// else: test by opening ublox, then leaving and opening DAP
// Link. DAP Link should force the backlight on but doesn't.
if ((ublox->data_display_state).backlight_mode == UbloxDataDisplayBacklightOn) {
notification_message_block(ublox->notifications, &sequence_display_backlight_enforce_auto);
}
ublox_free(ublox);
return 0;
}