mainwindow.cpp
periodiceffectsettings.cpp
rampeffectsettings.cpp
- rumbleeffectsettings.cpp)
+ rumbleeffectsettings.cpp
+ sdl2deviceprober.cpp)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
if (SDL2_FOUND)
#include "globalsettings.h"
#include "linuxdeviceprober.h"
+#include "sdl2deviceprober.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtWidgets/QMessageBox>
/* Fill the list of available interfaces */
ui->cbox_interfaces->addItem("Linux API", static_cast<std::underlying_type<DeviceProber::DeviceInterfaces>::type>(DeviceProber::DeviceInterfaces::LINUX));
#ifdef FFBC_HAVE_SDL2
- ui->cbox_interfaces->addItem("SDL2", static_cast<std::underlying_type<DeviceProber::DeviceInterfaces>::type>(DeviceProber::DeviceInterfaces::SDL2));
+ if (SDL2DeviceProber::initializeSDL())
+ ui->cbox_interfaces->addItem("SDL2", static_cast<std::underlying_type<DeviceProber::DeviceInterfaces>::type>(DeviceProber::DeviceInterfaces::SDL2));
#endif
ui->cbox_interfaces->setCurrentIndex(0);
case DeviceProber::DeviceInterfaces::LINUX:
prober = std::make_shared<LinuxDeviceProber>();
break;
+#ifdef FFBC_HAVE_SDL2
+ case DeviceProber::DeviceInterfaces::SDL2:
+ prober = std::make_shared<SDL2DeviceProber>();
+ break;
+#endif
default:
QMessageBox::critical(this, "Cannot probe devices", "Selected interface is not supported yet.");
break;
--- /dev/null
+#include "sdl2deviceprober.h"
+#include <QtCore/QDebug>
+#include <QtWidgets/QMessageBox>
+
+bool SDL2DeviceProber::s_SDLInited = false;
+
+bool SDL2DeviceProber::initializeSDL()
+{
+ int ret;
+
+ if (s_SDLInited)
+ return true;
+
+ ret = SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC);
+ if (ret == 0) {
+ s_SDLInited = true;
+ return true;
+ }
+
+ QMessageBox::warning(nullptr, "SDL2 error",
+ QString("Unable to initialize SDL2 (%1). SDL2 interface will not be available.").arg(SDL_GetError()));
+ return false;
+}
+
+void SDL2DeviceProber::closeAllDevices()
+{
+ if (!s_SDLInited)
+ return;
+
+ return;
+}
+
+
+DeviceProber::DeviceList SDL2DeviceProber::listDevices()
+{
+ DeviceProber::DeviceList devList;
+ int numJoy;
+
+ if (!s_SDLInited)
+ return devList;
+
+ numJoy = SDL_NumJoysticks();
+
+ for (int idx = 0; idx < numJoy; idx++) {
+ DeviceProber::DeviceInfo dinfo;
+
+ SDL_Joystick* joystick = SDL_JoystickOpen(idx);
+
+ if (joystick == nullptr) {
+ qDebug() << "SDL2: Cannot open joystick at idx" << idx;
+ continue;
+ }
+
+ if (SDL_JoystickIsHaptic(joystick) != 1) {
+ qDebug() << "SDL2: Joystick at idx" << idx << "does not support force feedback";
+ SDL_JoystickClose(joystick);
+ continue;
+ }
+
+ dinfo.name = QString(SDL_JoystickName(joystick));
+ dinfo.id = QVariant(idx);
+
+ devList.push_back(dinfo);
+ SDL_JoystickClose(joystick);
+ }
+
+ return devList;
+}
+
+std::shared_ptr<FFBDevice> SDL2DeviceProber::openDevice(const QString& id)
+{
+ if (!s_SDLInited)
+ return nullptr;
+
+ return nullptr;
+}
+
--- /dev/null
+#ifndef SDL2DEVICEPROBER_H
+#define SDL2DEVICEPROBER_H
+
+#include "deviceprober.h"
+#include "SDL.h"
+
+class SDL2DeviceProber : public DeviceProber
+{
+public:
+ static bool initializeSDL();
+
+ explicit SDL2DeviceProber() : DeviceProber(DeviceInterfaces::SDL2) {}
+ void closeAllDevices();
+ DeviceList listDevices();
+ std::shared_ptr<FFBDevice> openDevice(const QString& id);
+
+private:
+ static bool s_SDLInited;
+
+
+};
+
+#endif // SDL2DEVICEPROBER_H
\ No newline at end of file