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.

143 lines
4.5 KiB

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