Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion firmware/main/apps/app_setup/workers/ai_agent.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -207,9 +207,36 @@ XiaozhiGeneralWorker::XiaozhiGeneralWorker()
_slider_idle_motion->setValue(current_index);
_slider_idle_motion->onValueChanged().connect([this](int32_t value) { _pending_idle_motion_index = value; });

_panel_startup = std::make_unique<Container>(_panel->get());
_panel_startup->setSize(296, 120);
_panel_startup->align(LV_ALIGN_TOP_MID, 0, 196);
_panel_startup->setBgColor(lv_color_hex(0xD2E3FF));
_panel_startup->setBorderWidth(0);
_panel_startup->setRadius(18);
_panel_startup->setPadding(0, 0, 0, 0);
_panel_startup->removeFlag(LV_OBJ_FLAG_SCROLLABLE);

_label_startup_title = std::make_unique<Label>(_panel_startup->get());
_label_startup_title->setText("Start AI Agent on boot:");
_label_startup_title->setTextFont(&lv_font_montserrat_16);
_label_startup_title->setTextColor(lv_color_hex(0x26206A));
_label_startup_title->setWidth(260);
_label_startup_title->setTextAlign(LV_TEXT_ALIGN_CENTER);
_label_startup_title->align(LV_ALIGN_TOP_MID, 0, 18);

_switch_start_ai_on_boot = std::make_unique<Switch>(_panel_startup->get());
_switch_start_ai_on_boot->setSize(64, 36);
_switch_start_ai_on_boot->align(LV_ALIGN_TOP_MID, 0, 66);
_switch_start_ai_on_boot->setBgColor(lv_color_hex(0xB8D3FD), LV_PART_MAIN);
_switch_start_ai_on_boot->setBgColor(lv_color_hex(0x615B9E), LV_PART_INDICATOR | LV_STATE_CHECKED);
_switch_start_ai_on_boot->setBgColor(lv_color_hex(0xFFFFFF), LV_PART_KNOB);
if (_config.startAiAgentOnBoot) {
_switch_start_ai_on_boot->addState(LV_STATE_CHECKED);
}

_btn_confirm = std::make_unique<Button>(_panel->get());
apply_button_common_style(*_btn_confirm);
_btn_confirm->align(LV_ALIGN_TOP_MID, 0, 196);
_btn_confirm->align(LV_ALIGN_TOP_MID, 0, 326);
_btn_confirm->setSize(290, 50);
_btn_confirm->label().setText("Confirm");
_btn_confirm->onClick().connect([this]() { _confirm_flag = true; });
Expand All@@ -227,6 +254,7 @@ void XiaozhiGeneralWorker::update()

if (_confirm_flag) {
_confirm_flag = false;
_config.startAiAgentOnBoot = _switch_start_ai_on_boot->getValue();
GetHAL().setXiaozhiConfig(_config);
mclog::tagInfo(_tag, "xiaozhi config updated: idleRandomMovementLevel={} ({})", _config.idleRandomMovementLevel,
_idle_motion_level_labels[_config.idleRandomMovementLevel]);
Expand Down
3 changes: 3 additions & 0 deletions firmware/main/apps/app_setup/workers/workers.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -341,9 +341,12 @@ class XiaozhiGeneralWorker : public WorkerBase {

std::unique_ptr<uitk::lvgl_cpp::Container> _panel;
std::unique_ptr<uitk::lvgl_cpp::Container> _panel_general;
std::unique_ptr<uitk::lvgl_cpp::Container> _panel_startup;
std::unique_ptr<uitk::lvgl_cpp::Label> _label_idle_motion_title;
std::unique_ptr<uitk::lvgl_cpp::Label> _label_idle_motion_value;
std::unique_ptr<uitk::lvgl_cpp::Slider> _slider_idle_motion;
std::unique_ptr<uitk::lvgl_cpp::Label> _label_startup_title;
std::unique_ptr<uitk::lvgl_cpp::Switch> _switch_start_ai_on_boot;
std::unique_ptr<uitk::lvgl_cpp::Button> _btn_confirm;

XiaozhiConfig_t _config;
Expand Down
4 changes: 4 additions & 0 deletions firmware/main/hal/board/hal_bridge.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,6 +24,7 @@ static constexpr std::string_view _xiaozhi_config_nvs_ns
static constexpr std::string_view _xiaozhi_config_idle_shutdown_time_key = "idle_sec";
static constexpr std::string_view _xiaozhi_config_allow_shutdown_when_charging_key = "ext_pwr";
static constexpr std::string_view _xiaozhi_config_idle_random_movement_key = "idle_lv";
static constexpr std::string_view _xiaozhi_config_start_ai_agent_on_boot_key = "boot_ai";

namespace hal_bridge {

Expand DownExpand Up@@ -129,6 +130,8 @@ XiaozhiConfig_t get_xiaozhi_config()
settings.GetBool(_xiaozhi_config_allow_shutdown_when_charging_key.data(), config.allowShutdownWhenCharging);
config.idleRandomMovementLevel =
settings.GetInt(_xiaozhi_config_idle_random_movement_key.data(), config.idleRandomMovementLevel);
config.startAiAgentOnBoot =
settings.GetBool(_xiaozhi_config_start_ai_agent_on_boot_key.data(), config.startAiAgentOnBoot);

return config;
}
Expand All@@ -139,6 +142,7 @@ void set_xiaozhi_config(const XiaozhiConfig_t& config)
settings.SetInt(_xiaozhi_config_idle_shutdown_time_key.data(), config.idleShutdownTimeSeconds);
settings.SetBool(_xiaozhi_config_allow_shutdown_when_charging_key.data(), config.allowShutdownWhenCharging);
settings.SetInt(_xiaozhi_config_idle_random_movement_key.data(), config.idleRandomMovementLevel);
settings.SetBool(_xiaozhi_config_start_ai_agent_on_boot_key.data(), config.startAiAgentOnBoot);
}

void app_play_sound(const std::string_view& sound)
Expand Down
1 change: 1 addition & 0 deletions firmware/main/hal/board/hal_bridge.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,6 +28,7 @@ struct XiaozhiConfig_t {
uint32_t idleShutdownTimeSeconds = 600;
bool allowShutdownWhenCharging = false;
uint8_t idleRandomMovementLevel = 2;
bool startAiAgentOnBoot = false;
};

void lock();
Expand Down
2 changes: 2 additions & 0 deletions firmware/main/hal/hal.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -209,6 +209,7 @@ XiaozhiConfig_t Hal::getXiaozhiConfig()
.idleShutdownTimeSeconds = bridge_config.idleShutdownTimeSeconds,
.allowShutdownWhenCharging = bridge_config.allowShutdownWhenCharging,
.idleRandomMovementLevel = bridge_config.idleRandomMovementLevel,
.startAiAgentOnBoot = bridge_config.startAiAgentOnBoot,
};
}

Expand All@@ -218,6 +219,7 @@ void Hal::setXiaozhiConfig(XiaozhiConfig_t config)
.idleShutdownTimeSeconds = config.idleShutdownTimeSeconds,
.allowShutdownWhenCharging = config.allowShutdownWhenCharging,
.idleRandomMovementLevel = config.idleRandomMovementLevel,
.startAiAgentOnBoot = config.startAiAgentOnBoot,
});
}

Expand Down
1 change: 1 addition & 0 deletions firmware/main/hal/hal.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -118,6 +118,7 @@ struct XiaozhiConfig_t {
uint32_t idleShutdownTimeSeconds = 600;
bool allowShutdownWhenCharging = false;
uint8_t idleRandomMovementLevel = 2;
bool startAiAgentOnBoot = false;
};

/**
Expand Down
51 changes: 28 additions & 23 deletions firmware/main/main.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,31 +26,36 @@ extern "C" void app_main(void)
ui_hal::on_delay([](uint32_t ms) { GetHAL().delay(ms); });
ui_hal::on_get_tick([]() { return GetHAL().millis(); });

// Install apps
GetMooncake().installApp(std::make_unique<AppLauncher>());
GetMooncake().installApp(std::make_unique<AppAiAgent>());
GetMooncake().installApp(std::make_unique<AppAvatar>());
GetMooncake().installApp(std::make_unique<AppEspnowControl>());
GetMooncake().installApp(std::make_unique<AppAppCenter>());
GetMooncake().installApp(std::make_unique<AppEzdata>());
GetMooncake().installApp(std::make_unique<AppDance>());
GetMooncake().installApp(std::make_unique<AppSetup>());

// Main loop
while (1) {
GetHAL().feedTheDog();
GetHAL().updateHeapStatusLog();

GetMooncake().update();

if (GetHAL().isXiaozhiStartRequested()) {
break;
const bool skip_mooncake =
GetHAL().getXiaozhiConfig().startAiAgentOnBoot && GetHAL().getWarmRebootTarget() < 0;

if (!skip_mooncake) {
// Install apps
GetMooncake().installApp(std::make_unique<AppLauncher>());
GetMooncake().installApp(std::make_unique<AppAiAgent>());
GetMooncake().installApp(std::make_unique<AppAvatar>());
GetMooncake().installApp(std::make_unique<AppEspnowControl>());
GetMooncake().installApp(std::make_unique<AppAppCenter>());
GetMooncake().installApp(std::make_unique<AppEzdata>());
GetMooncake().installApp(std::make_unique<AppDance>());
GetMooncake().installApp(std::make_unique<AppSetup>());

// Main loop
while (1) {
GetHAL().feedTheDog();
GetHAL().updateHeapStatusLog();

GetMooncake().update();

if (GetHAL().isXiaozhiStartRequested()) {
break;
}
}
}

// Uninstall all apps and destroy mooncake
GetMooncake().uninstallAllApps();
DestroyMooncake();
// Uninstall all apps and destroy mooncake
GetMooncake().uninstallAllApps();
DestroyMooncake();
}

// Start xiaozhi, never returns
GetHAL().startXiaozhi();
Expand Down