Skip to content
This repository has been archived by the owner on Aug 31, 2020. It is now read-only.

Commit

Permalink
Added detection of wireless gamepads - #64
Browse files Browse the repository at this point in the history
  • Loading branch information
juliagoda committed Nov 11, 2019
1 parent 1bcf412 commit 7c6c5d6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/gamecontroller/gamecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

GameController::GameController(SDL_GameController *controller, int deviceIndex,
AntiMicroSettings *settings, QObject *parent) :
InputDevice(deviceIndex, settings, parent)
InputDevice(SDL_GameControllerGetJoystick(controller), deviceIndex, settings, parent)
{

qInstallMessageHandler(MessageHandler::myMessageOutput);
Expand Down
3 changes: 2 additions & 1 deletion src/inputdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <QDebug>


InputDevice::InputDevice(int deviceIndex, AntiMicroSettings *settings, QObject *parent) :
InputDevice::InputDevice(SDL_Joystick* joystick, int deviceIndex, AntiMicroSettings *settings, QObject *parent) :
QObject(parent)
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
Expand All @@ -44,6 +44,7 @@ InputDevice::InputDevice(int deviceIndex, AntiMicroSettings *settings, QObject *
active_set = 0;
joystickID = 0;
keyPressTime = 0;
m_joyhandle = joystick;
deviceEdited = false;
#ifdef Q_OS_WIN
keyRepeatEnabled = true;
Expand Down
6 changes: 2 additions & 4 deletions src/inputdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class InputDevice : public QObject
Q_OBJECT

public:
explicit InputDevice(int deviceIndex, AntiMicroSettings *settings, QObject *parent = nullptr);
explicit InputDevice(SDL_Joystick* joystick, int deviceIndex, AntiMicroSettings *settings, QObject *parent = nullptr);
virtual ~InputDevice();

virtual int getNumberButtons();
Expand Down Expand Up @@ -135,13 +135,11 @@ class InputDevice : public QObject
bool elementsHaveNames();

QHash<int, SetJoystick*>& getJoystick_sets();
SDL_Joystick* getJoyHandle() const;

protected:
void enableSetConnections(SetJoystick *setstick);

SDL_Joystick* getJoyHandle() const;


QHash<int, JoyAxis::ThrottleTypes>& getCali();
SDL_JoystickID* getJoystickID();

Expand Down
2 changes: 1 addition & 1 deletion src/joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

Joystick::Joystick(SDL_Joystick *joyhandle, int deviceIndex,
AntiMicroSettings *settings, QObject *parent) :
InputDevice(deviceIndex, settings, parent)
InputDevice(joyhandle, deviceIndex, settings, parent)
{
qInstallMessageHandler(MessageHandler::myMessageOutput);

Expand Down
13 changes: 11 additions & 2 deletions src/joytabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,17 @@ void JoyTabWidget::changeJoyConfig(int index)
removeCurrentButtons();
emit forceTabUnflash(this);

QMetaObject::invokeMethod(&tabHelper, "readConfigFile", Qt::BlockingQueuedConnection,
Q_ARG(QString, filename));
qDebug() << "SDL Current Powerl Level: " << SDL_JoystickCurrentPowerLevel(m_joystick->getJoyHandle()) << "\n";

if (SDL_JoystickCurrentPowerLevel(m_joystick->getJoyHandle()) == SDL_JOYSTICK_POWER_WIRED ||
SDL_JoystickCurrentPowerLevel(m_joystick->getJoyHandle()) == SDL_JOYSTICK_POWER_UNKNOWN)
{
QMetaObject::invokeMethod(&tabHelper, "readConfigFile", Qt::BlockingQueuedConnection, Q_ARG(QString, filename));
}
else
{
tabHelper.readConfigFile(filename);
}

fillButtons();
refreshSetButtons();
Expand Down

0 comments on commit 7c6c5d6

Please sign in to comment.