diff --git a/src/FoodDeliveryBase.cpp b/src/FoodDeliveryBase.cpp index ac23ff8..087191e 100644 --- a/src/FoodDeliveryBase.cpp +++ b/src/FoodDeliveryBase.cpp @@ -1,6 +1,6 @@ #include "FoodDeliveryBase.h" -///MQTT和Mavlink业务逻辑控制 -/// @file FoodDeliveryBase.cpp +/// MQTT和Mavlink业务逻辑控制 +/// @file FoodDeliveryBase.cpp /** * @description: 初始化 */ @@ -37,7 +37,7 @@ FoodCube::FoodCube(char *userSsid, char *userPassword, char *userMqttServer, int case 2: Serial2.begin(57600, SERIAL_8N1); // 设置接收缓冲区大小为1024字节 - Serial2.setRxBufferSize(2048); //飞控用 + Serial2.setRxBufferSize(2048); // 飞控用 break; } // 初始化声音模块串口 波特率 @@ -273,6 +273,16 @@ void FoodCube::SetplayvolMax() */ void FoodCube::playText(String str, VoiceVolume vol) { + unsigned long currentTime = millis(); + // 判断是否到了可以执行函数的时间 + if (currentTime - lastRunTime > 3000) + { + lastRunTime = currentTime; // 更新上次执行时间 + } + else + { + return; // 频繁为 达到3秒 不播放声音退出 + } // 拼接音量控制前缀,例如 "[v5]起飞" String vstr = "[v" + String((int)vol) + "]" + str; @@ -307,7 +317,7 @@ void FoodCube::playText(String str, VoiceVolume vol) SWrite(command, sizeof(command), voiceSerial); // 延时等待模块处理,防止连续播放死机 - //delay(300); // 可根据模块处理时间调节 + // delay(300); // 可根据模块处理时间调节 } /** @@ -500,18 +510,16 @@ void FoodCube::mav_request_data() * MAV_DATA_STREAM_ENUM_END=13, */ // 根据从Pixhawk请求的所需信息进行设置 - //const int maxStreams = 1; // 遍历次数 (下面组合的长度) - //const uint8_t MAVStreams[maxStreams] = {MAV_DATA_STREAM_ALL}; // 请求的数据流组合 放到一个对象 后面进行遍历 - //const uint16_t MAVRates[maxStreams] = {0x01}; // 设定发送频率 分别对应上面数据流 ps:0X01 1赫兹 既每秒发送一次 + // const int maxStreams = 1; // 遍历次数 (下面组合的长度) + // const uint8_t MAVStreams[maxStreams] = {MAV_DATA_STREAM_ALL}; // 请求的数据流组合 放到一个对象 后面进行遍历 + // const uint16_t MAVRates[maxStreams] = {0x01}; // 设定发送频率 分别对应上面数据流 ps:0X01 1赫兹 既每秒发送一次 const int maxStreams = 3; - const uint8_t MAVStreams[maxStreams] = { - MAV_DATA_STREAM_EXTENDED_STATUS, - MAV_DATA_STREAM_POSITION, - MAV_DATA_STREAM_EXTRA1 - }; - const uint16_t MAVRates[maxStreams] = {1,1,1}; - - + const uint8_t MAVStreams[maxStreams] = { + MAV_DATA_STREAM_EXTENDED_STATUS, + MAV_DATA_STREAM_POSITION, + MAV_DATA_STREAM_EXTRA1}; + const uint16_t MAVRates[maxStreams] = {1, 1, 1}; + for (int i = 0; i < maxStreams; i++) { // 向飞控发送请求 diff --git a/src/FoodDeliveryBase.h b/src/FoodDeliveryBase.h index f94a965..a52da1b 100644 --- a/src/FoodDeliveryBase.h +++ b/src/FoodDeliveryBase.h @@ -71,6 +71,7 @@ public: V8 = 8, V9 = 9 }; + unsigned long lastRunTime = 0; // playText()上次运行时间戳 void playText(String str, VoiceVolume vol = V1); void SetplayvolMax(); uint8_t chekVoiceMcu();