forked from m5stack/M5Tab5-UserDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings_ui.c
More file actions
99 lines (87 loc) · 2.35 KB
/
settings_ui.c
File metadata and controls
99 lines (87 loc) · 2.35 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
/*
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
#include "settings_ui/settings_ui.h"
#include "esp_log.h"
#include "esp_timer.h"
static const char* TAG = "settings_ui";
static esp_timer_handle_t s_dim_timer = NULL;
static settings_ui_runtime_t* s_dim_state = NULL;
static void dim_timer_callback(void* arg)
{
(void)arg;
settings_ui_runtime_t* state = s_dim_state;
if (!state)
{
return;
}
state->dimming_active = true;
ESP_LOGI(
TAG, "Screen dim timer fired (%u seconds)", state->last_applied.screen_timeout_seconds);
}
esp_err_t settings_ui_apply(const app_cfg_t* cfg, settings_ui_runtime_t* state)
{
if (!cfg || !state)
{
return ESP_ERR_INVALID_ARG;
}
state->last_applied = cfg->ui;
state->dimming_active = false;
switch (cfg->ui.theme)
{
case APP_CFG_UI_THEME_LIGHT:
ESP_LOGI(
TAG, "Applying light theme with brightness %u", (unsigned int)cfg->ui.brightness);
break;
case APP_CFG_UI_THEME_DARK:
ESP_LOGI(
TAG, "Applying dark theme with brightness %u", (unsigned int)cfg->ui.brightness);
break;
case APP_CFG_UI_THEME_AUTO:
default:
ESP_LOGI(
TAG, "Applying auto theme with brightness %u", (unsigned int)cfg->ui.brightness);
break;
}
return ESP_OK;
}
esp_err_t settings_ui_schedule_dim(settings_ui_runtime_t* state, uint32_t timeout_ms)
{
if (!state)
{
return ESP_ERR_INVALID_ARG;
}
s_dim_state = state;
if (!s_dim_timer)
{
const esp_timer_create_args_t args = {
.callback = &dim_timer_callback,
.arg = NULL,
.name = "ui_dim",
};
esp_err_t err = esp_timer_create(&args, &s_dim_timer);
if (err != ESP_OK)
{
return err;
}
}
if (esp_timer_is_active(s_dim_timer))
{
esp_timer_stop(s_dim_timer);
}
state->dimming_active = false;
return esp_timer_start_once(s_dim_timer, timeout_ms * 1000ULL);
}
void settings_ui_cancel_dim(settings_ui_runtime_t* state)
{
if (s_dim_timer && esp_timer_is_active(s_dim_timer))
{
esp_timer_stop(s_dim_timer);
}
if (state == s_dim_state)
{
s_dim_state = NULL;
}
}