Skip to content

Commit

Permalink
Joystick: Fixup Joystick Threading
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Nov 30, 2024
1 parent fd1ecc9 commit 744f00c
Show file tree
Hide file tree
Showing 10 changed files with 910 additions and 858 deletions.
1,160 changes: 613 additions & 547 deletions src/Joystick/Joystick.cc

Large diffs are not rendered by default.

558 changes: 271 additions & 287 deletions src/Joystick/Joystick.h

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions src/Joystick/JoystickAndroid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,18 @@ bool JoystickAndroid::_update(void)
return true;
}

bool JoystickAndroid::_getButton(int i) {
bool JoystickAndroid::_getButton(int i) const
{
return btnValue[ i ];
}

int JoystickAndroid::_getAxis(int i) {
int JoystickAndroid::_getAxis(int i) const
{
return axisValue[ i ];
}

int JoystickAndroid::_getAndroidHatAxis(int axisHatCode) {
int JoystickAndroid::_getAndroidHatAxis(int axisHatCode) const
{
for(int i = 0; i < _axisCount; i++) {
if (axisCode[i] == axisHatCode) {
return _getAxis(i);
Expand All @@ -221,7 +224,8 @@ int JoystickAndroid::_getAndroidHatAxis(int axisHatCode) {
return 0;
}

bool JoystickAndroid::_getHat(int hat,int i) {
bool JoystickAndroid::_getHat(int hat,int i) const
{
// Android supports only one hat button
if (hat != 0) {
return false;
Expand Down
14 changes: 7 additions & 7 deletions src/Joystick/JoystickAndroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class JoystickAndroid : public Joystick, public QtAndroidPrivate::GenericMotionE
private:
bool handleKeyEvent(jobject event);
bool handleGenericMotionEvent(jobject event);
int _getAndroidHatAxis(int axisHatCode);
int _getAndroidHatAxis(int axisHatCode) const;

virtual bool _open ();
virtual void _close ();
virtual bool _update ();
bool _open () final;
void _close () final;
bool _update () final;

virtual bool _getButton (int i);
virtual int _getAxis (int i);
virtual bool _getHat (int hat,int i);
bool _getButton (int i) const final;
int _getAxis (int i) const final;
bool _getHat (int hat,int i) const final;

int *btnCode;
int *axisCode;
Expand Down
7 changes: 3 additions & 4 deletions src/Joystick/JoystickSDL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
****************************************************************************/

#include "JoystickSDL.h"
#include "MultiVehicleManager.h"
#include "QGCLoggingCategory.h"

#include <QtCore/QTextStream>
Expand Down Expand Up @@ -166,23 +165,23 @@ bool JoystickSDL::_update(void)
return true;
}

bool JoystickSDL::_getButton(int i) {
bool JoystickSDL::_getButton(int i) const {
if (_isGameController) {
return SDL_GameControllerGetButton(sdlController, SDL_GameControllerButton(i)) == 1;
} else {
return SDL_JoystickGetButton(sdlJoystick, i) == 1;
}
}

int JoystickSDL::_getAxis(int i) {
int JoystickSDL::_getAxis(int i) const {
if (_isGameController) {
return SDL_GameControllerGetAxis(sdlController, SDL_GameControllerAxis(i));
} else {
return SDL_JoystickGetAxis(sdlJoystick, i);
}
}

bool JoystickSDL::_getHat(int hat, int i) {
bool JoystickSDL::_getHat(int hat, int i) const {
uint8_t hatButtons[] = {SDL_HAT_UP,SDL_HAT_DOWN,SDL_HAT_LEFT,SDL_HAT_RIGHT};
if (i < int(sizeof(hatButtons))) {
return (SDL_JoystickGetHat(sdlJoystick, hat) & hatButtons[i]) != 0;
Expand Down
6 changes: 3 additions & 3 deletions src/Joystick/JoystickSDL.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class JoystickSDL : public Joystick
void _close () final;
bool _update () final;

bool _getButton (int i) final;
int _getAxis (int i) final;
bool _getHat (int hat,int i) final;
bool _getButton (int i) const final;
int _getAxis (int i) const final;
bool _getHat (int hat,int i) const final;

SDL_Joystick* sdlJoystick;
SDL_GameController* sdlController;
Expand Down
7 changes: 4 additions & 3 deletions src/MAVLink/QGCMAVLink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ QGCMAVLink::QGCMAVLink(QObject *parent)
{
// qCDebug(StatusTextHandlerLog) << Q_FUNC_INFO << this;

qRegisterMetaType<mavlink_message_t>("mavlink_message_t");
qRegisterMetaType<MAV_TYPE>("MAV_TYPE");
qRegisterMetaType<MAV_AUTOPILOT>("MAV_AUTOPILOT");
(void) qRegisterMetaType<mavlink_message_t>("mavlink_message_t");
(void) qRegisterMetaType<MAV_TYPE>("MAV_TYPE");
(void) qRegisterMetaType<MAV_AUTOPILOT>("MAV_AUTOPILOT");
(void) qRegisterMetaType<GRIPPER_ACTIONS>("GRIPPER_ACTIONS");
}

QGCMAVLink::~QGCMAVLink()
Expand Down
1 change: 1 addition & 0 deletions src/MAVLink/QGCMAVLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,4 @@ class QGCMAVLink : public QObject

static mavlink_status_t* getChannelStatus(mavlink_channel_t channel) { return mavlink_get_channel_status(static_cast<uint8_t>(channel)); }
};
Q_DECLARE_METATYPE(GRIPPER_ACTIONS)
2 changes: 0 additions & 2 deletions src/Utilities/QGCLoggingCategory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ QGC_LOGGING_CATEGORY(ParameterManagerLog, "ParameterManagerLog")
QGC_LOGGING_CATEGORY(GuidedActionsControllerLog, "GuidedActionsControllerLog")
QGC_LOGGING_CATEGORY(LocalizationLog, "LocalizationLog")
QGC_LOGGING_CATEGORY(VideoAllLog, kVideoAllLogCategory)
QGC_LOGGING_CATEGORY(JoystickLog, "JoystickLog")


QGCLoggingCategoryRegister* _instance = nullptr;

Expand Down
1 change: 0 additions & 1 deletion src/Utilities/QGCLoggingCategory.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Q_DECLARE_LOGGING_CATEGORY(ParameterManagerLog)
Q_DECLARE_LOGGING_CATEGORY(GuidedActionsControllerLog)
Q_DECLARE_LOGGING_CATEGORY(LocalizationLog)
Q_DECLARE_LOGGING_CATEGORY(VideoAllLog) // turns on all individual QGC video logs
Q_DECLARE_LOGGING_CATEGORY(JoystickLog)

/// @def QGC_LOGGING_CATEGORY
/// This is a QGC specific replacement for Q_LOGGING_CATEGORY. It will register the category name into a
Expand Down

0 comments on commit 744f00c

Please sign in to comment.