You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
6.5 KiB

7 years ago
​
​
​
​
​
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
  1. #ifndef __JOYSTICK_OBJECT_HEADER__
  2. #define __JOYSTICK_OBJECT_HEADER__
  3. #ifndef __linux__
  4. //Windows Joystick implementation
  5. #include <WinSock2.h>
  6. #include <math.h>
  7. #ifndef STRICT
  8. #define STRICT 1
  9. #endif
  10. #define DIRECTINPUT_VERSION 0x0800
  11. #ifndef _CRT_SECURE_NO_DEPRECATE
  12. #define _CRT_SECURE_NO_DEPRECATE
  13. #endif
  14. #ifndef _WIN32_DCOM
  15. #define _WIN32_DCOM
  16. #endif
  17. #include <windows.h>
  18. #include <commctrl.h>
  19. #include <basetsd.h>
  20. #include <dinput.h>
  21. #include <dinputd.h>
  22. #include <assert.h>
  23. #include <oleauto.h>
  24. #include <shellapi.h>
  25. //#pragma warning( disable : 4996 ) // disable deprecated warning
  26. //#include <strsafe.h>
  27. //#pragma warning( default : 4996 )
  28. //#include <Windows.h>
  29. //#include <tchar.h>
  30. #define _USE_MATH_DEFINES
  31. #ifndef M_E
  32. #include <math.h>
  33. #endif
  34. //#include <hidsdi.h>
  35. #include "../../components/base/basicLogCollection.h"
  36. #include "../../components/base/basicSettingsProvider.h"
  37. #include "../../components/base/basicThread.h"
  38. #include "../../gui/guiClass.h"
  39. #define IDI_MAIN 102
  40. #define IDD_JOYST_IMM 103
  41. #define IDR_ACCELERATOR1 103
  42. #define IDC_CLOSE 1001
  43. #define IDC_X_AXIS 1010
  44. #define IDC_Y_AXIS 1011
  45. #define IDC_Z_AXIS 1012
  46. #define IDC_X_AXIS_TEXT 1013
  47. #define IDC_Y_AXIS_TEXT 1014
  48. #define IDC_Z_AXIS_TEXT 1015
  49. #define IDC_X_ROT_TEXT 1016
  50. #define IDC_Y_ROT_TEXT 1017
  51. #define IDC_Z_ROT_TEXT 1018
  52. #define IDC_SLIDER0_TEXT 1019
  53. #define IDC_X_ROT 1020
  54. #define IDC_Y_ROT 1021
  55. #define IDC_Z_ROT 1022
  56. #define IDC_SLIDER1_TEXT 1023
  57. #define IDC_POV0_TEXT 1024
  58. #define IDC_POV1_TEXT 1025
  59. #define IDC_POV2_TEXT 1026
  60. #define IDC_POV3_TEXT 1027
  61. #define IDC_SLIDER0 1030
  62. #define IDC_SLIDER1 1031
  63. #define IDC_POV 1040
  64. #define IDC_POV0 1040
  65. #define IDC_BUTTONS 1041
  66. #define IDC_POV1 1042
  67. #define IDC_POV2 1043
  68. #define IDC_POV3 1044
  69. // Next default values for new objects
  70. //
  71. #ifdef APSTUDIO_INVOKED
  72. #ifndef APSTUDIO_READONLY_SYMBOLS
  73. #define _APS_NEXT_RESOURCE_VALUE 104
  74. #define _APS_NEXT_COMMAND_VALUE 40001
  75. #define _APS_NEXT_CONTROL_VALUE 1025
  76. #define _APS_NEXT_SYMED_VALUE 101
  77. #endif
  78. #endif
  79. #define MAX_BUTTONS 128
  80. class joysticObject : public basicThread{
  81. private:
  82. basicLogCollection *m_pLog;
  83. config_setting_t *m_pSettings;
  84. DIJOYSTATE2 m_sJoystickState; // DInput joystick state
  85. bool m_bPresented;
  86. bool m_bActive;
  87. bool bButtonStates[MAX_BUTTONS];
  88. long lAxisX;
  89. long lAxisY;
  90. long lAxisZ;
  91. long lAxisRz;
  92. long lHat;
  93. int m_nNumberOfButtons;
  94. static BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, VOID* pContext );
  95. public:
  96. // Method to fetch singleton instance.
  97. static joysticObject* getInstance();
  98. // Destructor
  99. ~joysticObject();
  100. bool isActive( void ) { return m_bActive; };
  101. bool isPresent( void ){ return m_bPresented; };
  102. int getBtnCnt( void ){ return m_nNumberOfButtons; };
  103. bool getButton( uint8_t id ){return(!m_bPresented)?false:bButtonStates[id];};
  104. long getAxisX( void ){return(!m_bPresented)?0:lAxisX;};
  105. long getAxisY( void ){return(!m_bPresented)?0:lAxisY;};
  106. long getAxisZ( void ){return(!m_bPresented)?0:lAxisZ;};
  107. long getAxisRz( void ){return(!m_bPresented)?0:lAxisRz;};
  108. long getHat( void ){return(!m_bPresented)?0:lHat;};
  109. protected:
  110. // Constructor - protected so users cannot call it.
  111. joysticObject();
  112. void m_fThreadProc(void);
  113. private:
  114. // private static member referencing the single instance of the object
  115. // TODO: Replace mediaVideoSourceManager with the type of object you want to
  116. // return the single instance of
  117. static joysticObject* _instance;
  118. // Copy constructor
  119. // Declared but not defined to prevent auto-generated
  120. // copy constructor. Refer to "Effective C++" by Meyers
  121. joysticObject(const joysticObject& src);
  122. // Assignment operator
  123. // Declared but not defined to prevent auto-generated
  124. // assignment operator. Refer to "Effective C++" by Meyers
  125. joysticObject& operator=(const joysticObject& src);
  126. };
  127. #else
  128. // Linux Joystick Implementation
  129. #include "../../components/base/basicLogCollection.h"
  130. #include "../../components/base/basicSettingsProvider.h"
  131. #include "../../components/base/basicThread.h"
  132. #include "../../gui/guiClass.h"
  133. #define MAX_BUTTONS 32
  134. class joysticObject : public basicThread{
  135. private:
  136. basicLogCollection *m_pLog;
  137. config_setting_t *m_pSettings;
  138. bool m_bPresented;
  139. bool m_bActive;
  140. bool bButtonStates[MAX_BUTTONS];
  141. long lAxisX;
  142. long lAxisY;
  143. long lAxisZ;
  144. long lAxisRz;
  145. long lHat;
  146. int m_nNumberOfButtons;
  147. public:
  148. // Method to fetch singleton instance.
  149. static joysticObject* getInstance();
  150. // Destructor
  151. ~joysticObject();
  152. bool isActive( void ) { return m_bActive; };
  153. bool isPresent( void ){ return m_bPresented; };
  154. int getBtnCnt( void ){ return m_nNumberOfButtons; };
  155. bool getButton( uint8_t id ){return(!m_bPresented)?false:bButtonStates[id];};
  156. long getAxisX( void ){return(!m_bPresented)?0:lAxisX;};
  157. long getAxisY( void ){return(!m_bPresented)?0:lAxisY;};
  158. long getAxisZ( void ){return(!m_bPresented)?0:lAxisZ;};
  159. long getAxisRz( void ){return(!m_bPresented)?0:lAxisRz;};
  160. long getHat( void ){return(!m_bPresented)?0:lHat;};
  161. protected:
  162. // Constructor - protected so users cannot call it.
  163. joysticObject();
  164. void m_fThreadProc(void);
  165. private:
  166. // private static member referencing the single instance of the object
  167. // TODO: Replace mediaVideoSourceManager with the type of object you want to
  168. // return the single instance of
  169. static joysticObject* _instance;
  170. // Copy constructor
  171. // Declared but not defined to prevent auto-generated
  172. // copy constructor. Refer to "Effective C++" by Meyers
  173. joysticObject(const joysticObject& src);
  174. // Assignment operator
  175. // Declared but not defined to prevent auto-generated
  176. // assignment operator. Refer to "Effective C++" by Meyers
  177. joysticObject& operator=(const joysticObject& src);
  178. };
  179. #endif
  180. #endif