diff --git a/src/input/JoystickInput.cc b/src/input/JoystickInput.cc index 805f9a5d6534c3ffd4ee0575ca45ce20d0f84f17..01d6e4fab00ff7e72fec3b06639de5f3bb761a1f 100644 --- a/src/input/JoystickInput.cc +++ b/src/input/JoystickInput.cc @@ -37,6 +37,7 @@ This file is part of the PIXHAWK project #include "UAS.h" #include "UASManager.h" #include "QGC.h" +#include /** * The coordinate frame of the joystick axis is the aeronautical frame like shown on this image: @@ -49,10 +50,10 @@ JoystickInput::JoystickInput() : uas(NULL), uasButtonList(QList()), done(false), - thrustAxis(3), - xAxis(1), - yAxis(0), - yawAxis(2), + thrustAxis(2), + xAxis(0), + yAxis(1), + yawAxis(3), joystickName(tr("Unitinialized")) { for (int i = 0; i < 10; i++) { @@ -66,6 +67,17 @@ JoystickInput::JoystickInput() : //start(); } +JoystickInput::~JoystickInput() +{ + { + QMutexLocker locker(&this->m_doneMutex); + done = true; + } + this->wait(); + this->deleteLater(); +} + + void JoystickInput::setActiveUAS(UASInterface* uas) { // Only connect / disconnect is the UAS is of a controllable UAS class @@ -134,7 +146,16 @@ void JoystickInput::run() init(); - while(!done) { + forever + { + { + QMutexLocker locker(&this->m_doneMutex); + if(done) + { + done = false; + break; + } + } while(SDL_PollEvent(&event)) { SDL_JoystickUpdate(); diff --git a/src/input/JoystickInput.h b/src/input/JoystickInput.h index ad08c123a7ecda059e1ef583019d739b8f160989..f8b369e49cd3ffaba0d53d6ec5c9dfae8f5a6f42 100644 --- a/src/input/JoystickInput.h +++ b/src/input/JoystickInput.h @@ -35,6 +35,7 @@ This file is part of the PIXHAWK project #include #include +#include #include #include "UASInterface.h" @@ -48,6 +49,7 @@ class JoystickInput : public QThread public: JoystickInput(); + ~JoystickInput(); void run(); const QString& getName(); @@ -63,6 +65,7 @@ protected: UASInterface* uas; QList uasButtonList; bool done; + QMutex m_doneMutex; // Axis 3 is thrust (CALIBRATION!) int thrustAxis; diff --git a/src/ui/WaypointList.cc b/src/ui/WaypointList.cc index 8436230ec40ec85f78c17eaa079651154aefc271..a4f1cf156ca9cdf9304ed90cc35af46115a3b492 100644 --- a/src/ui/WaypointList.cc +++ b/src/ui/WaypointList.cc @@ -154,9 +154,11 @@ void WaypointList::setUAS(UASInterface* uas) if (this->uas == NULL && uas != NULL) { this->uas = uas; - - connect(uas, SIGNAL(localPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updatePosition(UASInterface*,double,double,double,quint64))); - connect(uas, SIGNAL(attitudeChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateAttitude(UASInterface*,double,double,double,quint64))); + if(uas != NULL) + { + connect(uas, SIGNAL(localPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updatePosition(UASInterface*,double,double,double,quint64))); + connect(uas, SIGNAL(attitudeChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateAttitude(UASInterface*,double,double,double,quint64))); + } connect(WPM, SIGNAL(updateStatusString(const QString &)), this, SLOT(updateStatusLabel(const QString &))); connect(WPM, SIGNAL(waypointEditableListChanged(void)), this, SLOT(waypointEditableListChanged(void)));