diff --git a/src/ConRIG/Configs/RadioConfig.h b/src/ConRIG/Configs/RadioConfig.h index 735ae3f51db71ad76c0ebe6a8ce151bdc35a39b9..af7f66cdea1a9a808c22f1cdf18404ea3e97bd82 100644 --- a/src/ConRIG/Configs/RadioConfig.h +++ b/src/ConRIG/Configs/RadioConfig.h @@ -50,6 +50,12 @@ constexpr uint8_t MAV_COMPONENT_ID = 96; // Periodic telemetries frequency constexpr Hertz PING_GSE_PERIOD = 2_hz; +// Audio feedback message threshold +constexpr auto AUDIO_FEEDBACK_THRESHOLD = 10; +// Value to reset the message counter to, to avoid long pauses without audio +// feedback after startup or disarming +constexpr auto AUDIO_FEEDBACK_RESET_VALUE = AUDIO_FEEDBACK_THRESHOLD * 4 / 5; + } // namespace Radio } // namespace Config } // namespace ConRIG diff --git a/src/ConRIG/Radio/Radio.cpp b/src/ConRIG/Radio/Radio.cpp index cb88b002b6c0144edfdb1d90bde806f7e54c1b92..f9e218372658f5aea704a04a780a7963e658f7a7 100644 --- a/src/ConRIG/Radio/Radio.cpp +++ b/src/ConRIG/Radio/Radio.cpp @@ -63,10 +63,18 @@ void Radio::handleMessage(const mavlink_message_t& msg) case MAVLINK_MSG_ID_GSE_TM: { int armingState = mavlink_msg_gse_tm_get_arming_state(&msg); - messagesReceived += 1; + bool wasArmed = isArmed; + bool isNowArmed = armingState == 1; + isArmed = isNowArmed; + + // Reset the message counter to a value higher than zero to avoid + // long pauses without audio feedback after disarming + if (wasArmed && !isNowArmed) + messagesReceived = Config::Radio::AUDIO_FEEDBACK_RESET_VALUE; + else + messagesReceived += 1; - isArmed = armingState == 1; - if (armingState == 1) + if (isNowArmed) getModule<Buttons>()->enableIgnition(); else getModule<Buttons>()->disableIgnition(); @@ -144,7 +152,8 @@ void Radio::loopBuzzer() Thread::sleep(100); // Doesn't matter the precision, the important thing is // the beep, this is because an atomic is used - if ((!isArmed && messagesReceived > 10) || + if ((!isArmed && + messagesReceived > Config::Radio::AUDIO_FEEDBACK_THRESHOLD) || (isArmed && messagesReceived > 0)) { messagesReceived = 0; diff --git a/src/ConRIG/Radio/Radio.h b/src/ConRIG/Radio/Radio.h index 949df5f99e067bdcd269e69a34599eddd98a4694..29197d28011941501edad0de994f1d06b94e7954 100644 --- a/src/ConRIG/Radio/Radio.h +++ b/src/ConRIG/Radio/Radio.h @@ -79,7 +79,8 @@ private: std::thread buzzerLooper; - std::atomic<uint8_t> messagesReceived{0}; + std::atomic<uint8_t> messagesReceived{ + Config::Radio::AUDIO_FEEDBACK_RESET_VALUE}; std::atomic<bool> isArmed{false}; Boardcore::PrintLogger logger = Boardcore::Logging::getLogger("radio"); diff --git a/src/ConRIGv2/Configs/RadioConfig.h b/src/ConRIGv2/Configs/RadioConfig.h index 8f2695e6784a4d18966dbb0ad481efeb2eebe4bb..b6065aa5e0652ef0d3aeaa43bc9316b47d37160a 100644 --- a/src/ConRIGv2/Configs/RadioConfig.h +++ b/src/ConRIGv2/Configs/RadioConfig.h @@ -50,6 +50,12 @@ constexpr uint8_t MAV_COMPONENT_ID = 96; // Periodic telemetries frequency constexpr Hertz PING_GSE_PERIOD = 2_hz; +// Audio feedback message threshold +constexpr auto AUDIO_FEEDBACK_THRESHOLD = 10; +// Value to reset the message counter to, to avoid long pauses without audio +// feedback after startup or disarming +constexpr auto AUDIO_FEEDBACK_RESET_VALUE = AUDIO_FEEDBACK_THRESHOLD * 4 / 5; + } // namespace Radio } // namespace Config } // namespace ConRIGv2 diff --git a/src/ConRIGv2/Radio/Radio.cpp b/src/ConRIGv2/Radio/Radio.cpp index 328df566ad8998cc4558d832d574df9797ed240e..3091b2a7c18990bc20ff87c01ee2c452cc6f6381 100644 --- a/src/ConRIGv2/Radio/Radio.cpp +++ b/src/ConRIGv2/Radio/Radio.cpp @@ -63,10 +63,18 @@ void Radio::handleMessage(const mavlink_message_t& msg) case MAVLINK_MSG_ID_GSE_TM: { int armingState = mavlink_msg_gse_tm_get_arming_state(&msg); - messagesReceived += 1; + bool wasArmed = isArmed; + bool isNowArmed = armingState == 1; + isArmed = isNowArmed; + + // Reset the message counter to a value higher than zero to avoid + // long pauses without audio feedback after disarming + if (wasArmed && !isNowArmed) + messagesReceived = Config::Radio::AUDIO_FEEDBACK_RESET_VALUE; + else + messagesReceived += 1; - isArmed = armingState == 1; - if (armingState == 1) + if (isNowArmed) getModule<Buttons>()->enableIgnition(); else getModule<Buttons>()->disableIgnition(); @@ -149,9 +157,8 @@ void Radio::buzzerOff() void Radio::buzzerTask() { - constexpr int beepPeriod = 5; // seconds - - if ((!isArmed && messagesReceived > beepPeriod * 2) || + if ((!isArmed && + messagesReceived > Config::Radio::AUDIO_FEEDBACK_THRESHOLD) || (isArmed && messagesReceived > 0)) { messagesReceived = 0; diff --git a/src/ConRIGv2/Radio/Radio.h b/src/ConRIGv2/Radio/Radio.h index 9d8c8bb476e8ccacd5a2e4b63d2a9b617fa47c32..71120d3fbe62145106615d3ea97724a1744d7129 100644 --- a/src/ConRIGv2/Radio/Radio.h +++ b/src/ConRIGv2/Radio/Radio.h @@ -88,7 +88,8 @@ private: miosix::FastMutex buttonsMutex; mavlink_conrig_state_tc_t buttonState{}; - std::atomic<uint8_t> messagesReceived{0}; + std::atomic<uint8_t> messagesReceived{ + Config::Radio::AUDIO_FEEDBACK_RESET_VALUE}; std::atomic<bool> isArmed{false}; Boardcore::PrintLogger logger = Boardcore::Logging::getLogger("radio");