joyreadthread.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef JOYREADTHREAD_H
  2. #define JOYREADTHREAD_H
  3. #include <QThread>
  4. #include <QFile>
  5. #ifdef Q_OS_WIN
  6. #include "dinput.h"
  7. typedef bool (*LogiSteeringInitializeFunction)(bool ignoreXInputControllers);
  8. typedef bool (*LogiUpdateFunction)();
  9. //Check if a generic device at index is connected
  10. typedef bool (*LogiIsConnectedFunction)(const int index);
  11. //Get the state of the controller in the standard way.
  12. typedef DIJOYSTATE2* (*LogiGetStateFunction)(const int index);
  13. //Call this function to shutdown the SDK and destroy the controller and wheel objects
  14. typedef void (*LogiSteeringShutdownFunction)();
  15. //Play the constant force on the controller at index with the specified parameter
  16. typedef bool (*LogiPlayConstantForceFunction)(const int index, const int magnitudePercentage);
  17. //Stop the constant force on the controller at index
  18. typedef bool (*LogiStopConstantForceFunction)(const int index);
  19. #endif
  20. class JoyReadThread : public QThread
  21. {
  22. public:
  23. JoyReadThread();
  24. public:
  25. bool isOK();
  26. double GetWheel();
  27. double GetAcc();
  28. double GetBrake();
  29. int GetShift();
  30. private:
  31. void run();
  32. private:
  33. int fd;
  34. int axis_count;
  35. int button_count;
  36. std::string orig_name;
  37. QFile mxFile;
  38. QFile * mpFile;
  39. bool mbJoyOK = true;
  40. double mfWheel = 0;
  41. double mfAcc = 32767;
  42. double mfBrake = 32767;
  43. int mnShift = 0; //0 N >0 D -1 R
  44. private:
  45. #ifdef Q_OS_WIN
  46. LogiUpdateFunction LogiUpdate;
  47. LogiSteeringInitializeFunction LogiSteeringInitialize;
  48. LogiIsConnectedFunction LogiIsConnected;
  49. LogiGetStateFunction LogiGetState;
  50. LogiSteeringShutdownFunction LogiSteeringShutdown;
  51. LogiPlayConstantForceFunction LogiPlayConstantForce;
  52. LogiStopConstantForceFunction LogiStopConstantForce;
  53. void LoadAPI();
  54. #endif
  55. };
  56. #endif // JOYREADTHREAD_H