update firmware v1.2.4 (#16)

This commit is contained in:
Forairaaaaa
2026-04-20 16:27:36 +08:00
committed by GitHub
parent 605b575fcc
commit dd34f9e0ec
94 changed files with 3615 additions and 41513 deletions
@@ -13,6 +13,7 @@
#include <hal/hal.h>
#include <functional>
#include <vector>
#include <apps/common/loading_page/loading_page.h>
using namespace uitk;
using namespace uitk::lvgl_cpp;
@@ -294,3 +295,35 @@ void FwVersionWorker::update()
_egg->update();
}
}
SystemUpdateWorker::SystemUpdateWorker()
{
auto loading_page = std::make_unique<view::LoadingPage>(0xF6F6F6, 0x26206A);
GetHAL().lvglUnlock();
// Start network
GetHAL().startNetwork([&](std::string_view msg) {
LvglLockGuard lock;
loading_page->setMessage(msg);
});
// Update Firmware
bool result = GetHAL().updateFirmware([&](std::string_view msg) {
LvglLockGuard lock;
loading_page->setMessage(msg);
});
// Hold the result for a while
GetHAL().delay(3000);
GetHAL().lvglLock();
_is_done = true;
}
SystemUpdateWorker::~SystemUpdateWorker()
{
}
void SystemUpdateWorker::update()
{
}
@@ -0,0 +1,153 @@
/*
* SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
#include "workers.h"
#include <hal/hal.h>
#include <mooncake_log.h>
#include <apps/common/loading_page/loading_page.h>
using namespace uitk::lvgl_cpp;
using namespace setup_workers;
static std::string _tag = "Setup-Account";
AccountWorker::PanelInfo::PanelInfo(lv_obj_t* parent, int posY, std::string_view title, std::string_view info)
{
_panel = std::make_unique<Container>(parent);
_panel->setBgColor(lv_color_hex(0xB8D3FD));
_panel->align(LV_ALIGN_TOP_MID, 0, posY);
_panel->setBorderWidth(0);
_panel->setSize(296, 108);
_panel->setPadding(0, 0, 0, 0);
_panel->setRadius(18);
_panel->removeFlag(LV_OBJ_FLAG_SCROLLABLE);
_label_title = std::make_unique<Label>(_panel->get());
_label_title->setTextFont(&lv_font_montserrat_20);
_label_title->setTextColor(lv_color_hex(0x445B80));
_label_title->align(LV_ALIGN_TOP_MID, 0, 13);
_label_title->setText(title);
_label_info = std::make_unique<Label>(_panel->get());
_label_info->setTextFont(&lv_font_montserrat_20);
_label_info->setTextColor(lv_color_hex(0x07162C));
_label_info->align(LV_ALIGN_CENTER, 0, 14);
_label_info->setWidth(270);
_label_info->setTextAlign(LV_TEXT_ALIGN_CENTER);
_label_info->setText(info);
}
AccountWorker::PageAccount::PageAccount(std::string_view username, std::string_view deviceName)
{
_panel = std::make_unique<Container>(lv_screen_active());
_panel->setBgColor(lv_color_hex(0xF6F6F6));
_panel->align(LV_ALIGN_CENTER, 0, 0);
_panel->setBorderWidth(0);
_panel->setSize(320, 240);
_panel->setPadding(0, 20, 0, 0);
_panel->setRadius(0);
// Title
_label_title = std::make_unique<Label>(_panel->get());
_label_title->setTextFont(&lv_font_montserrat_20);
_label_title->setTextColor(lv_color_hex(0x7E7B9C));
_label_title->align(LV_ALIGN_TOP_MID, 0, 12);
_label_title->setText("ACCOUNT");
_panel_username = std::make_unique<PanelInfo>(_panel->get(), 50, "M5Stack Account:", username);
_panel_device_name = std::make_unique<PanelInfo>(_panel->get(), 174, "Device Name:", deviceName);
// Button
_btn_unbind = std::make_unique<Button>(_panel->get());
apply_button_common_style(*_btn_unbind);
_btn_unbind->align(LV_ALIGN_TOP_MID, 0, 303);
_btn_unbind->setSize(290, 48);
_btn_unbind->setBgColor(lv_color_hex(0xFF8080));
_btn_unbind->label().setText("Unbind and factory reset");
_btn_unbind->label().setTextFont(&lv_font_montserrat_20);
_btn_unbind->label().setTextColor(lv_color_hex(0x731F1F));
_btn_unbind->onClick().connect([this]() { _is_unbind_clicked = true; });
_btn_quit = std::make_unique<Button>(_panel->get());
apply_button_common_style(*_btn_quit);
_btn_quit->align(LV_ALIGN_TOP_MID, 0, 371);
_btn_quit->setSize(290, 48);
_btn_quit->label().setText("Back");
_btn_quit->label().setTextFont(&lv_font_montserrat_20);
_btn_quit->onClick().connect([this]() { _is_quit_clicked = true; });
}
AccountWorker::AccountWorker()
{
// Update account info
{
auto loading_page = std::make_unique<view::LoadingPage>(0xF6F6F6, 0x26206A);
GetHAL().lvglUnlock();
// Start network
GetHAL().startNetwork([&](std::string_view msg) {
LvglLockGuard lock;
loading_page->setMessage(msg);
});
// Update info
bool result = GetHAL().updateAccountInfo([&](std::string_view msg) {
LvglLockGuard lock;
loading_page->setMessage(msg);
});
if (!result) {
GetHAL().delay(5000);
}
GetHAL().lvglLock();
}
auto info = GetHAL().getUserAccountInfo();
_page_account = std::make_unique<PageAccount>(info.username, info.deviceName);
}
AccountWorker::~AccountWorker()
{
}
void AccountWorker::update()
{
if (_page_account) {
if (_page_account->isUnbindClicked()) {
mclog::tagInfo(_tag, "unbind clicked");
_page_account.reset();
// Unbind account
{
auto loading_page = std::make_unique<view::LoadingPage>(0xF6F6F6, 0x26206A);
GetHAL().lvglUnlock();
bool result = GetHAL().unbindAccount([&](std::string_view msg) {
LvglLockGuard lock;
loading_page->setMessage(msg);
});
if (!result) {
GetHAL().delay(5000);
}
GetHAL().lvglLock();
}
// Factory reset
_worker_reset = std::make_unique<FactoryResetWorker>();
} else if (_page_account->isQuitClicked()) {
mclog::tagInfo(_tag, "quit clicked");
_is_done = true;
}
} else if (_worker_reset) {
_worker_reset->update();
if (_worker_reset->isDone()) {
_worker_reset.reset();
_is_done = true;
}
}
}
@@ -31,11 +31,6 @@ WifiSetupWorker::WifiSetupWorker()
avatar->rightEye().setVisible(false);
avatar->mouth().setVisible(false);
GetStackChan().attachAvatar(std::move(avatar));
_app_config_signal_id =
GetHAL().onAppConfigEvent.connect([this](AppConfigEvent event) { _last_app_config_event = event; });
GetHAL().startAppConfigServer();
}
WifiSetupWorker::~WifiSetupWorker()
@@ -69,30 +64,65 @@ void WifiSetupWorker::update_state()
data.title = std::make_unique<Label>(lv_screen_active());
data.title->setTextFont(&lv_font_montserrat_20);
data.title->setTextColor(lv_color_hex(0x7E7B9C));
data.title->align(LV_ALIGN_TOP_MID, 0, 13);
data.title->align(LV_ALIGN_TOP_MID, 0, 0);
data.title->setText("APP SETUP");
data.info = std::make_unique<Label>(lv_screen_active());
data.info->setTextFont(&lv_font_montserrat_14);
data.info->setTextColor(lv_color_hex(0x26206A));
data.info->align(LV_ALIGN_TOP_MID, 0, 27);
data.info->setTextAlign(LV_TEXT_ALIGN_CENTER);
data.info->setText("Install \"StackChan World\" app\nand login to your M5Stack account");
std::string qrcode_text = "https://apps.apple.com/us/app/stackchan-world/id6756086326";
data.qrcode = std::make_unique<Qrcode>(lv_screen_active());
data.qrcode->setSize(150);
data.qrcode->setDarkColor(lv_color_hex(0x221C5B));
data.qrcode->setLightColor(lv_color_hex(0xEDF4FF));
data.qrcode->update(qrcode_text);
data.qrcode->align(LV_ALIGN_CENTER, -72, 12);
data.qrcode_ios = std::make_unique<Qrcode>(lv_screen_active());
data.qrcode_ios->setSize(80);
data.qrcode_ios->setDarkColor(lv_color_hex(0x221C5B));
data.qrcode_ios->setLightColor(lv_color_hex(0xEDF4FF));
data.qrcode_ios->update(qrcode_text);
data.qrcode_ios->align(LV_ALIGN_CENTER, -65, -12);
qrcode_text = "https://play.google.com/store/apps/details?id=com.m5stack.stackchan";
data.qrcode_android = std::make_unique<Qrcode>(lv_screen_active());
data.qrcode_android->setSize(80);
data.qrcode_android->setDarkColor(lv_color_hex(0x221C5B));
data.qrcode_android->setLightColor(lv_color_hex(0xEDF4FF));
data.qrcode_android->update(qrcode_text);
data.qrcode_android->align(LV_ALIGN_CENTER, 65, -12);
data.label_ios = std::make_unique<Label>(lv_screen_active());
data.label_ios->setTextFont(&lv_font_montserrat_14);
data.label_ios->setTextColor(lv_color_hex(0x26206A));
data.label_ios->align(LV_ALIGN_CENTER, -65, 47);
data.label_ios->setText("App Store\n(iOS)");
data.label_ios->setTextAlign(LV_TEXT_ALIGN_CENTER);
data.label_android = std::make_unique<Label>(lv_screen_active());
data.label_android->setTextFont(&lv_font_montserrat_14);
data.label_android->setTextColor(lv_color_hex(0x26206A));
data.label_android->align(LV_ALIGN_CENTER, 65, 47);
data.label_android->setText("Play Store\n(Android)");
data.label_android->setTextAlign(LV_TEXT_ALIGN_CENTER);
data.btn_next = std::make_unique<Button>(lv_screen_active());
apply_button_common_style(*data.btn_next);
data.btn_next->align(LV_ALIGN_CENTER, 79, 73);
data.btn_next->setSize(112, 48);
data.btn_next->align(LV_ALIGN_CENTER, 72, 91);
data.btn_next->setSize(112, 42);
data.btn_next->label().setText("Next");
data.btn_next->onClick().connect([this]() { _state_app_download_data.next_clicked = true; });
data.info = std::make_unique<Label>(lv_screen_active());
data.info->setTextFont(&lv_font_montserrat_20);
data.info->setTextColor(lv_color_hex(0x26206A));
data.info->align(LV_ALIGN_TOP_LEFT, 183, 56);
data.info->setTextAlign(LV_TEXT_ALIGN_LEFT);
data.info->setText("Download\n\"StackChan\"\napp to start\nthe setup");
data.btn_quit = std::make_unique<Button>(lv_screen_active());
apply_button_common_style(*data.btn_quit);
data.btn_quit->align(LV_ALIGN_CENTER, -72, 91);
data.btn_quit->setSize(112, 42);
data.btn_quit->setBgColor(lv_color_hex(0xD4D9E0));
data.btn_quit->label().setText("Back");
data.btn_quit->label().setTextColor(lv_color_hex(0x525064));
data.btn_quit->onClick().connect([this]() { _state_app_download_data.quit_clicked = true; });
}
if (_state_app_download_data.quit_clicked) {
_is_done = true;
}
if (_state_app_download_data.next_clicked) {
@@ -113,6 +143,12 @@ void WifiSetupWorker::update_state()
if (_is_first_in) {
_is_first_in = false;
// Start app config server
_app_config_signal_id =
GetHAL().onAppConfigEvent.connect([this](AppConfigEvent event) { _last_app_config_event = event; });
GetHAL().startAppConfigServer();
auto& data = _state_wait_app_connection_data;
data.panel = std::make_unique<Container>(lv_screen_active());
+269 -3
View File
@@ -9,6 +9,7 @@
#include <mooncake_log.h>
#include <assets/assets.h>
#include <hal/hal.h>
#include <array>
using namespace smooth_ui_toolkit::lvgl_cpp;
using namespace setup_workers;
@@ -36,8 +37,9 @@ public:
_title->align(LV_ALIGN_TOP_MID, 0, 13);
_title->setText("HOME POSITION:");
_img = std::make_unique<Image>(lv_screen_active());
_img->setSrc(&setup_stackchan_front_view);
_img = std::make_unique<Image>(lv_screen_active());
_img_setup_stackchan_front_view = assets::get_image("setup_stackchan_front_view.bin");
_img->setSrc(&_img_setup_stackchan_front_view);
_img->align(LV_ALIGN_CENTER, -74, 15);
_btn_next = std::make_unique<Button>(lv_screen_active());
@@ -62,6 +64,7 @@ private:
std::unique_ptr<uitk::lvgl_cpp::Image> _img;
std::unique_ptr<uitk::lvgl_cpp::Button> _btn_next;
std::unique_ptr<uitk::lvgl_cpp::Label> _info;
lv_image_dsc_t _img_setup_stackchan_front_view;
};
/**
@@ -190,6 +193,269 @@ void ZeroCalibrationWorker::update()
}
}
class PageServoTips : public WorkerBase {
public:
PageServoTips()
{
_panel = std::make_unique<Container>(lv_screen_active());
_panel->setBgColor(lv_color_hex(0xEDF4FF));
_panel->align(LV_ALIGN_CENTER, 0, 0);
_panel->setBorderWidth(0);
_panel->setSize(320, 240);
_panel->setRadius(0);
_title = std::make_unique<Label>(lv_screen_active());
_title->setTextFont(&lv_font_montserrat_20);
_title->setTextColor(lv_color_hex(0x7E7B9C));
_title->align(LV_ALIGN_TOP_MID, 0, 13);
_title->setText("SERVO TEST");
_info = std::make_unique<Label>(lv_screen_active());
_info->setWidth(280);
_info->setTextFont(&lv_font_montserrat_16);
_info->setTextColor(lv_color_hex(0x26206A));
_info->align(LV_ALIGN_CENTER, 0, -18);
_info->setTextAlign(LV_TEXT_ALIGN_CENTER);
_info->setText(
"Put me on a flat stable surface\nand remove your hands.\n\nPower me via the bottom USB-C \nif needed. ");
_btn_skip = std::make_unique<Button>(lv_screen_active());
apply_button_common_style(*_btn_skip);
_btn_skip->align(LV_ALIGN_CENTER, -72, 72);
_btn_skip->setSize(112, 48);
_btn_skip->setBgColor(lv_color_hex(0xD4D9E0));
_btn_skip->label().setText("Skip");
_btn_skip->label().setTextFont(&lv_font_montserrat_20);
_btn_skip->label().setTextColor(lv_color_hex(0x525064));
_btn_skip->onClick().connect([this]() { _is_skip_clicked = true; });
_btn_start = std::make_unique<Button>(lv_screen_active());
apply_button_common_style(*_btn_start);
_btn_start->align(LV_ALIGN_CENTER, 72, 72);
_btn_start->setSize(112, 48);
_btn_start->label().setText("Start");
_btn_start->label().setTextFont(&lv_font_montserrat_20);
_btn_start->onClick().connect([this]() { _is_start_clicked = true; });
}
bool isSkipClicked() const
{
return _is_skip_clicked;
}
bool isStartClicked() const
{
return _is_start_clicked;
}
private:
std::unique_ptr<uitk::lvgl_cpp::Container> _panel;
std::unique_ptr<uitk::lvgl_cpp::Label> _title;
std::unique_ptr<uitk::lvgl_cpp::Label> _info;
std::unique_ptr<uitk::lvgl_cpp::Button> _btn_skip;
std::unique_ptr<uitk::lvgl_cpp::Button> _btn_start;
bool _is_skip_clicked = false;
bool _is_start_clicked = false;
};
class PageServoTest : public WorkerBase {
public:
PageServoTest()
{
_panel = std::make_unique<Container>(lv_screen_active());
_panel->setBgColor(lv_color_hex(0xEDF4FF));
_panel->align(LV_ALIGN_CENTER, 0, 0);
_panel->setBorderWidth(0);
_panel->setSize(320, 240);
_panel->setRadius(0);
_title = std::make_unique<Label>(lv_screen_active());
_title->setTextFont(&lv_font_montserrat_20);
_title->setTextColor(lv_color_hex(0x7E7B9C));
_title->align(LV_ALIGN_TOP_MID, 0, 13);
_title->setText("SERVO TEST");
_info = std::make_unique<Label>(lv_screen_active());
_info->setWidth(280);
_info->setTextFont(&lv_font_montserrat_20);
_info->setTextColor(lv_color_hex(0x26206A));
_info->align(LV_ALIGN_CENTER, 0, -12);
_info->setTextAlign(LV_TEXT_ALIGN_CENTER);
_info->setText("Preparing...");
auto& motion = GetStackChan().motion();
motion.setAutoAngleSyncEnabled(true);
}
void update() override
{
if (_current_step >= _steps.size()) {
_is_done = true;
return;
}
const auto now = GetHAL().millis();
if (!_step_started) {
run_step(_steps[_current_step]);
_step_started = true;
_step_start_tick = now;
return;
}
if (now - _step_start_tick >= _step_delay_ms) {
_current_step++;
_step_started = false;
}
}
private:
enum class Step {
GoHome1,
Left90,
GoHome2,
Right90,
GoHome3,
Up90,
GoHome4,
};
void run_step(Step step)
{
auto& motion = GetStackChan().motion();
switch (step) {
case Step::GoHome1:
case Step::GoHome2:
case Step::GoHome3:
case Step::GoHome4:
_info->setText("Returning to\nthe home position...");
motion.goHome(_move_speed);
break;
case Step::Left90:
_info->setText("Moving left...");
motion.moveWithSpeed(900, 0, _move_speed);
break;
case Step::Right90:
_info->setText("Moving right...");
motion.moveWithSpeed(-900, 0, _move_speed);
break;
case Step::Up90:
_info->setText("Moving up...");
motion.moveWithSpeed(0, 900, _move_speed);
break;
}
}
std::unique_ptr<uitk::lvgl_cpp::Container> _panel;
std::unique_ptr<uitk::lvgl_cpp::Label> _title;
std::unique_ptr<uitk::lvgl_cpp::Label> _info;
static constexpr uint32_t _step_delay_ms = 1800;
static constexpr int _move_speed = 500;
const std::array<Step, 7> _steps = {
Step::GoHome1, Step::Left90, Step::GoHome2, Step::Right90, Step::GoHome3, Step::Up90, Step::GoHome4,
};
size_t _current_step = 0;
uint32_t _step_start_tick = 0;
bool _step_started = false;
};
class PageServoDone : public WorkerBase {
public:
PageServoDone()
{
_panel = std::make_unique<Container>(lv_screen_active());
_panel->setBgColor(lv_color_hex(0xEDF4FF));
_panel->align(LV_ALIGN_CENTER, 0, 0);
_panel->setBorderWidth(0);
_panel->setSize(320, 240);
_panel->setRadius(0);
_title = std::make_unique<Label>(lv_screen_active());
_title->setTextFont(&lv_font_montserrat_20);
_title->setTextColor(lv_color_hex(0x7E7B9C));
_title->align(LV_ALIGN_TOP_MID, 0, 13);
_title->setText("SERVO TEST");
_info = std::make_unique<Label>(lv_screen_active());
_info->setWidth(280);
_info->setTextFont(&lv_font_montserrat_20);
_info->setTextColor(lv_color_hex(0x26206A));
_info->align(LV_ALIGN_CENTER, 0, -16);
_info->setTextAlign(LV_TEXT_ALIGN_CENTER);
_info->setText("Servo test completed.\n");
_btn_retest = std::make_unique<Button>(lv_screen_active());
apply_button_common_style(*_btn_retest);
_btn_retest->align(LV_ALIGN_CENTER, -72, 67);
_btn_retest->setSize(112, 48);
_btn_retest->setBgColor(lv_color_hex(0xD4D9E0));
_btn_retest->label().setText("Retest");
_btn_retest->label().setTextFont(&lv_font_montserrat_20);
_btn_retest->label().setTextColor(lv_color_hex(0x525064));
_btn_retest->onClick().connect([this]() { _is_retest_clicked = true; });
_btn_next = std::make_unique<Button>(lv_screen_active());
apply_button_common_style(*_btn_next);
_btn_next->align(LV_ALIGN_CENTER, 72, 67);
_btn_next->setSize(112, 48);
_btn_next->label().setText("Next");
_btn_next->label().setTextFont(&lv_font_montserrat_20);
_btn_next->onClick().connect([this]() { _is_next_clicked = true; });
}
bool isRetestClicked() const
{
return _is_retest_clicked;
}
bool isNextClicked() const
{
return _is_next_clicked;
}
private:
std::unique_ptr<uitk::lvgl_cpp::Container> _panel;
std::unique_ptr<uitk::lvgl_cpp::Label> _title;
std::unique_ptr<uitk::lvgl_cpp::Label> _info;
std::unique_ptr<uitk::lvgl_cpp::Button> _btn_retest;
std::unique_ptr<uitk::lvgl_cpp::Button> _btn_next;
bool _is_retest_clicked = false;
bool _is_next_clicked = false;
};
ServoTestWorker::ServoTestWorker()
{
_page_tips = std::make_unique<PageServoTips>();
}
void ServoTestWorker::update()
{
if (_page_tips) {
auto* page = static_cast<PageServoTips*>(_page_tips.get());
if (page->isSkipClicked()) {
_page_tips.reset();
_is_done = true;
} else if (page->isStartClicked()) {
_page_tips.reset();
_page_test = std::make_unique<PageServoTest>();
}
} else if (_page_test) {
_page_test->update();
if (_page_test->isDone()) {
_page_test.reset();
_page_done = std::make_unique<PageServoDone>();
}
} else if (_page_done) {
auto* page = static_cast<PageServoDone*>(_page_done.get());
if (page->isRetestClicked()) {
_page_done.reset();
_page_test = std::make_unique<PageServoTest>();
} else if (page->isNextClicked()) {
_page_done.reset();
_is_done = true;
}
}
}
struct RgbColorEntry {
std::string name;
uint8_t r;
@@ -235,7 +501,7 @@ RgbTestWorker::RgbTestWorker()
auto btn_quit = std::make_unique<Button>(*_panel);
apply_button_common_style(*btn_quit);
btn_quit->setSize(200, 50);
btn_quit->label().setText("Quit");
btn_quit->label().setText("Back");
btn_quit->onClick().connect([this]() { _is_done = true; });
_buttons.push_back(std::move(btn_quit));
}
@@ -67,6 +67,15 @@ void StartupWorker::update()
_is_done = true;
} else if (_page_startup->isStartClicked()) {
_page_startup.reset();
mclog::tagInfo(_tag, "start servo test");
_worker_servo_test = std::make_unique<ServoTestWorker>();
}
}
// Servo test
else if (_worker_servo_test) {
_worker_servo_test->update();
if (_worker_servo_test->isDone()) {
_worker_servo_test.reset();
mclog::tagInfo(_tag, "start wifi setup");
_worker_wifi = std::make_unique<WifiSetupWorker>();
}
@@ -76,8 +85,8 @@ void StartupWorker::update()
_worker_wifi->update();
if (_worker_wifi->isDone()) {
_worker_wifi.reset();
mclog::tagInfo(_tag, "startup done");
_is_done = true;
mclog::tagInfo(_tag, "startup back");
_page_startup = std::make_unique<PageStartup>();
}
}
}
@@ -33,6 +33,74 @@ static const std::vector<TimezoneOption_t> _timezone_list = {
{"Tokyo (UTC+9)", "JST-9"}, {"Sydney (UTC+10)", "AEST-10"}, {"Noumea (UTC+11)", "SBT-11"},
{"Auckland (UTC+12)", "NZST-12"}, {"Fiji (UTC+13)", "FJT-13"}, {"Line Islands (UTC+14)", "LINT-14"}};
VolumeSetupWorker::VolumeSetupWorker()
{
mclog::info("VolumeSetupWorker start");
for (int volume = 0; volume <= 100; volume += 5) {
_volume_levels.push_back(volume);
}
uint8_t current_volume = GetHAL().getSpeakerVolume();
int current_index = _volume_levels.size() - 1;
for (size_t i = 0; i < _volume_levels.size(); i++) {
if (_volume_levels[i] >= current_volume) {
current_index = static_cast<int>(i);
break;
}
}
_panel = std::make_unique<Container>(lv_screen_active());
_panel->setBgColor(lv_color_hex(0xEDF4FF));
_panel->align(LV_ALIGN_CENTER, 0, 0);
_panel->setBorderWidth(0);
_panel->setSize(320, 240);
_panel->setRadius(0);
_panel->removeFlag(LV_OBJ_FLAG_SCROLLABLE);
_label_volume = std::make_unique<Label>(*_panel);
_label_volume->setText(fmt::format("{}%", _volume_levels[current_index]));
_label_volume->setTextFont(&lv_font_montserrat_24);
_label_volume->setTextColor(lv_color_hex(0x26206A));
_label_volume->align(LV_ALIGN_CENTER, 0, -70);
_slider = std::make_unique<Slider>(*_panel);
_slider->align(LV_ALIGN_CENTER, 0, -12);
_slider->setRange(0, _volume_levels.size() - 1);
_slider->setSize(250, 18);
_slider->setBgColor(lv_color_hex(0x615B9E), LV_PART_KNOB);
_slider->setBgColor(lv_color_hex(0x615B9E), LV_PART_INDICATOR);
_slider->setBgColor(lv_color_hex(0xB8D3FD), LV_PART_MAIN);
_slider->setBgOpa(255);
_slider->setValue(current_index);
_slider->onValueChanged().connect([this](int32_t value) {
_label_volume->setText(fmt::format("{}%", _volume_levels[value]));
_target_volume = _volume_levels[value];
});
_btn_confirm = std::make_unique<Button>(*_panel);
apply_button_common_style(*_btn_confirm);
_btn_confirm->align(LV_ALIGN_CENTER, 0, 60);
_btn_confirm->setSize(150, 50);
_btn_confirm->label().setText("Confirm");
_btn_confirm->onClick().connect([this]() { _is_done = true; });
}
VolumeSetupWorker::~VolumeSetupWorker()
{
auto volume = _volume_levels[_slider->getValue()];
mclog::tagInfo(_tag, "final volume: {}", volume);
GetHAL().setSpeakerVolume(volume, true);
}
void VolumeSetupWorker::update()
{
if (_target_volume != -1) {
GetHAL().setSpeakerVolume(_target_volume, false);
_target_volume = -1;
}
}
TimezoneWorker::TimezoneWorker()
{
_panel = std::make_unique<uitk::lvgl_cpp::Container>(lv_screen_active());
+110 -2
View File
@@ -10,6 +10,7 @@
#include <hal/hal.h>
#include <cstdint>
#include <memory>
#include <string_view>
namespace setup_workers {
@@ -48,6 +49,21 @@ private:
std::unique_ptr<WorkerBase> _page_calibration;
};
/**
* @brief
*
*/
class ServoTestWorker : public WorkerBase {
public:
ServoTestWorker();
void update() override;
private:
std::unique_ptr<WorkerBase> _page_tips;
std::unique_ptr<WorkerBase> _page_test;
std::unique_ptr<WorkerBase> _page_done;
};
/**
* @brief
*
@@ -79,19 +95,29 @@ private:
struct StateAppDownloadData {
std::unique_ptr<uitk::lvgl_cpp::Container> panel;
std::unique_ptr<uitk::lvgl_cpp::Label> title;
std::unique_ptr<uitk::lvgl_cpp::Qrcode> qrcode;
std::unique_ptr<uitk::lvgl_cpp::Qrcode> qrcode_ios;
std::unique_ptr<uitk::lvgl_cpp::Qrcode> qrcode_android;
std::unique_ptr<uitk::lvgl_cpp::Label> label_ios;
std::unique_ptr<uitk::lvgl_cpp::Label> label_android;
std::unique_ptr<uitk::lvgl_cpp::Button> btn_next;
std::unique_ptr<uitk::lvgl_cpp::Button> btn_quit;
std::unique_ptr<uitk::lvgl_cpp::Label> info;
bool next_clicked = false;
bool quit_clicked = false;
void reset()
{
panel.reset();
title.reset();
qrcode.reset();
qrcode_ios.reset();
qrcode_android.reset();
label_ios.reset();
label_android.reset();
btn_next.reset();
btn_quit.reset();
info.reset();
next_clicked = false;
quit_clicked = false;
}
};
StateAppDownloadData _state_app_download_data;
@@ -170,6 +196,7 @@ public:
private:
std::unique_ptr<PageStartup> _page_startup;
std::unique_ptr<ServoTestWorker> _worker_servo_test;
std::unique_ptr<WifiSetupWorker> _worker_wifi;
};
@@ -187,6 +214,17 @@ private:
uint32_t _last_tick = 0;
};
/**
* @brief
*
*/
class SystemUpdateWorker : public WorkerBase {
public:
SystemUpdateWorker();
~SystemUpdateWorker();
void update() override;
};
/**
* @brief
*
@@ -205,6 +243,25 @@ private:
int32_t _target_brightness = -1;
};
/**
* @brief
*
*/
class VolumeSetupWorker : public WorkerBase {
public:
VolumeSetupWorker();
~VolumeSetupWorker();
void update() override;
private:
std::unique_ptr<uitk::lvgl_cpp::Container> _panel;
std::unique_ptr<uitk::lvgl_cpp::Label> _label_volume;
std::unique_ptr<uitk::lvgl_cpp::Slider> _slider;
std::unique_ptr<uitk::lvgl_cpp::Button> _btn_confirm;
std::vector<uint8_t> _volume_levels;
int32_t _target_volume = -1;
};
/**
* @brief
*
@@ -247,4 +304,55 @@ private:
void update_ui();
};
/**
* @brief
*
*/
class AccountWorker : public WorkerBase {
public:
class PanelInfo {
public:
PanelInfo(lv_obj_t* parent, int posY, std::string_view title, std::string_view info);
private:
std::unique_ptr<uitk::lvgl_cpp::Container> _panel;
std::unique_ptr<uitk::lvgl_cpp::Label> _label_title;
std::unique_ptr<uitk::lvgl_cpp::Label> _label_info;
};
class PageAccount {
public:
PageAccount(std::string_view username, std::string_view deviceName);
bool isUnbindClicked() const
{
return _is_unbind_clicked;
}
bool isQuitClicked() const
{
return _is_quit_clicked;
}
private:
std::unique_ptr<uitk::lvgl_cpp::Container> _panel;
std::unique_ptr<uitk::lvgl_cpp::Label> _label_title;
std::unique_ptr<PanelInfo> _panel_username;
std::unique_ptr<PanelInfo> _panel_device_name;
std::unique_ptr<uitk::lvgl_cpp::Button> _btn_unbind;
std::unique_ptr<uitk::lvgl_cpp::Button> _btn_quit;
bool _is_unbind_clicked = false;
bool _is_quit_clicked = false;
};
AccountWorker();
~AccountWorker();
void update() override;
private:
std::unique_ptr<PageAccount> _page_account;
std::unique_ptr<FactoryResetWorker> _worker_reset;
};
} // namespace setup_workers