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
+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));
}