From d53d5f88a82cb9e9eb970cd6a8ca253f0794a6a4 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Tue, 9 Dec 2014 13:54:45 +0100 Subject: [PATCH] Improve audio output logic and consistency --- src/GAudioOutput.cc | 2 +- src/GAudioOutput.h | 14 +++++++++++++- src/audio/QGCAudioWorker.cpp | 9 +++++---- src/uas/UAS.cc | 6 +++--- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/GAudioOutput.cc b/src/GAudioOutput.cc index a6788f97b..dc847cee7 100644 --- a/src/GAudioOutput.cc +++ b/src/GAudioOutput.cc @@ -107,7 +107,7 @@ bool GAudioOutput::say(QString text, int severity) */ bool GAudioOutput::alert(QString text) { - emit textToSpeak(text, 2); + emit textToSpeak(text, 1); return true; } diff --git a/src/GAudioOutput.h b/src/GAudioOutput.h index 4330a8e81..b9440e585 100644 --- a/src/GAudioOutput.h +++ b/src/GAudioOutput.h @@ -58,12 +58,24 @@ public: VOICE_FEMALE } QGVoice; + enum AUDIO_SEVERITY + { + AUDIO_SEVERITY_EMERGENCY = 0, + AUDIO_SEVERITY_ALERT = 1, + AUDIO_SEVERITY_CRITICAL = 2, + AUDIO_SEVERITY_ERROR = 3, + AUDIO_SEVERITY_WARNING = 4, + AUDIO_SEVERITY_NOTICE = 5, + AUDIO_SEVERITY_INFO = 6, + AUDIO_SEVERITY_DEBUG = 7 + }; + /** @brief Get the mute state */ bool isMuted(); public slots: /** @brief Say this text if current output priority matches */ - bool say(QString text, int severity = 1); + bool say(QString text, int severity = 6); /** @brief Play alert sound and say notification message */ bool alert(QString text); /** @brief Start emergency sound */ diff --git a/src/audio/QGCAudioWorker.cpp b/src/audio/QGCAudioWorker.cpp index e56133206..0e74a85e9 100644 --- a/src/audio/QGCAudioWorker.cpp +++ b/src/audio/QGCAudioWorker.cpp @@ -6,6 +6,7 @@ #include "QGC.h" #include "QGCAudioWorker.h" +#include "GAudioOutput.h" #if defined Q_OS_MAC && defined QGC_SPEECH_ENABLED #include @@ -89,11 +90,12 @@ QGCAudioWorker::~QGCAudioWorker() void QGCAudioWorker::say(QString text, int severity) { - qDebug() << "TEXT" << text; if (!muted) { - // TODO Add severity filter - Q_UNUSED(severity); + // Prepend high priority text with alert beep + if (severity < GAudioOutput::AUDIO_SEVERITY_CRITICAL) { + beep(); + } // Wait for the last sound to finish while (!sound->isFinished()) { @@ -149,7 +151,6 @@ void QGCAudioWorker::beep() { // Use QFile to transform path for all OS QFile f(QCoreApplication::applicationDirPath() + QString("/files/audio/alert.wav")); - qDebug() << "SOUND FILE:" << f.fileName(); sound->play(f.fileName()); } } diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 1e7f16d0e..a474a487b 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -333,7 +333,7 @@ void UAS::updateState() connectionLost = true; receivedMode = false; QString audiostring = QString("Link lost to system %1").arg(this->getUASID()); - GAudioOutput::instance()->say(audiostring.toLower()); + GAudioOutput::instance()->say(audiostring.toLower(), GAudioOutput::AUDIO_SEVERITY_ALERT); } // Update connection loss time on each iteration @@ -347,7 +347,7 @@ void UAS::updateState() if (connectionLost && (heartbeatInterval < timeoutIntervalHeartbeat)) { QString audiostring = QString("Link regained to system %1").arg(this->getUASID()); - GAudioOutput::instance()->say(audiostring.toLower()); + GAudioOutput::instance()->say(audiostring.toLower(), GAudioOutput::AUDIO_SEVERITY_NOTICE); connectionLost = false; connectionLossTime = 0; emit heartbeatTimeout(false, 0); @@ -574,7 +574,7 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) if (statechanged && ((int)state.system_status == (int)MAV_STATE_CRITICAL || state.system_status == (int)MAV_STATE_EMERGENCY)) { - GAudioOutput::instance()->say(QString("emergency for system %1").arg(this->getUASID())); + GAudioOutput::instance()->say(QString("emergency for system %1").arg(this->getUASID()), GAudioOutput::AUDIO_SEVERITY_EMERGENCY); QTimer::singleShot(3000, GAudioOutput::instance(), SLOT(startEmergency())); } else if (modechanged || statechanged) -- 2.22.0