Skip to content

Commit

Permalink
Add sound alerts on low battery and weak wifi link
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslaobeyer committed Dec 31, 2015
1 parent 817f96f commit 40c54fc
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ include_directories("${PROJECT_SOURCE_DIR}/../libdrone/include")
add_definitions(-DQT_NO_KEYWORDS)
find_package(Qt5Widgets)
find_package(Qt5OpenGL)
find_package(Qt5Multimedia)

# Find the Boost libraries
IF(MINGW)
Expand Down Expand Up @@ -197,4 +198,4 @@ ELSE()
ENDIF()

# Use the Widgets module from Qt 5
qt5_use_modules(AutoFlight Widgets PrintSupport WebKit WebKitWidgets OpenGL)
qt5_use_modules(AutoFlight Widgets PrintSupport WebKit WebKitWidgets OpenGL Multimedia)
3 changes: 3 additions & 0 deletions src/afmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ AFMainWindow::AFMainWindow(AutoFlight *af, QWidget *parent) : QMainWindow(parent
_manualcontrol->setControllerConfiguration(cc);
}

// Initialize sound alerts
QObject::connect(this, SIGNAL(navdataAvailableSignal(std::shared_ptr<const drone::navdata>)), &_soundAlerts, SLOT(navdataAvailable(std::shared_ptr<const drone::navdata>)));

showFirstRunInfoIfRequired();

loadDroneConfiguration();
Expand Down
3 changes: 3 additions & 0 deletions src/afmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "asmainwindow.h"
#include "input/manualcontrol.h"
#include "input/icontrollerinputlistener.h"
#include "soundalerts.h"

#include <drone.h>
#include <interface/inavdatalistener.h>
Expand Down Expand Up @@ -90,6 +91,8 @@ class AFMainWindow : public QMainWindow, public INavdataListener, public IStatus
uint64_t _lastProcessedFrameTime = 0;

ImageProcessor *_imgProcTest = NULL;

SoundAlerts _soundAlerts;
private Q_SLOTS:
void showMessageSlot(QString message);
void attemptConnection();
Expand Down
23 changes: 13 additions & 10 deletions src/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,42 @@
<qresource>
<file>resources/icon.png</file>
<file>resources/autoflight.png</file>

<file>resources/autoscript.png</file>


<file>resources/indicator_gyroYAW_128x128.png</file>
<file>resources/indicator_gyroPITCH_128x128.png</file>
<file>resources/indicator_gyroROLL_128x128.png</file>
<file>resources/speedometer_160x160.png</file>
<file>resources/speedometer-needle_160x160.png</file>

<file>resources/controller_button-only.png</file>
<file>resources/controller_button.png</file>
<file>resources/controller_stick.png</file>

<file>resources/as_save.png</file>
<file>resources/as_open.png</file>
<file>resources/as_sim.png</file>
<file>resources/as_exec.png</file>
<file>resources/as_abort.png</file>
<file>resources/as_landonerror.png</file>
<file>resources/as_errormarker.png</file>

<file>resources/sessionviewer_picture.png</file>
<file>resources/sessionviewer_navdata.png</file>
<file>resources/sessionviewer_video.png</file>
<file>resources/sessionviewer_takeoff.png</file>
<file>resources/sessionviewer_land.png</file>
<file>resources/sessionviewer_emergency.png</file>

<file>resources/visualpipeline_bg.png</file>
<file>resources/af_controls.png</file>

<file>resources/af_controls.png</file>

<file>resources/welcome.png</file>

<file>resources/batt_low.wav</file>
<file>resources/link_weak.wav</file>
</qresource>
</RCC>
Binary file added src/resources/batt_low.wav
Binary file not shown.
Binary file added src/resources/link_weak.wav
Binary file not shown.
37 changes: 37 additions & 0 deletions src/soundalerts.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "soundalerts.h"

#define BATTERY_ALERT_THRESHOLD 13
#define LINK_ALERT_THRESHOLD 25

SoundAlerts::SoundAlerts()
{
battery_low.reset(new QSoundEffect());
battery_low->setSource(QUrl("qrc:/resources/batt_low.wav"));

link_weak.reset(new QSoundEffect());
link_weak->setSource(QUrl("qrc:/resources/link_weak.wav"));
}

void SoundAlerts::navdataAvailable(std::shared_ptr<const drone::navdata> nd)
{
int battery_percent = (int) (nd->batterystatus * 100.0f);
int link_percent = (int) (nd->linkquality * 100.0f);

if(battery_percent <= BATTERY_ALERT_THRESHOLD)
{
if(!battery_low->isPlaying()) battery_low->play();
}
else
{
if(battery_low->isPlaying()) battery_low->stop();
}

if(link_percent <= LINK_ALERT_THRESHOLD)
{
if(!link_weak->isPlaying()) link_weak->play();
}
else
{
if(link_weak->isPlaying()) link_weak->stop();
}
}
28 changes: 28 additions & 0 deletions src/soundalerts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef AUTOFLIGHT_SOUNDALERTS_H
#define AUTOFLIGHT_SOUNDALERTS_H

#include <QtWidgets>
#include <QtMultimedia/QSoundEffect>

#include <memory>

#include "qinterface/qnavdatalistener.h"

#include <drone.h>

class SoundAlerts : public QObject, QNavdataListener
{
Q_OBJECT

public:
SoundAlerts();

public Q_SLOTS:
void navdataAvailable(std::shared_ptr<const drone::navdata> navdata);

private:
std::unique_ptr<QSoundEffect> battery_low = nullptr;
std::unique_ptr<QSoundEffect> link_weak = nullptr;
};

#endif

0 comments on commit 40c54fc

Please sign in to comment.