【类 型】:fix

【原  因】:防止播放声音函数 频繁执行
【过  程】:记录时间戳 两次执行之间需要超过3秒
【影  响】:

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
This commit is contained in:
air 2025-05-18 21:58:13 +08:00
parent 5fd6ca6eb9
commit 52c445f981
2 changed files with 24 additions and 15 deletions

View File

@ -273,6 +273,16 @@ void FoodCube::SetplayvolMax()
*/ */
void FoodCube::playText(String str, VoiceVolume vol) void FoodCube::playText(String str, VoiceVolume vol)
{ {
unsigned long currentTime = millis();
// 判断是否到了可以执行函数的时间
if (currentTime - lastRunTime > 3000)
{
lastRunTime = currentTime; // 更新上次执行时间
}
else
{
return; // 频繁为 达到3秒 不播放声音退出
}
// 拼接音量控制前缀,例如 "[v5]起飞" // 拼接音量控制前缀,例如 "[v5]起飞"
String vstr = "[v" + String((int)vol) + "]" + str; String vstr = "[v" + String((int)vol) + "]" + str;
@ -507,11 +517,9 @@ void FoodCube::mav_request_data()
const uint8_t MAVStreams[maxStreams] = { const uint8_t MAVStreams[maxStreams] = {
MAV_DATA_STREAM_EXTENDED_STATUS, MAV_DATA_STREAM_EXTENDED_STATUS,
MAV_DATA_STREAM_POSITION, MAV_DATA_STREAM_POSITION,
MAV_DATA_STREAM_EXTRA1 MAV_DATA_STREAM_EXTRA1};
};
const uint16_t MAVRates[maxStreams] = {1, 1, 1}; const uint16_t MAVRates[maxStreams] = {1, 1, 1};
for (int i = 0; i < maxStreams; i++) for (int i = 0; i < maxStreams; i++)
{ {
// 向飞控发送请求 // 向飞控发送请求

View File

@ -71,6 +71,7 @@ public:
V8 = 8, V8 = 8,
V9 = 9 V9 = 9
}; };
unsigned long lastRunTime = 0; // playText()上次运行时间戳
void playText(String str, VoiceVolume vol = V1); void playText(String str, VoiceVolume vol = V1);
void SetplayvolMax(); void SetplayvolMax();
uint8_t chekVoiceMcu(); uint8_t chekVoiceMcu();