v1.8.0: Audio 代码重构与低功耗优化 (#943)

* Reconstruct Audio Code

* Remove old IoT implementation

* Add MQTT-UDP documentation

* OTA升级失败时,可以继续使用
This commit is contained in:
Xiaoxia
2025-07-19 22:45:22 +08:00
committed by GitHub
parent 0621578f55
commit 3c71558a5f
173 changed files with 2099 additions and 3265 deletions

View File

@@ -1,60 +0,0 @@
#include <freertos/FreeRTOS.h>
#include <freertos/timers.h>
#include <freertos/task.h>
#include <esp_log.h>
#include "board.h"
#include "boards/common/wifi_board.h"
#include "boards/esp32-cgc-144/config.h"
#include "iot/thing.h"
#include "audio_codec.h"
#define TAG "BoardControl"
namespace iot {
class BoardControl : public Thing {
public:
BoardControl() : Thing("BoardControl", "当前 AI 机器人管理和控制") {
// 修改音量调节
properties_.AddNumberProperty("volume", "当前音量值", [this]() -> int {
auto codec = Board::GetInstance().GetAudioCodec();
return codec->output_volume();
});
// 定义设备可以被远程执行的指令
#if defined(ESP32_CGC_144_lite)
methods_.AddMethod("SetVolume", "设置音量", ParameterList({
Parameter("volume", "0到100之间的整数", kValueTypeNumber, true)
}), [this](const ParameterList& parameters) {
auto codec = Board::GetInstance().GetAudioCodec();
// 获取传入的音量值
int volume = parameters["volume"].number();
// 限制音量值
if (volume > 66) {
volume = 66;
}
codec->SetOutputVolume(static_cast<uint8_t>(volume));
});
#else
methods_.AddMethod("SetVolume", "设置音量", ParameterList({
Parameter("volume", "0到100之间的整数", kValueTypeNumber, true)
}), [this](const ParameterList& parameters) {
auto codec = Board::GetInstance().GetAudioCodec();
// 获取传入的音量值
int volume = parameters["volume"].number();
// 限制音量值
if (volume > 100) {
volume = 100;
}
codec->SetOutputVolume(static_cast<uint8_t>(volume));
});
#endif
}
};
} // namespace iot
DECLARE_THING(BoardControl);

View File

@@ -1,5 +1,5 @@
#include "wifi_board.h"
#include "audio_codecs/no_audio_codec.h"
#include "codecs/no_audio_codec.h"
#include "display/lcd_display.h"
#include "system_reset.h"
#include "application.h"
@@ -8,7 +8,6 @@
#include "power_save_timer.h"
#include "mcp_server.h"
#include "lamp_controller.h"
#include "iot/thing_manager.h"
#include "led/single_led.h"
#include "assets/lang_config.h"
@@ -157,16 +156,8 @@ void InitializePowerManager() {
}
// 物联网初始化,添加对 AI 可见设备
void InitializeIot() {
#if CONFIG_IOT_PROTOCOL_XIAOZHI
auto& thing_manager = iot::ThingManager::GetInstance();
thing_manager.AddThing(iot::CreateThing("Screen"));
thing_manager.AddThing(iot::CreateThing("BoardControl"));
thing_manager.AddThing(iot::CreateThing("Battery"));
thing_manager.AddThing(iot::CreateThing("Lamp"));
#elif CONFIG_IOT_PROTOCOL_MCP
void InitializeTools() {
static LampController lamp(LAMP_GPIO);
#endif
}
public:
@@ -177,7 +168,7 @@ public:
InitializeSpi();
InitializeSt7735Display();
InitializeButtons();
InitializeIot();
InitializeTools();
GetBacklight()->RestoreBrightness();
}