Commit 0ddc6eed authored by dogmaphobic's avatar dogmaphobic

Merge remote-tracking branch 'Mavlink/master' into iosAppStore

* Mavlink/master:
  Improving coding style
  Updating mavlink v1.0 ref
  Removing AndroidJoystick (requires Qt5.6)
  GPSFact.json: add RTK float & fixed types
  gps: use a read buffer size of 1024
  gps: update drivers submodule
  gps read callback: avoid sleep, don't wait when data already available
  gps: use GPS_RTCM_DATA mavlink message for RTCM, use fragmentation if needed
  gps: update submodule
  gps: use an inline function for usleep instead of #define
  GPSProvider: add SIMULATE_RTCM_OUTPUT to enable simulated RTCM output (currently disabled)
  Sync with official
  Fixing syntax
  Android Joystick support
  Fixing syntax
  Android Joystick support
  Fixing syntax
  Android Joystick support
parents 133ff142 ce7035b4
...@@ -262,6 +262,7 @@ HEADERS += \ ...@@ -262,6 +262,7 @@ HEADERS += \
src/HomePositionManager.h \ src/HomePositionManager.h \
src/Joystick/Joystick.h \ src/Joystick/Joystick.h \
src/Joystick/JoystickManager.h \ src/Joystick/JoystickManager.h \
src/VehicleSetup/JoystickConfigController.h \
src/FollowMe/FollowMe.h \ src/FollowMe/FollowMe.h \
src/PositionManager/SimulatedPosition.h \ src/PositionManager/SimulatedPosition.h \
src/JsonHelper.h \ src/JsonHelper.h \
...@@ -309,6 +310,10 @@ HEADERS += \ ...@@ -309,6 +310,10 @@ HEADERS += \
src/QtLocationPlugin/QMLControl/QGCMapEngineManager.h \ src/QtLocationPlugin/QMLControl/QGCMapEngineManager.h \
src/PositionManager/PositionManager.h src/PositionManager/PositionManager.h
AndroidBuild {
HEADERS += \
}
DebugBuild { DebugBuild {
HEADERS += \ HEADERS += \
src/comm/MockLink.h \ src/comm/MockLink.h \
...@@ -341,6 +346,7 @@ HEADERS += \ ...@@ -341,6 +346,7 @@ HEADERS += \
src/comm/QGCHilLink.h \ src/comm/QGCHilLink.h \
src/comm/QGCJSBSimLink.h \ src/comm/QGCJSBSimLink.h \
src/comm/QGCXPlaneLink.h \ src/comm/QGCXPlaneLink.h \
src/Joystick/JoystickSDL.h \
src/QGCFileDialog.h \ src/QGCFileDialog.h \
src/QGCMessageBox.h \ src/QGCMessageBox.h \
src/uas/FileManager.h \ src/uas/FileManager.h \
...@@ -385,7 +391,6 @@ HEADERS += \ ...@@ -385,7 +391,6 @@ HEADERS += \
src/GPS/GPSManager.h \ src/GPS/GPSManager.h \
src/GPS/GPSPositionMessage.h \ src/GPS/GPSPositionMessage.h \
src/GPS/GPSProvider.h \ src/GPS/GPSProvider.h \
src/VehicleSetup/JoystickConfigController.h \
src/ViewWidgets/CustomCommandWidget.h \ src/ViewWidgets/CustomCommandWidget.h \
src/ViewWidgets/CustomCommandWidgetController.h \ src/ViewWidgets/CustomCommandWidgetController.h \
src/ViewWidgets/LogDownload.h \ src/ViewWidgets/LogDownload.h \
...@@ -398,6 +403,7 @@ iOSBuild { ...@@ -398,6 +403,7 @@ iOSBuild {
src/audio/QGCAudioWorker_iOS.mm \ src/audio/QGCAudioWorker_iOS.mm \
src/MobileScreenMgr.mm \ src/MobileScreenMgr.mm \
} }
AndroidBuild { AndroidBuild {
SOURCES += src/MobileScreenMgr.cc \ SOURCES += src/MobileScreenMgr.cc \
} }
...@@ -418,6 +424,7 @@ SOURCES += \ ...@@ -418,6 +424,7 @@ SOURCES += \
src/HomePositionManager.cc \ src/HomePositionManager.cc \
src/Joystick/Joystick.cc \ src/Joystick/Joystick.cc \
src/Joystick/JoystickManager.cc \ src/Joystick/JoystickManager.cc \
src/VehicleSetup/JoystickConfigController.cc \
src/JsonHelper.cc \ src/JsonHelper.cc \
src/FollowMe/FollowMe.cc \ src/FollowMe/FollowMe.cc \
src/LogCompressor.cc \ src/LogCompressor.cc \
...@@ -495,6 +502,7 @@ SOURCES += \ ...@@ -495,6 +502,7 @@ SOURCES += \
src/comm/QGCFlightGearLink.cc \ src/comm/QGCFlightGearLink.cc \
src/comm/QGCJSBSimLink.cc \ src/comm/QGCJSBSimLink.cc \
src/comm/QGCXPlaneLink.cc \ src/comm/QGCXPlaneLink.cc \
src/Joystick/JoystickSDL.cc \
src/ui/HILDockWidget.cc \ src/ui/HILDockWidget.cc \
src/ui/linechart/ChartPlot.cc \ src/ui/linechart/ChartPlot.cc \
src/ui/linechart/IncrementalPlot.cc \ src/ui/linechart/IncrementalPlot.cc \
...@@ -525,7 +533,6 @@ SOURCES += \ ...@@ -525,7 +533,6 @@ SOURCES += \
src/GPS/RTCM/RTCMMavlink.cc \ src/GPS/RTCM/RTCMMavlink.cc \
src/GPS/GPSManager.cc \ src/GPS/GPSManager.cc \
src/GPS/GPSProvider.cc \ src/GPS/GPSProvider.cc \
src/VehicleSetup/JoystickConfigController.cc \
src/ViewWidgets/CustomCommandWidget.cc \ src/ViewWidgets/CustomCommandWidget.cc \
src/ViewWidgets/CustomCommandWidgetController.cc \ src/ViewWidgets/CustomCommandWidgetController.cc \
src/ViewWidgets/LogDownload.cc \ src/ViewWidgets/LogDownload.cc \
......
Subproject commit 60739aaace1723c700f23b22212696dc75169559 Subproject commit 5c1ae956552c3887c5fddd303a8f242efa715333
...@@ -18,9 +18,25 @@ ...@@ -18,9 +18,25 @@
#include "Drivers/src/gps_helper.h" #include "Drivers/src/gps_helper.h"
#include "definitions.h" #include "definitions.h"
//#define SIMULATE_RTCM_OUTPUT //if defined, generate simulated RTCM messages
//additionally make sure to call connectGPS(""), eg. from QGCToolbox.cc
void GPSProvider::run() void GPSProvider::run()
{ {
#ifdef SIMULATE_RTCM_OUTPUT
const int fakeMsgLengths[3] = { 30, 170, 240 };
uint8_t* fakeData = new uint8_t[fakeMsgLengths[2]];
while (!_requestStop) {
for (int i = 0; i < 3; ++i) {
gotRTCMData((uint8_t*) fakeData, fakeMsgLengths[i]);
msleep(4);
}
msleep(100);
}
delete[] fakeData;
#endif /* SIMULATE_RTCM_OUTPUT */
if (_serial) delete _serial; if (_serial) delete _serial;
_serial = new QSerialPort(); _serial = new QSerialPort();
...@@ -125,10 +141,11 @@ int GPSProvider::callback(GPSCallbackType type, void *data1, int data2) ...@@ -125,10 +141,11 @@ int GPSProvider::callback(GPSCallbackType type, void *data1, int data2)
{ {
switch (type) { switch (type) {
case GPSCallbackType::readDeviceData: { case GPSCallbackType::readDeviceData: {
int timeout = *((int *) data1); if (_serial->bytesAvailable() == 0) {
if (!_serial->waitForReadyRead(timeout)) int timeout = *((int *) data1);
return 0; //timeout if (!_serial->waitForReadyRead(timeout))
msleep(10); //give some more time to buffer data return 0; //timeout
}
return (int)_serial->read((char*) data1, data2); return (int)_serial->read((char*) data1, data2);
} }
case GPSCallbackType::writeDeviceData: case GPSCallbackType::writeDeviceData:
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "RTCMMavlink.h" #include "RTCMMavlink.h"
#include "MultiVehicleManager.h" #include "MultiVehicleManager.h"
#include "MAVLinkProtocol.h"
#include "Vehicle.h" #include "Vehicle.h"
#include <cstdio> #include <cstdio>
...@@ -24,8 +23,6 @@ RTCMMavlink::RTCMMavlink(QGCToolbox& toolbox) ...@@ -24,8 +23,6 @@ RTCMMavlink::RTCMMavlink(QGCToolbox& toolbox)
void RTCMMavlink::RTCMDataUpdate(QByteArray message) void RTCMMavlink::RTCMDataUpdate(QByteArray message)
{ {
Q_ASSERT(message.size() <= 110); //mavlink message uses a fixed-size buffer
/* statistics */ /* statistics */
_bandwidthByteCounter += message.size(); _bandwidthByteCounter += message.size();
qint64 elapsed = _bandwidthTimer.elapsed(); qint64 elapsed = _bandwidthTimer.elapsed();
...@@ -34,19 +31,38 @@ void RTCMMavlink::RTCMDataUpdate(QByteArray message) ...@@ -34,19 +31,38 @@ void RTCMMavlink::RTCMDataUpdate(QByteArray message)
_bandwidthTimer.restart(); _bandwidthTimer.restart();
_bandwidthByteCounter = 0; _bandwidthByteCounter = 0;
} }
QmlObjectListModel& vehicles = *_toolbox.multiVehicleManager()->vehicles();
MAVLinkProtocol* mavlinkProtocol = _toolbox.mavlinkProtocol();
mavlink_gps_inject_data_t mavlinkRtcmData;
memset(&mavlinkRtcmData, 0, sizeof(mavlink_gps_inject_data_t));
mavlinkRtcmData.len = message.size(); const int maxMessageLength = MAVLINK_MSG_GPS_RTCM_DATA_FIELD_DATA_LEN;
memcpy(&mavlinkRtcmData.data, message.data(), message.size()); mavlink_gps_rtcm_data_t mavlinkRtcmData;
memset(&mavlinkRtcmData, 0, sizeof(mavlink_gps_rtcm_data_t));
if (message.size() < maxMessageLength) {
mavlinkRtcmData.len = message.size();
memcpy(&mavlinkRtcmData.data, message.data(), message.size());
sendMessageToVehicle(mavlinkRtcmData);
} else {
//we need to fragment
int start = 0;
while (start < message.size()) {
int length = std::min(message.size() - start, maxMessageLength);
mavlinkRtcmData.flags = 1; //fragmented
mavlinkRtcmData.len = length;
memcpy(&mavlinkRtcmData.data, message.data() + start, length);
sendMessageToVehicle(mavlinkRtcmData);
start += length;
}
}
}
void RTCMMavlink::sendMessageToVehicle(const mavlink_gps_rtcm_data_t& msg)
{
QmlObjectListModel& vehicles = *_toolbox.multiVehicleManager()->vehicles();
MAVLinkProtocol* mavlinkProtocol = _toolbox.mavlinkProtocol();
for (int i = 0; i < vehicles.count(); i++) { for (int i = 0; i < vehicles.count(); i++) {
Vehicle* vehicle = qobject_cast<Vehicle*>(vehicles[i]); Vehicle* vehicle = qobject_cast<Vehicle*>(vehicles[i]);
mavlink_message_t message; mavlink_message_t message;
mavlink_msg_gps_inject_data_encode(mavlinkProtocol->getSystemId(), mavlink_msg_gps_rtcm_data_encode(mavlinkProtocol->getSystemId(),
mavlinkProtocol->getComponentId(), &message, &mavlinkRtcmData); mavlinkProtocol->getComponentId(), &message, &msg);
vehicle->sendMessage(message); vehicle->sendMessage(message);
} }
} }
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <QElapsedTimer> #include <QElapsedTimer>
#include "QGCToolbox.h" #include "QGCToolbox.h"
#include "MAVLinkProtocol.h"
/** /**
** class RTCMMavlink ** class RTCMMavlink
...@@ -30,6 +31,8 @@ public slots: ...@@ -30,6 +31,8 @@ public slots:
void RTCMDataUpdate(QByteArray message); void RTCMDataUpdate(QByteArray message);
private: private:
void sendMessageToVehicle(const mavlink_gps_rtcm_data_t& msg);
QGCToolbox& _toolbox; QGCToolbox& _toolbox;
QElapsedTimer _bandwidthTimer; QElapsedTimer _bandwidthTimer;
int _bandwidthByteCounter = 0; int _bandwidthByteCounter = 0;
......
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
#include <QtGlobal> #include <QtGlobal>
#define GPS_READ_BUFFER_SIZE 1024
#define GPS_INFO(...) qInfo(__VA_ARGS__) #define GPS_INFO(...) qInfo(__VA_ARGS__)
#define GPS_WARN(...) qWarning(__VA_ARGS__) #define GPS_WARN(...) qWarning(__VA_ARGS__)
#define GPS_ERR(...) qCritical(__VA_ARGS__) #define GPS_ERR(...) qCritical(__VA_ARGS__)
...@@ -59,7 +61,9 @@ public: ...@@ -59,7 +61,9 @@ public:
static void usleep(unsigned long usecs) { QThread::usleep(usecs); } static void usleep(unsigned long usecs) { QThread::usleep(usecs); }
}; };
#define usleep Sleeper::usleep static inline void usleep(unsigned long usecs) {
Sleeper::usleep(usecs);
}
typedef uint64_t gps_abstime; typedef uint64_t gps_abstime;
......
...@@ -15,14 +15,6 @@ ...@@ -15,14 +15,6 @@
#include <QSettings> #include <QSettings>
#ifndef __mobile__
#ifdef Q_OS_MAC
#include <SDL.h>
#else
#include <SDL/SDL.h>
#endif
#endif
QGC_LOGGING_CATEGORY(JoystickLog, "JoystickLog") QGC_LOGGING_CATEGORY(JoystickLog, "JoystickLog")
QGC_LOGGING_CATEGORY(JoystickValuesLog, "JoystickValuesLog") QGC_LOGGING_CATEGORY(JoystickValuesLog, "JoystickValuesLog")
...@@ -38,10 +30,8 @@ const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = { ...@@ -38,10 +30,8 @@ const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = {
"ThrottleAxis" "ThrottleAxis"
}; };
Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int sdlIndex, MultiVehicleManager* multiVehicleManager) Joystick::Joystick(const QString& name, int axisCount, int buttonCount, MultiVehicleManager* multiVehicleManager)
#ifndef __mobile__ : _exitThread(false)
: _sdlIndex(sdlIndex)
, _exitThread(false)
, _name(name) , _name(name)
, _axisCount(axisCount) , _axisCount(axisCount)
, _buttonCount(buttonCount) , _buttonCount(buttonCount)
...@@ -55,15 +45,7 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int sdlI ...@@ -55,15 +45,7 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int sdlI
, _activeVehicle(NULL) , _activeVehicle(NULL)
, _pollingStartedForCalibration(false) , _pollingStartedForCalibration(false)
, _multiVehicleManager(multiVehicleManager) , _multiVehicleManager(multiVehicleManager)
#endif // __mobile__
{ {
#ifdef __mobile__
Q_UNUSED(name)
Q_UNUSED(axisCount)
Q_UNUSED(buttonCount)
Q_UNUSED(sdlIndex)
Q_UNUSED(multiVehicleManager)
#else
_rgAxisValues = new int[_axisCount]; _rgAxisValues = new int[_axisCount];
_rgCalibration = new Calibration_t[_axisCount]; _rgCalibration = new Calibration_t[_axisCount];
_rgButtonValues = new bool[_buttonCount]; _rgButtonValues = new bool[_buttonCount];
...@@ -77,21 +59,16 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int sdlI ...@@ -77,21 +59,16 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int sdlI
} }
_loadSettings(); _loadSettings();
#endif // __mobile__
} }
Joystick::~Joystick() Joystick::~Joystick()
{ {
#ifndef __mobile__
delete _rgAxisValues; delete _rgAxisValues;
delete _rgCalibration; delete _rgCalibration;
delete _rgButtonValues; delete _rgButtonValues;
delete _rgButtonActions; delete _rgButtonActions;
#endif
} }
#ifndef __mobile__
void Joystick::_loadSettings(void) void Joystick::_loadSettings(void)
{ {
QSettings settings; QSettings settings;
...@@ -244,19 +221,14 @@ float Joystick::_adjustRange(int value, Calibration_t calibration) ...@@ -244,19 +221,14 @@ float Joystick::_adjustRange(int value, Calibration_t calibration)
void Joystick::run(void) void Joystick::run(void)
{ {
SDL_Joystick* sdlJoystick = SDL_JoystickOpen(_sdlIndex); _open();
if (!sdlJoystick) {
qCWarning(JoystickLog) << "SDL_JoystickOpen failed:" << SDL_GetError();
return;
}
while (!_exitThread) { while (!_exitThread) {
SDL_JoystickUpdate(); _update();
// Update axes // Update axes
for (int axisIndex=0; axisIndex<_axisCount; axisIndex++) { for (int axisIndex=0; axisIndex<_axisCount; axisIndex++) {
int newAxisValue = SDL_JoystickGetAxis(sdlJoystick, axisIndex); int newAxisValue = _getAxis(axisIndex);
// Calibration code requires signal to be emitted even if value hasn't changed // Calibration code requires signal to be emitted even if value hasn't changed
_rgAxisValues[axisIndex] = newAxisValue; _rgAxisValues[axisIndex] = newAxisValue;
emit rawAxisValueChanged(axisIndex, newAxisValue); emit rawAxisValueChanged(axisIndex, newAxisValue);
...@@ -264,7 +236,7 @@ void Joystick::run(void) ...@@ -264,7 +236,7 @@ void Joystick::run(void)
// Update buttons // Update buttons
for (int buttonIndex=0; buttonIndex<_buttonCount; buttonIndex++) { for (int buttonIndex=0; buttonIndex<_buttonCount; buttonIndex++) {
bool newButtonValue = !!SDL_JoystickGetButton(sdlJoystick, buttonIndex); bool newButtonValue = _getButton(buttonIndex);
if (newButtonValue != _rgButtonValues[buttonIndex]) { if (newButtonValue != _rgButtonValues[buttonIndex]) {
_rgButtonValues[buttonIndex] = newButtonValue; _rgButtonValues[buttonIndex] = newButtonValue;
emit rawButtonPressedChanged(buttonIndex, newButtonValue); emit rawButtonPressedChanged(buttonIndex, newButtonValue);
...@@ -349,7 +321,7 @@ void Joystick::run(void) ...@@ -349,7 +321,7 @@ void Joystick::run(void)
QGC::SLEEP::msleep(40); QGC::SLEEP::msleep(40);
} }
SDL_JoystickClose(sdlJoystick); _close();
} }
void Joystick::startPolling(Vehicle* vehicle) void Joystick::startPolling(Vehicle* vehicle)
...@@ -566,4 +538,3 @@ bool Joystick::_validButton(int button) ...@@ -566,4 +538,3 @@ bool Joystick::_validButton(int button)
return button >= 0 && button < _buttonCount; return button >= 0 && button < _buttonCount;
} }
#endif // __mobile__
...@@ -26,9 +26,9 @@ class Joystick : public QThread ...@@ -26,9 +26,9 @@ class Joystick : public QThread
Q_OBJECT Q_OBJECT
public: public:
Joystick(const QString& name, int axisCount, int buttonCount, int sdlIndex, MultiVehicleManager* multiVehicleManager); Joystick(const QString& name, int axisCount, int buttonCount, MultiVehicleManager* multiVehicleManager);
~Joystick(); ~Joystick();
typedef struct { typedef struct {
int min; int min;
int max; int max;
...@@ -50,7 +50,6 @@ public: ...@@ -50,7 +50,6 @@ public:
ThrottleModeMax ThrottleModeMax
} ThrottleMode_t; } ThrottleMode_t;
#ifndef __mobile__
Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(bool calibrated MEMBER _calibrated NOTIFY calibratedChanged) Q_PROPERTY(bool calibrated MEMBER _calibrated NOTIFY calibratedChanged)
...@@ -124,7 +123,7 @@ signals: ...@@ -124,7 +123,7 @@ signals:
void buttonActionTriggered(int action); void buttonActionTriggered(int action);
private: protected:
void _saveSettings(void); void _saveSettings(void);
void _loadSettings(void); void _loadSettings(void);
float _adjustRange(int value, Calibration_t calibration); float _adjustRange(int value, Calibration_t calibration);
...@@ -132,11 +131,18 @@ private: ...@@ -132,11 +131,18 @@ private:
bool _validAxis(int axis); bool _validAxis(int axis);
bool _validButton(int button); bool _validButton(int button);
private:
virtual bool _open() = 0;
virtual void _close() = 0;
virtual bool _update() = 0;
virtual bool _getButton(int i) = 0;
virtual int _getAxis(int i) = 0;
// Override from QThread // Override from QThread
virtual void run(void); virtual void run(void);
private: protected:
int _sdlIndex; ///< Index for SDL_JoystickOpen
bool _exitThread; ///< true: signal thread to exit bool _exitThread; ///< true: signal thread to exit
...@@ -161,7 +167,6 @@ private: ...@@ -161,7 +167,6 @@ private:
bool _pollingStartedForCalibration; bool _pollingStartedForCalibration;
MultiVehicleManager* _multiVehicleManager; MultiVehicleManager* _multiVehicleManager;
#endif // __mobile__
private: private:
static const char* _rgFunctionSettingsKey[maxFunction]; static const char* _rgFunctionSettingsKey[maxFunction];
......
...@@ -14,11 +14,15 @@ ...@@ -14,11 +14,15 @@
#include <QQmlEngine> #include <QQmlEngine>
#ifndef __mobile__ #ifndef __mobile__
#ifdef Q_OS_MAC #include "JoystickSDL.h"
#include <SDL.h> #define __sdljoystick__
#else #endif
#include <SDL/SDL.h>
#endif #ifdef __android__
/*
* Android Joystick not yet supported
* #include "JoystickAndroid.h"
*/
#endif #endif
QGC_LOGGING_CATEGORY(JoystickManagerLog, "JoystickManagerLog") QGC_LOGGING_CATEGORY(JoystickManagerLog, "JoystickManagerLog")
...@@ -31,7 +35,15 @@ JoystickManager::JoystickManager(QGCApplication* app) ...@@ -31,7 +35,15 @@ JoystickManager::JoystickManager(QGCApplication* app)
, _activeJoystick(NULL) , _activeJoystick(NULL)
, _multiVehicleManager(NULL) , _multiVehicleManager(NULL)
{ {
}
JoystickManager::~JoystickManager() {
QMap<QString, Joystick*>::iterator i;
for (i = _name2JoystickMap.begin(); i != _name2JoystickMap.end(); ++i) {
qDebug() << "Releasing joystick:" << i.key();
delete i.value();
}
qDebug() << "Done";
} }
void JoystickManager::setToolbox(QGCToolbox *toolbox) void JoystickManager::setToolbox(QGCToolbox *toolbox)
...@@ -42,33 +54,13 @@ void JoystickManager::setToolbox(QGCToolbox *toolbox) ...@@ -42,33 +54,13 @@ void JoystickManager::setToolbox(QGCToolbox *toolbox)
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
#ifndef __mobile__ #ifdef __sdljoystick__
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) < 0) { _name2JoystickMap = JoystickSDL::discover(_multiVehicleManager);
qWarning() << "Couldn't initialize SimpleDirectMediaLayer:" << SDL_GetError(); #elif defined(__android__)
return; /*
} * Android Joystick not yet supported
* _name2JoystickMap = JoystickAndroid::discover(_multiVehicleManager);
// Load available joysticks */
qCDebug(JoystickManagerLog) << "Available joysticks";
for (int i=0; i<SDL_NumJoysticks(); i++) {
QString name = SDL_JoystickName(i);
if (!_name2JoystickMap.contains(name)) {
int axisCount, buttonCount;
SDL_Joystick* sdlJoystick = SDL_JoystickOpen(i);
axisCount = SDL_JoystickNumAxes(sdlJoystick);
buttonCount = SDL_JoystickNumButtons(sdlJoystick);
SDL_JoystickClose(sdlJoystick);
qCDebug(JoystickManagerLog) << "\t" << name << "axes:" << axisCount << "buttons:" << buttonCount;
_name2JoystickMap[name] = new Joystick(name, axisCount, buttonCount, i, _multiVehicleManager);
} else {
qCDebug(JoystickManagerLog) << "\tSkipping duplicate" << name;
}
}
#endif #endif
if (!_name2JoystickMap.count()) { if (!_name2JoystickMap.count()) {
...@@ -79,10 +71,8 @@ void JoystickManager::setToolbox(QGCToolbox *toolbox) ...@@ -79,10 +71,8 @@ void JoystickManager::setToolbox(QGCToolbox *toolbox)
_setActiveJoystickFromSettings(); _setActiveJoystickFromSettings();
} }
void JoystickManager::_setActiveJoystickFromSettings(void) void JoystickManager::_setActiveJoystickFromSettings(void)
{ {
#ifndef __mobile__
QSettings settings; QSettings settings;
settings.beginGroup(_settingsGroup); settings.beginGroup(_settingsGroup);
...@@ -94,7 +84,6 @@ void JoystickManager::_setActiveJoystickFromSettings(void) ...@@ -94,7 +84,6 @@ void JoystickManager::_setActiveJoystickFromSettings(void)
setActiveJoystick(_name2JoystickMap.value(name, _name2JoystickMap.first())); setActiveJoystick(_name2JoystickMap.value(name, _name2JoystickMap.first()));
settings.setValue(_settingsKeyActiveJoystick, _activeJoystick->name()); settings.setValue(_settingsKeyActiveJoystick, _activeJoystick->name());
#endif
} }
Joystick* JoystickManager::activeJoystick(void) Joystick* JoystickManager::activeJoystick(void)
...@@ -104,9 +93,6 @@ Joystick* JoystickManager::activeJoystick(void) ...@@ -104,9 +93,6 @@ Joystick* JoystickManager::activeJoystick(void)
void JoystickManager::setActiveJoystick(Joystick* joystick) void JoystickManager::setActiveJoystick(Joystick* joystick)
{ {
#ifdef __mobile__
Q_UNUSED(joystick)
#else
QSettings settings; QSettings settings;
if (!_name2JoystickMap.contains(joystick->name())) { if (!_name2JoystickMap.contains(joystick->name())) {
...@@ -125,7 +111,6 @@ void JoystickManager::setActiveJoystick(Joystick* joystick) ...@@ -125,7 +111,6 @@ void JoystickManager::setActiveJoystick(Joystick* joystick)
emit activeJoystickChanged(_activeJoystick); emit activeJoystickChanged(_activeJoystick);
emit activeJoystickNameChanged(_activeJoystick->name()); emit activeJoystickNameChanged(_activeJoystick->name());
#endif
} }
QVariantList JoystickManager::joysticks(void) QVariantList JoystickManager::joysticks(void)
...@@ -146,11 +131,7 @@ QStringList JoystickManager::joystickNames(void) ...@@ -146,11 +131,7 @@ QStringList JoystickManager::joystickNames(void)
QString JoystickManager::activeJoystickName(void) QString JoystickManager::activeJoystickName(void)
{ {
#ifdef __mobile__
return QString();
#else
return _activeJoystick ? _activeJoystick->name() : QString(); return _activeJoystick ? _activeJoystick->name() : QString();
#endif
} }
void JoystickManager::setActiveJoystickName(const QString& name) void JoystickManager::setActiveJoystickName(const QString& name)
......
...@@ -28,6 +28,7 @@ class JoystickManager : public QGCTool ...@@ -28,6 +28,7 @@ class JoystickManager : public QGCTool
public: public:
JoystickManager(QGCApplication* app); JoystickManager(QGCApplication* app);
~JoystickManager();
/// List of available joysticks /// List of available joysticks
Q_PROPERTY(QVariantList joysticks READ joysticks CONSTANT) Q_PROPERTY(QVariantList joysticks READ joysticks CONSTANT)
......
#include "JoystickSDL.h"
#include "QGCApplication.h"
#include <QQmlEngine>
JoystickSDL::JoystickSDL(const QString& name, int axisCount, int buttonCount, int index, MultiVehicleManager* multiVehicleManager)
: Joystick(name,axisCount,buttonCount,multiVehicleManager)
, _index(index)
{
}
QMap<QString, Joystick*> JoystickSDL::discover(MultiVehicleManager* _multiVehicleManager) {
static QMap<QString, Joystick*> ret;
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) < 0) {
qWarning() << "Couldn't initialize SimpleDirectMediaLayer:" << SDL_GetError();
return ret;
}
// Load available joysticks
qCDebug(JoystickLog) << "Available joysticks";
for (int i=0; i<SDL_NumJoysticks(); i++) {
QString name = SDL_JoystickName(i);
if (!ret.contains(name)) {
int axisCount, buttonCount;
SDL_Joystick* sdlJoystick = SDL_JoystickOpen(i);
axisCount = SDL_JoystickNumAxes(sdlJoystick);
buttonCount = SDL_JoystickNumButtons(sdlJoystick);
SDL_JoystickClose(sdlJoystick);
qCDebug(JoystickLog) << "\t" << name << "axes:" << axisCount << "buttons:" << buttonCount;
ret[name] = new JoystickSDL(name, axisCount, buttonCount, i, _multiVehicleManager);
} else {
qCDebug(JoystickLog) << "\tSkipping duplicate" << name;
}
}
return ret;
}
bool JoystickSDL::_open(void) {
sdlJoystick = SDL_JoystickOpen(_index);
if (!sdlJoystick) {
qCWarning(JoystickLog) << "SDL_JoystickOpen failed:" << SDL_GetError();
return false;
}
return true;
}
void JoystickSDL::_close(void) {
SDL_JoystickClose(sdlJoystick);
}
bool JoystickSDL::_update(void)
{
SDL_JoystickUpdate();
return true;
}
bool JoystickSDL::_getButton(int i) {
return !!SDL_JoystickGetButton(sdlJoystick, i);
}
int JoystickSDL::_getAxis(int i) {
return SDL_JoystickGetAxis(sdlJoystick, i);
}
#ifndef JOYSTICKSDL_H
#define JOYSTICKSDL_H
#include "Joystick.h"
#include "Vehicle.h"
#include "MultiVehicleManager.h"
#ifdef Q_OS_MAC
#include <SDL.h>
#else
#include <SDL/SDL.h>
#endif
class JoystickSDL : public Joystick
{
public:
JoystickSDL(const QString& name, int axisCount, int buttonCount, int index, MultiVehicleManager* multiVehicleManager);
static QMap<QString, Joystick*> discover(MultiVehicleManager* _multiVehicleManager);
private:
bool _open() final;
void _close() final;
bool _update() final;
bool _getButton(int i) final;
int _getAxis(int i) final;
SDL_Joystick *sdlJoystick;
int _index; ///< Index for SDL_JoystickOpen
};
#endif // JOYSTICKSDL_H
...@@ -72,6 +72,7 @@ ...@@ -72,6 +72,7 @@
#include "PX4/PX4FirmwarePlugin.h" #include "PX4/PX4FirmwarePlugin.h"
#include "Vehicle.h" #include "Vehicle.h"
#include "MavlinkQmlSingleton.h" #include "MavlinkQmlSingleton.h"
#include "JoystickConfigController.h"
#include "JoystickManager.h" #include "JoystickManager.h"
#include "QmlObjectListModel.h" #include "QmlObjectListModel.h"
#include "MissionManager.h" #include "MissionManager.h"
...@@ -102,7 +103,6 @@ ...@@ -102,7 +103,6 @@
#include "QGCFileDialog.h" #include "QGCFileDialog.h"
#include "QGCMessageBox.h" #include "QGCMessageBox.h"
#include "FirmwareUpgradeController.h" #include "FirmwareUpgradeController.h"
#include "JoystickConfigController.h"
#include "MainWindow.h" #include "MainWindow.h"
#endif #endif
...@@ -386,12 +386,11 @@ void QGCApplication::_initCommon(void) ...@@ -386,12 +386,11 @@ void QGCApplication::_initCommon(void)
qmlRegisterType<ValuesWidgetController> ("QGroundControl.Controllers", 1, 0, "ValuesWidgetController"); qmlRegisterType<ValuesWidgetController> ("QGroundControl.Controllers", 1, 0, "ValuesWidgetController");
qmlRegisterType<QGCMobileFileDialogController> ("QGroundControl.Controllers", 1, 0, "QGCMobileFileDialogController"); qmlRegisterType<QGCMobileFileDialogController> ("QGroundControl.Controllers", 1, 0, "QGCMobileFileDialogController");
qmlRegisterType<RCChannelMonitorController> ("QGroundControl.Controllers", 1, 0, "RCChannelMonitorController"); qmlRegisterType<RCChannelMonitorController> ("QGroundControl.Controllers", 1, 0, "RCChannelMonitorController");
qmlRegisterType<JoystickConfigController> ("QGroundControl.Controllers", 1, 0, "JoystickConfigController");
#ifndef __mobile__ #ifndef __mobile__
qmlRegisterType<ViewWidgetController> ("QGroundControl.Controllers", 1, 0, "ViewWidgetController"); qmlRegisterType<ViewWidgetController> ("QGroundControl.Controllers", 1, 0, "ViewWidgetController");
qmlRegisterType<CustomCommandWidgetController> ("QGroundControl.Controllers", 1, 0, "CustomCommandWidgetController"); qmlRegisterType<CustomCommandWidgetController> ("QGroundControl.Controllers", 1, 0, "CustomCommandWidgetController");
qmlRegisterType<FirmwareUpgradeController> ("QGroundControl.Controllers", 1, 0, "FirmwareUpgradeController"); qmlRegisterType<FirmwareUpgradeController> ("QGroundControl.Controllers", 1, 0, "FirmwareUpgradeController");
qmlRegisterType<JoystickConfigController> ("QGroundControl.Controllers", 1, 0, "JoystickConfigController");
qmlRegisterType<LogDownloadController> ("QGroundControl.Controllers", 1, 0, "LogDownloadController"); qmlRegisterType<LogDownloadController> ("QGroundControl.Controllers", 1, 0, "LogDownloadController");
#endif #endif
......
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
"name": "lock", "name": "lock",
"shortDescription": "GPS Lock", "shortDescription": "GPS Lock",
"type": "uint32", "type": "uint32",
"enumStrings": "None,None,2D Lock,3D Lock,3D DGPS Lock,3D RTK GPS Lock", "enumStrings": "None,None,2D Lock,3D Lock,3D DGPS Lock,3D RTK GPS Lock (float),3D RTK GPS Lock (fixed)",
"enumValues": "0,1,2,3,4,5", "enumValues": "0,1,2,3,4,5,6",
"decimalPlaces": 0 "decimalPlaces": 0
}, },
{ {
......
...@@ -1111,7 +1111,6 @@ void Vehicle::setJoystickEnabled(bool enabled) ...@@ -1111,7 +1111,6 @@ void Vehicle::setJoystickEnabled(bool enabled)
void Vehicle::_startJoystick(bool start) void Vehicle::_startJoystick(bool start)
{ {
#ifndef __mobile__
Joystick* joystick = _joystickManager->activeJoystick(); Joystick* joystick = _joystickManager->activeJoystick();
if (joystick) { if (joystick) {
if (start) { if (start) {
...@@ -1122,9 +1121,6 @@ void Vehicle::_startJoystick(bool start) ...@@ -1122,9 +1121,6 @@ void Vehicle::_startJoystick(bool start)
joystick->stopPolling(); joystick->stopPolling();
} }
} }
#else
Q_UNUSED(start);
#endif
} }
bool Vehicle::active(void) bool Vehicle::active(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