From 1d89806744a5e63012b45e684f3332db86108b02 Mon Sep 17 00:00:00 2001 From: Matthias Krebs Date: Sun, 18 Nov 2012 17:48:10 +0100 Subject: [PATCH] Adding 3DMouse Support for LINUX (not completed) --- qgroundcontrol.pro | 20 +++++++++ src/input/Mouse6dofInput.cpp | 79 ++++++++++++++++++++++++++++++++++++ src/input/Mouse6dofInput.h | 10 ++++- src/ui/MainWindow.cc | 14 +++++++ src/ui/MainWindow.h | 14 +++++-- 5 files changed, 133 insertions(+), 4 deletions(-) diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 1c8c52864..db7d448b2 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -625,6 +625,26 @@ win32-msvc2008|win32-msvc2010|linux { -llibxbee } +################################################################### +#### --- 3DConnexion 3d Mice support (e.g. spacenavigator) --- #### +################################################################### + +# xdrvlib only supported by linux (theoretical all X11) systems +# You have to install the official 3DxWare driver for linux to use 3D mouse support on linux systems! +linux-g++|linux-g++-64{ + exists(/usr/local/lib/libxdrvlib.so){ + message("Including support for Magellan 3DxWare for linux system.") + SOURCES += src/input/Mouse6dofInput.cpp + HEADERS += src/input/Mouse6dofInput.h + LIBS += -L/usr/local/lib/ -lxdrvlib + INCLUDEPATH *= /usr/local/include + DEFINES += MOUSE_ENABLED_LINUX \ + ParameterCheck # Hack: Has to be defined for magellan usage + } +} + +# Support for Windows systems +# You have to install the official 3DxWare driver for Windows to use the 3D mouse support on Windows systems! win32-msvc2008|win32-msvc2010 { message("Including support for 3DxWare for Windows system.") SOURCES += libs/thirdParty/3DMouse/win/MouseParameters.cpp \ diff --git a/src/input/Mouse6dofInput.cpp b/src/input/Mouse6dofInput.cpp index 867c656f5..807eaeffa 100644 --- a/src/input/Mouse6dofInput.cpp +++ b/src/input/Mouse6dofInput.cpp @@ -9,7 +9,18 @@ #include "Mouse6dofInput.h" #include "UAS.h" #include "UASManager.h" +#include "QMessageBox" +#ifdef MOUSE_ENABLED_LINUX +#include +#include +#undef Success // Eigen library doesn't work if Success is defined +extern "C" +{ +#include "xdrvlib.h" +} +#endif // MOUSE_ENABLED_LINUX +#ifdef MOUSE_ENABLED_WIN Mouse6dofInput::Mouse6dofInput(Mouse3DInput* mouseInput) : mouse3DMax(0.075), // TODO: check maximum value fot plugged device uas(NULL), @@ -30,6 +41,74 @@ Mouse6dofInput::Mouse6dofInput(Mouse3DInput* mouseInput) : //connect(mouseInput, SIGNAL(On3dmouseKeyUp(int)), this, SLOT); } +#endif //MOUSE_ENABLED_WIN + +#ifdef MOUSE_ENABLED_LINUX +Mouse6dofInput::Mouse6dofInput(QWidget *parent) : + mouse3DMax(0.075), // TODO: check maximum value fot plugged device + uas(NULL), + done(false), + mouseActive(false), + xValue(0.0), + yValue(0.0), + zValue(0.0), + aValue(0.0), + bValue(0.0), + cValue(0.0) +{ + +} +#endif //MOUSE_ENABLED_LINUX + +#ifdef MOUSE_ENABLED_LINUX + +void Mouse6dofInput::init3dMouse(QWidget* parent) +{ + if (!mouseActive) + { +// // man visudo --> then you can omit giving password (success not guarantied..) +// qDebug() << "Starting 3DxWare Daemon for 3dConnexion 3dMouse"; +// QString processProgramm = "gksudo"; +// QStringList processArguments; +// processArguments << "/etc/3DxWare/daemon/3dxsrv -d usb"; +// process3dxDaemon = new QProcess(); +// process3dxDaemon->start(processProgramm, processArguments); +// // process3dxDaemon->waitForFinished(); +// // { +// // qDebug() << "... continuing without 3DxWare. May not be initialized properly!"; +// // qDebug() << "Try in terminal as user root:" << processArguments.last(); +// // } + + Display *display = QX11Info::display(); + if(!display) + { + qDebug() << "Cannot open display!" << endl; + } + if ( !MagellanInit( display, winId() ) ) + { + QMessageBox msgBox; + msgBox.setIcon(QMessageBox::Information); + msgBox.setText(tr("No 3DxWare driver is running.")); + msgBox.setInformativeText(tr("Enter in Terminal 'sudo /etc/3DxWare/daemon/3dxsrv -d usb'")); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.exec(); + + qDebug() << "No 3DxWare driver is running!"; + return; + } + else + { + qDebug() << "Initialized 3dMouse"; + mouseActive = true; + } + } + else + { + qDebug() << "3dMouse already initialized.."; + } +} +#endif //MOUSE_ENABLED_LINUX Mouse6dofInput::~Mouse6dofInput() { diff --git a/src/input/Mouse6dofInput.h b/src/input/Mouse6dofInput.h index 98e393d26..6bb637b9f 100644 --- a/src/input/Mouse6dofInput.h +++ b/src/input/Mouse6dofInput.h @@ -10,7 +10,9 @@ #define MOUSE6DOFINPUT_H #include +#ifdef MOUSE_ENABLED_WIN #include "Mouse3DInput.h" +#endif //MOUSE_ENABLED_WIN #include "UASInterface.h" @@ -19,7 +21,14 @@ class Mouse6dofInput : public QThread Q_OBJECT public: +#ifdef MOUSE_ENABLED_WIN Mouse6dofInput(Mouse3DInput* mouseInput); +#endif //MOUSE_ENABLED_WIN +#ifdef MOUSE_ENABLED_LINUX + Mouse6dofInput(QWidget* parent); + void init3dMouse(QWidget* parent); +#endif //MOUSE_ENABLED_LINUX + ~Mouse6dofInput(); void run(); @@ -28,7 +37,6 @@ public: protected: void init(); - Mouse3DInput* mouse3D; UASInterface* uas; bool done; bool mouseActive; diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index f026a66ef..2cf767ad9 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -189,6 +189,12 @@ MainWindow::MainWindow(QWidget *parent): mouse = new Mouse6dofInput(mouseInput); #endif //MOUSE_ENABLED_WIN +#if MOUSE_ENABLED_LINUX + emit initStatusChanged("Initializing 3D mouse interface."); + + mouse = new Mouse6dofInput(this); +#endif //MOUSE_ENABLED_LINUX + // Connect link if (autoReconnect) { @@ -1726,3 +1732,11 @@ QList MainWindow::listLinkMenuActions(void) { return ui.menuNetwork->actions(); } + +#ifdef MOUSE_ENABLED_LINUX +bool MainWindow::x11Event(XEvent *event) +{ + emit x11EventOccured(event); + qDebug("XEvent occured..."); +} +#endif // MOUSE_ENABLED_LINUX diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index b9727a59a..387ea2491 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -54,8 +54,8 @@ This file is part of the QGROUNDCONTROL project #include "HUD.h" #include "JoystickWidget.h" #include "input/JoystickInput.h" -#ifdef MOUSE_ENABLED_WIN -#include "input/Mouse6dofInput.h" +#if (defined MOUSE_ENABLED_WIN) | (defined MOUSE_ENABLED_LINUX) +#include "Mouse6dofInput.h" #endif // MOUSE_ENABLED_WIN #include "DebugConsole.h" #include "ParameterInterface.h" @@ -235,6 +235,8 @@ public slots: signals: void initStatusChanged(const QString& message); + /** @brief Forward X11Event to catch 3DMouse inputs */ + void x11EventOccured(XEvent *event); public: QGCMAVLinkLogPlayer* getLogPlayer() @@ -375,11 +377,17 @@ protected: JoystickInput* joystick; #ifdef MOUSE_ENABLED_WIN - /** 3d Mouse support (WIN only) **/ + /** @brief 3d Mouse support (WIN only) */ Mouse3DInput* mouseInput; ///< 3dConnexion 3dMouse SDK Mouse6dofInput* mouse; ///< Implementation for 3dMouse input #endif // MOUSE_ENABLED_WIN +#ifdef MOUSE_ENABLED_LINUX + /** @brief Reimplementation of X11Event to handle 3dMouse Events (magellan) */ + bool x11Event(XEvent *event); + Mouse6dofInput* mouse; ///< Implementation for 3dMouse input +#endif // MOUSE_ENABLED_LINUX + /** User interface actions **/ QAction* connectUASAct; QAction* disconnectUASAct; -- 2.22.0