Commit ce0bd4d2 authored by oberion's avatar oberion Committed by LM

Solved Windows threading problem with joystick and signal slot bug in WaypointList.cc

parent f4504903
......@@ -37,6 +37,7 @@ This file is part of the PIXHAWK project
#include "UAS.h"
#include "UASManager.h"
#include "QGC.h"
#include <QMutexLocker>
/**
* 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<int>()),
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();
......
......@@ -35,6 +35,7 @@ This file is part of the PIXHAWK project
#include <QThread>
#include <QList>
#include <qmutex.h>
#include <SDL/SDL.h>
#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<int> uasButtonList;
bool done;
QMutex m_doneMutex;
// Axis 3 is thrust (CALIBRATION!)
int thrustAxis;
......
......@@ -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)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment