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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// 添加 C 接口头文件
extern "C" {
#include "drv_es8388.h"
#include <rtdevice.h>
}


Expand All @@ -12,10 +13,11 @@ namespace iot {

class Speaker : public Thing {
public:
Speaker() : Thing("Speaker", "扬声器") {
Speaker() : Thing("Speaker", "扬声器"), current_volume_(60) {
sound_dev_ = rt_device_find("sound0");
// 定义属性:volume(当前音量值)
properties_.AddNumberProperty("volume", "当前音量值(0到100之间)", [this]() -> int {
return es8388_volume_get();
return current_volume_;
});

// 定义方法:SetVolume(设置音量)
Expand All @@ -26,15 +28,24 @@ class Speaker : public Thing {
if(volume > 100) {
volume = 100;
}
es8388_volume_set(volume);
struct rt_audio_caps caps;
caps.main_type = AUDIO_TYPE_MIXER;
caps.sub_type = AUDIO_MIXER_VOLUME;
caps.udata.value = volume;
rt_device_control(sound_dev_, AUDIO_CTL_CONFIGURE, &caps);
current_volume_ = volume;
});

// 新增方法:GetVolume(获取音量)
methods_.AddMethod("GetVolume", "获取当前音量", ParameterList(),
[this](const ParameterList&) {
return es8388_volume_get(); // 直接返回音频服务获取的值
return current_volume_;
});
}

private:
rt_device_t sound_dev_;
int current_volume_;
};

} // namespace iot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#define NETWORK_CHECK_DELAY_MS 500
#define RETRY_DELAY_BASE_MS 1000
#define RETRY_DELAY_INCREMENT_MS 200
#define TTS_STOP_DELAY_MS 200
#define TTS_STOP_DELAY_MS 500
#define BUTTON_DEBOUNCE_MS 20
#define WAKEWORD_INIT_FLAG_RESET 0
#define TTS_SENTENCE_TIMEOUT_MS 6000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void xz_sound_init(void)
struct rt_audio_caps sound_dev_arg;
sound_dev_arg.main_type = AUDIO_TYPE_OUTPUT;
sound_dev_arg.sub_type = AUDIO_DSP_PARAM;
sound_dev_arg.udata.value = 30;
struct rt_audio_configure audio_configure;
audio_configure.channels = 1;
audio_configure.samplebits = 16;
Expand All @@ -61,6 +62,12 @@ int xz_mic_init(void)
thiz->rt_mic_dev = rt_device_find("mic0");
thiz->is_rx_enable = 0; /* Initialize as disabled */

struct rt_audio_caps mic_dev_arg;
mic_dev_arg.main_type = AUDIO_TYPE_MIXER;
mic_dev_arg.sub_type = AUDIO_MIXER_VOLUME;
mic_dev_arg.udata.value = 30;
rt_device_control(thiz->rt_mic_dev, AUDIO_CTL_CONFIGURE, &mic_dev_arg);

mic_event = rt_event_create("mic_evt", RT_IPC_FLAG_FIFO);
RT_ASSERT(mic_event != RT_NULL);
LOG_I("xz_mic_init");
Expand Down