forked from xiaozhi/xiaozhi-esp32
更新ESP32 CGC MCP控制方式,添加一个ESP32 CGC 144的开发板 (#736)
* Update README.md * Update config.h 增加MCP控制方式 * Update esp32_cgc_board.cc 增加MCP控制方式 * Update CMakeLists.txt 增加ESP32 CGC 144开发板 * Update Kconfig.projbuild 增加ESP32 CGC 144开发板 * Create README.md 增加ESP32 CGC 144开发板 * Add files via upload * Update config.h 修改注释
This commit is contained in:
60
main/boards/esp32-cgc-144/board_control.cc
Normal file
60
main/boards/esp32-cgc-144/board_control.cc
Normal file
@@ -0,0 +1,60 @@
|
||||
#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);
|
||||
Reference in New Issue
Block a user