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.

141 lines
4.5 KiB

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