-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathabout_screen.c
More file actions
86 lines (69 loc) · 2.45 KB
/
Copy pathabout_screen.c
File metadata and controls
86 lines (69 loc) · 2.45 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
#include "config.h"
#include "esp_log.h"
#include "remote/connection.h"
#include "remote/display.h"
#include "remote/espnow.h"
#include "remote/wifi.h"
#include "utilities/screen_utils.h"
#include "utilities/string_utils.h"
#include <remote/remoteinputs.h>
#include <remote/stats.h>
#include <stdio.h>
#include <stdlib.h>
#include <ui/ui.h>
static const char *TAG = "PUBREMOTE-ABOUT_SCREEN";
bool is_about_screen_active() {
lv_obj_t *active_screen = lv_scr_act();
return active_screen == ui_AboutScreen;
}
// Set version label string
static void update_version_info_label() {
char *formattedString;
asprintf(&formattedString, "Version: %d.%d.%d.%s\nHW: %s\nHash: %s", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH,
RELEASE_VARIANT, HW_TYPE, BUILD_ID);
lv_label_set_text(ui_VersionInfoLabel, formattedString);
free(formattedString);
}
static void update_battery_percentage_label() {
char *formattedString;
asprintf(&formattedString, "Battery: %.2fV | %d%%\nState: %s", ((float)remoteStats.remoteBatteryVoltage / 1000.0f),
remoteStats.remoteBatteryPercentage, charge_state_to_string(remoteStats.chargeState));
if (remoteStats.chargeState != CHARGE_STATE_NOT_CHARGING && remoteStats.chargeCurrent > 0) {
asprintf(&formattedString, "%s\nCurrent: %umA", formattedString, remoteStats.chargeCurrent);
}
lv_label_set_text(ui_DebugInfoLabel, formattedString);
free(formattedString);
}
static void about_task(void *pvParameters) {
while (is_about_screen_active()) {
if (LVGL_lock(-1)) {
update_battery_percentage_label();
LVGL_unlock();
}
vTaskDelay(pdMS_TO_TICKS(100));
}
ESP_LOGI(TAG, "About task ended");
vTaskDelete(NULL);
}
// Event handlers
void about_screen_load_start(lv_event_t *e) {
ESP_LOGI(TAG, "About screen load start");
if (LVGL_lock(0)) {
apply_ui_scale(NULL);
update_version_info_label();
update_battery_percentage_label();
lv_obj_add_event_cb(ui_AboutBody, paged_scroll_event_cb, LV_EVENT_SCROLL, ui_AboutHeader);
add_page_scroll_indicators(ui_AboutHeader, ui_AboutBody);
create_navigation_group(ui_AboutFooter);
LVGL_unlock();
}
}
void about_screen_loaded(lv_event_t *e) {
ESP_LOGI(TAG, "About screen loaded");
// Start task to update UI
xTaskCreate(about_task, "about_task", 3072, NULL, 2, NULL);
}
void about_screen_unload_start(lv_event_t *e) {
ESP_LOGI(TAG, "About screen unload start");
lv_obj_remove_event_cb(ui_AboutBody, paged_scroll_event_cb);
}