-
Notifications
You must be signed in to change notification settings - Fork 348
Expand file tree
/
Copy pathapp_setup.cpp
More file actions
182 lines (162 loc) · 4.66 KB
/
Copy pathapp_setup.cpp
File metadata and controls
182 lines (162 loc) · 4.66 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
/*
* SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
#include "app_setup.h"
#include "workers/feature_toggle.h"
#include <hal/hal.h>
#include <mooncake.h>
#include <mooncake_log.h>
#include <assets/assets.h>
#include <stackchan/stackchan.h>
#include <apps/common/common.h>
using namespace mooncake;
using namespace view;
using namespace setup_workers;
AppSetup::AppSetup()
{
// 配置 App 名
setAppInfo().name = "SETUP";
// 配置 App 图标
static auto icon = assets::get_image("icon_setup.bin");
setAppInfo().icon = (void*)&icon;
// 配置 App 主题颜色
static uint32_t theme_color = 0xB3B3B3;
setAppInfo().userData = (void*)&theme_color;
}
void AppSetup::onCreate()
{
mclog::tagInfo(getAppInfo().name, "on create");
// open();
}
void AppSetup::onOpen()
{
mclog::tagInfo(getAppInfo().name, "on open");
// Reset state
_destroy_menu = false;
_need_warm_reset = false;
_magic_count = 0;
_menu_sections = {
{
"Wi-Fi",
{{"Change Wi-Fi",
[&]() {
_destroy_menu = true;
_need_warm_reset = true;
_worker = std::make_unique<WifiSetupWorker>();
}}},
},
{
"Device",
{{"Brightness",
[&]() {
_destroy_menu = true;
_worker = std::make_unique<BrightnessSetupWorker>();
}},
{"Volume",
[&]() {
_destroy_menu = true;
_worker = std::make_unique<VolumeSetupWorker>();
}},
{"Timezone",
[&]() {
_destroy_menu = true;
_worker = std::make_unique<TimezoneWorker>();
}}},
},
{
"Hardware Test",
{{"Servo",
[&]() {
_destroy_menu = true;
_worker = std::make_unique<ZeroCalibrationWorker>();
}},
{"RGB Strip",
[&]() {
_destroy_menu = true;
_worker = std::make_unique<RgbTestWorker>();
}}},
},
{
"Account",
{{"Unbind & Reset",
[&]() {
_destroy_menu = true;
_need_warm_reset = true;
_worker = std::make_unique<AccountWorker>();
}}},
},
{
"Firmware",
{
{fmt::format("Version: {}", common::FirmwareVersion),
[&]() {
_magic_count++;
if (_magic_count >= 10) {
_magic_count = 0;
_destroy_menu = true;
_worker = std::make_unique<FwVersionWorker>();
}
}},
{"Check for Updates",
[&]() {
_destroy_menu = true;
_need_warm_reset = true;
_worker = std::make_unique<SystemUpdateWorker>();
}},
// {"Factory Reset",
// [&]() {
// _destroy_menu = true;
// _worker = std::make_unique<FactoryResetWorker>();
// }}
},
},
{
"Others",
{{"Feature Toggles",
[&]() {
_destroy_menu = true;
_worker = std::make_unique<FeatureToggleWorker>();
}}},
},
};
LvglLockGuard lock;
_menu_page = std::make_unique<view::SelectMenuPage>(_menu_sections);
view::create_home_indicator([&]() { close(); });
view::create_status_bar();
}
void AppSetup::onRunning()
{
LvglLockGuard lock;
if (_menu_page) {
_menu_page->update();
}
if (_destroy_menu) {
_menu_page.reset();
_destroy_menu = false;
}
if (_worker) {
_worker->update();
if (_worker->isDone()) {
_worker.reset();
_menu_page = std::make_unique<view::SelectMenuPage>(_menu_sections);
}
}
GetStackChan().update();
view::update_home_indicator();
view::update_status_bar();
}
void AppSetup::onClose()
{
mclog::tagInfo(getAppInfo().name, "on close");
LvglLockGuard lock;
_menu_sections.clear();
_menu_page.reset();
_worker.reset();
view::destroy_home_indicator();
view::destroy_status_bar();
if (_need_warm_reset) {
GetHAL().requestWarmReboot(6);
}
}