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.

561 lines
20 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
  1. #include "joystick.h"
  2. #define LOG( X ) m_pLog->Log( "J0YSTICK", this, X )
  3. #define LOG_ERROR( X ) m_pLog->Log( "J0YSTICK", this, _LOG_ERROR, X )
  4. #ifdef __linux__
  5. joysticObject* joysticObject::_instance = 0;
  6. joysticObject* joysticObject::getInstance() {
  7. // check if the instance has been created yet
  8. if (0 == _instance) {
  9. // if not, then create it
  10. _instance = new joysticObject;
  11. }
  12. // return the single instance
  13. return _instance;
  14. };
  15. joysticObject::joysticObject(): basicThread(){
  16. };
  17. void joysticObject::m_fThreadProc(void){
  18. };
  19. #else
  20. // Stuff to filter out XInput devices
  21. #include <wbemidl.h>
  22. HRESULT SetupForIsXInputDevice();
  23. bool IsXInputDevice( const GUID* pGuidProductFromDirectInput );
  24. void CleanupForIsXInputDevice();
  25. struct XINPUT_DEVICE_NODE{
  26. DWORD dwVidPid;
  27. XINPUT_DEVICE_NODE* pNext;
  28. };
  29. struct DI_ENUM_CONTEXT{
  30. DIJOYCONFIG* pPreferredJoyCfg;
  31. bool bPreferredJoyCfgValid;
  32. };
  33. bool g_bFilterOutXinputDevices = false;
  34. XINPUT_DEVICE_NODE* g_pXInputDeviceList = NULL;
  35. //-----------------------------------------------------------------------------
  36. // Defines, constants, and global variables
  37. //-----------------------------------------------------------------------------
  38. #define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
  39. #define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
  40. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  41. #define CHECK(exp) { if(!(exp)) goto Error; }
  42. #define SAFE_FREE(p) { if(p) { HeapFree(hHeap, 0, p); (p) = NULL; } }
  43. joysticObject* joysticObject::_instance = 0;
  44. LPDIRECTINPUT8 m_pDI;
  45. LPDIRECTINPUTDEVICE8 m_pJoystick;
  46. /**
  47. * Returns the single instance of the object.
  48. */
  49. joysticObject* joysticObject::getInstance() {
  50. // check if the instance has been created yet
  51. if (0 == _instance) {
  52. // if not, then create it
  53. _instance = new joysticObject;
  54. }
  55. // return the single instance
  56. return _instance;
  57. };
  58. //https://forum.qt.io/topic/66064/how-to-get-mouse-actual-position/9
  59. //-----------------------------------------------------------------------------
  60. // Enum each PNP device using WMI and check each device ID to see if it contains
  61. // "IG_" (ex. "VID_045E&PID_028E&IG_00"). If it does, then it�s an XInput device
  62. // Unfortunately this information can not be found by just using DirectInput.
  63. // Checking against a VID/PID of 0x028E/0x045E won't find 3rd party or future
  64. // XInput devices.
  65. //
  66. // This function stores the list of xinput devices in a linked list
  67. // at g_pXInputDeviceList, and IsXInputDevice() searchs that linked list
  68. //-----------------------------------------------------------------------------
  69. HRESULT SetupForIsXInputDevice(){
  70. IWbemServices* pIWbemServices = NULL;
  71. IEnumWbemClassObject* pEnumDevices = NULL;
  72. IWbemLocator* pIWbemLocator = NULL;
  73. IWbemClassObject* pDevices[20] = {0};
  74. BSTR bstrDeviceID = NULL;
  75. BSTR bstrClassName = NULL;
  76. BSTR bstrNamespace = NULL;
  77. DWORD uReturned = 0;
  78. bool bCleanupCOM = false;
  79. UINT iDevice = 0;
  80. VARIANT var;
  81. HRESULT hr;
  82. // CoInit if needed
  83. hr = CoInitialize( NULL );
  84. bCleanupCOM = SUCCEEDED( hr );
  85. // Create WMI
  86. hr = CoCreateInstance( __uuidof( WbemLocator ),
  87. NULL,
  88. CLSCTX_INPROC_SERVER,
  89. __uuidof( IWbemLocator ),
  90. ( LPVOID* )&pIWbemLocator );
  91. if( FAILED( hr ) || pIWbemLocator == NULL )
  92. goto LCleanup;
  93. // Create BSTRs for WMI
  94. bstrNamespace = SysAllocString( L"\\\\.\\root\\cimv2" ); if( bstrNamespace == NULL ) goto LCleanup;
  95. bstrDeviceID = SysAllocString( L"DeviceID" ); if( bstrDeviceID == NULL ) goto LCleanup;
  96. bstrClassName = SysAllocString( L"Win32_PNPEntity" ); if( bstrClassName == NULL ) goto LCleanup;
  97. // Connect to WMI
  98. hr = pIWbemLocator->ConnectServer( bstrNamespace, NULL, NULL, 0L,
  99. 0L, NULL, NULL, &pIWbemServices );
  100. if( FAILED( hr ) || pIWbemServices == NULL )
  101. goto LCleanup;
  102. // Switch security level to IMPERSONATE
  103. CoSetProxyBlanket( pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
  104. RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, 0 );
  105. // Get list of Win32_PNPEntity devices
  106. hr = pIWbemServices->CreateInstanceEnum( bstrClassName, 0, NULL, &pEnumDevices );
  107. if( FAILED( hr ) || pEnumDevices == NULL )
  108. goto LCleanup;
  109. // Loop over all devices
  110. for(; ; )
  111. {
  112. // Get 20 at a time
  113. hr = pEnumDevices->Next( 10000, 20, pDevices, &uReturned );
  114. if( FAILED( hr ) )
  115. goto LCleanup;
  116. if( uReturned == 0 )
  117. break;
  118. for( iDevice = 0; iDevice < uReturned; iDevice++ )
  119. {
  120. // For each device, get its device ID
  121. hr = pDevices[iDevice]->Get( bstrDeviceID, 0L, &var, NULL, NULL );
  122. if( SUCCEEDED( hr ) && var.vt == VT_BSTR && var.bstrVal != NULL )
  123. {
  124. // Check if the device ID contains "IG_". If it does, then it�s an XInput device
  125. // Unfortunately this information can not be found by just using DirectInput
  126. if( wcsstr( var.bstrVal, L"IG_" ) )
  127. {
  128. // If it does, then get the VID/PID from var.bstrVal
  129. DWORD dwPid = 0, dwVid = 0;
  130. WCHAR* strVid = wcsstr( var.bstrVal, L"VID_" );
  131. if( strVid && swscanf( strVid, L"VID_%4X", &dwVid ) != 1 )
  132. dwVid = 0;
  133. WCHAR* strPid = wcsstr( var.bstrVal, L"PID_" );
  134. if( strPid && swscanf( strPid, L"PID_%4X", &dwPid ) != 1 )
  135. dwPid = 0;
  136. DWORD dwVidPid = MAKELONG( dwVid, dwPid );
  137. // Add the VID/PID to a linked list
  138. XINPUT_DEVICE_NODE* pNewNode = new XINPUT_DEVICE_NODE;
  139. if( pNewNode )
  140. {
  141. pNewNode->dwVidPid = dwVidPid;
  142. pNewNode->pNext = g_pXInputDeviceList;
  143. g_pXInputDeviceList = pNewNode;
  144. }
  145. }
  146. }
  147. SAFE_RELEASE( pDevices[iDevice] );
  148. }
  149. }
  150. LCleanup:
  151. if( bstrNamespace )
  152. SysFreeString( bstrNamespace );
  153. if( bstrDeviceID )
  154. SysFreeString( bstrDeviceID );
  155. if( bstrClassName )
  156. SysFreeString( bstrClassName );
  157. for( iDevice = 0; iDevice < 20; iDevice++ )
  158. SAFE_RELEASE( pDevices[iDevice] );
  159. SAFE_RELEASE( pEnumDevices );
  160. SAFE_RELEASE( pIWbemLocator );
  161. SAFE_RELEASE( pIWbemServices );
  162. return hr;
  163. };
  164. //-----------------------------------------------------------------------------
  165. // Returns true if the DirectInput device is also an XInput device.
  166. // Call SetupForIsXInputDevice() before, and CleanupForIsXInputDevice() after
  167. //-----------------------------------------------------------------------------
  168. bool IsXInputDevice( const GUID* pGuidProductFromDirectInput ){
  169. // Check each xinput device to see if this device's vid/pid matches
  170. XINPUT_DEVICE_NODE* pNode = g_pXInputDeviceList;
  171. while( pNode ){
  172. if( pNode->dwVidPid == pGuidProductFromDirectInput->Data1 )
  173. return true;
  174. pNode = pNode->pNext;
  175. };
  176. return false;
  177. };
  178. //-----------------------------------------------------------------------------
  179. // Cleanup needed for IsXInputDevice()
  180. //-----------------------------------------------------------------------------
  181. void CleanupForIsXInputDevice(){
  182. // Cleanup linked list
  183. XINPUT_DEVICE_NODE* pNode = g_pXInputDeviceList;
  184. while( pNode ){
  185. XINPUT_DEVICE_NODE* pDelete = pNode;
  186. pNode = pNode->pNext;
  187. SAFE_DELETE( pDelete );
  188. };
  189. };
  190. //-----------------------------------------------------------------------------
  191. // Name: EnumJoysticksCallback()
  192. // Desc: Called once for each enumerated joystick. If we find one, create a
  193. // device interface on it so we can play with it.
  194. //-----------------------------------------------------------------------------
  195. BOOL CALLBACK joysticObject::EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance,
  196. VOID* pContext ){
  197. DI_ENUM_CONTEXT* pEnumContext = ( DI_ENUM_CONTEXT* )pContext;
  198. HRESULT hr;
  199. if( g_bFilterOutXinputDevices && IsXInputDevice( &pdidInstance->guidProduct ) )
  200. return DIENUM_CONTINUE;
  201. // Skip anything other than the perferred joystick device as defined by the control panel.
  202. // Instead you could store all the enumerated joysticks and let the user pick.
  203. if( pEnumContext->bPreferredJoyCfgValid &&
  204. !IsEqualGUID( pdidInstance->guidInstance, pEnumContext->pPreferredJoyCfg->guidInstance ) )
  205. return DIENUM_CONTINUE;
  206. // Obtain an interface to the enumerated joystick.
  207. hr = m_pDI->CreateDevice( pdidInstance->guidInstance, &m_pJoystick, NULL );
  208. // If it failed, then we can't use this joystick. (Maybe the user unplugged
  209. // it while we were in the middle of enumerating it.)
  210. if( FAILED( hr ) )
  211. return DIENUM_CONTINUE;
  212. // Stop enumeration. Note: we're just taking the first joystick we get. You
  213. // could store all the enumerated joysticks and let the user pick.
  214. return DIENUM_STOP;
  215. };
  216. //-----------------------------------------------------------------------------
  217. // Name: EnumObjectsCallback()
  218. // Desc: Callback function for enumerating objects (axes, buttons, POVs) on a
  219. // joystick. This function enables user interface elements for objects
  220. // that are found to exist, and scales axes min/max values.
  221. //-----------------------------------------------------------------------------
  222. BOOL CALLBACK EnumObjectsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
  223. VOID* pContext )
  224. {
  225. HWND hDlg = ( HWND )pContext;
  226. static int nSliderCount = 0; // Number of returned slider controls
  227. static int nPOVCount = 0; // Number of returned POV controls
  228. // For axes that are returned, set the DIPROP_RANGE property for the
  229. // enumerated axis in order to scale min/max values.
  230. if( pdidoi->dwType & DIDFT_AXIS )
  231. {
  232. DIPROPRANGE diprg;
  233. diprg.diph.dwSize = sizeof( DIPROPRANGE );
  234. diprg.diph.dwHeaderSize = sizeof( DIPROPHEADER );
  235. diprg.diph.dwHow = DIPH_BYID;
  236. diprg.diph.dwObj = pdidoi->dwType; // Specify the enumerated axis
  237. diprg.lMin = -1000;
  238. diprg.lMax = +1000;
  239. // Set the range for the axis
  240. if( FAILED( m_pJoystick->SetProperty( DIPROP_RANGE, &diprg.diph ) ) )
  241. return DIENUM_STOP;
  242. }
  243. // Set the UI to reflect what objects the joystick supports
  244. if( pdidoi->guidType == GUID_XAxis )
  245. {
  246. EnableWindow( GetDlgItem( hDlg, IDC_X_AXIS ), TRUE );
  247. EnableWindow( GetDlgItem( hDlg, IDC_X_AXIS_TEXT ), TRUE );
  248. }
  249. if( pdidoi->guidType == GUID_YAxis )
  250. {
  251. EnableWindow( GetDlgItem( hDlg, IDC_Y_AXIS ), TRUE );
  252. EnableWindow( GetDlgItem( hDlg, IDC_Y_AXIS_TEXT ), TRUE );
  253. }
  254. if( pdidoi->guidType == GUID_ZAxis )
  255. {
  256. EnableWindow( GetDlgItem( hDlg, IDC_Z_AXIS ), TRUE );
  257. EnableWindow( GetDlgItem( hDlg, IDC_Z_AXIS_TEXT ), TRUE );
  258. }
  259. if( pdidoi->guidType == GUID_RxAxis )
  260. {
  261. EnableWindow( GetDlgItem( hDlg, IDC_X_ROT ), TRUE );
  262. EnableWindow( GetDlgItem( hDlg, IDC_X_ROT_TEXT ), TRUE );
  263. }
  264. if( pdidoi->guidType == GUID_RyAxis )
  265. {
  266. EnableWindow( GetDlgItem( hDlg, IDC_Y_ROT ), TRUE );
  267. EnableWindow( GetDlgItem( hDlg, IDC_Y_ROT_TEXT ), TRUE );
  268. }
  269. if( pdidoi->guidType == GUID_RzAxis )
  270. {
  271. EnableWindow( GetDlgItem( hDlg, IDC_Z_ROT ), TRUE );
  272. EnableWindow( GetDlgItem( hDlg, IDC_Z_ROT_TEXT ), TRUE );
  273. }
  274. if( pdidoi->guidType == GUID_Slider )
  275. {
  276. switch( nSliderCount++ )
  277. {
  278. case 0 :
  279. EnableWindow( GetDlgItem( hDlg, IDC_SLIDER0 ), TRUE );
  280. EnableWindow( GetDlgItem( hDlg, IDC_SLIDER0_TEXT ), TRUE );
  281. break;
  282. case 1 :
  283. EnableWindow( GetDlgItem( hDlg, IDC_SLIDER1 ), TRUE );
  284. EnableWindow( GetDlgItem( hDlg, IDC_SLIDER1_TEXT ), TRUE );
  285. break;
  286. }
  287. }
  288. if( pdidoi->guidType == GUID_POV )
  289. {
  290. switch( nPOVCount++ )
  291. {
  292. case 0 :
  293. EnableWindow( GetDlgItem( hDlg, IDC_POV0 ), TRUE );
  294. EnableWindow( GetDlgItem( hDlg, IDC_POV0_TEXT ), TRUE );
  295. break;
  296. case 1 :
  297. EnableWindow( GetDlgItem( hDlg, IDC_POV1 ), TRUE );
  298. EnableWindow( GetDlgItem( hDlg, IDC_POV1_TEXT ), TRUE );
  299. break;
  300. case 2 :
  301. EnableWindow( GetDlgItem( hDlg, IDC_POV2 ), TRUE );
  302. EnableWindow( GetDlgItem( hDlg, IDC_POV2_TEXT ), TRUE );
  303. break;
  304. case 3 :
  305. EnableWindow( GetDlgItem( hDlg, IDC_POV3 ), TRUE );
  306. EnableWindow( GetDlgItem( hDlg, IDC_POV3_TEXT ), TRUE );
  307. break;
  308. }
  309. }
  310. return DIENUM_CONTINUE;
  311. }
  312. // Constructor implementation
  313. joysticObject::joysticObject() : basicThread(){
  314. m_pLog = basicLogCollection::getInstance();
  315. m_pSettings = basicSettingsProvider::getInstance()->getSubNode(NULL, "JOYSTICK");
  316. m_bPresented = false;
  317. m_pDI = NULL;
  318. m_pJoystick = NULL;
  319. m_nNumberOfButtons = -1;
  320. //
  321. // Register for joystick devices
  322. //
  323. HRESULT hr;
  324. // Register with the DirectInput subsystem and get a pointer
  325. // to a IDirectInput interface we can use.
  326. // Create a DInput object
  327. if( FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION,
  328. IID_IDirectInput8, ( VOID** )&m_pDI, NULL ) ) ) return;
  329. if( g_bFilterOutXinputDevices ) SetupForIsXInputDevice();
  330. DIJOYCONFIG PreferredJoyCfg = {0};
  331. DI_ENUM_CONTEXT enumContext;
  332. enumContext.pPreferredJoyCfg = &PreferredJoyCfg;
  333. enumContext.bPreferredJoyCfgValid = false;
  334. IDirectInputJoyConfig8 *pJoyConfig = NULL;
  335. if( FAILED( hr = m_pDI->QueryInterface( IID_IDirectInputJoyConfig8, ( void** )&pJoyConfig ) ) ) return;
  336. PreferredJoyCfg.dwSize = sizeof( PreferredJoyCfg );
  337. // This function is expected to fail if no joystick is attached
  338. if( SUCCEEDED( pJoyConfig->GetConfig( 0, &PreferredJoyCfg, DIJC_GUIDINSTANCE ) ) ){
  339. enumContext.bPreferredJoyCfgValid = true;
  340. } else {
  341. // No Joy Today!
  342. };
  343. SAFE_RELEASE( pJoyConfig );
  344. // Look for a simple joystick we can use for this sample program.
  345. if( FAILED( hr = m_pDI->EnumDevices( DI8DEVCLASS_GAMECTRL,
  346. joysticObject::EnumJoysticksCallback,
  347. &enumContext, DIEDFL_ATTACHEDONLY ) ) ) return;
  348. if( g_bFilterOutXinputDevices ) CleanupForIsXInputDevice();
  349. // Make sure we got a joystick
  350. if( NULL == m_pJoystick ) {
  351. // No Joy Today!
  352. return;
  353. };
  354. // Set the data format to "simple joystick" - a predefined data format
  355. //
  356. // A data format specifies which controls on a device we are interested in,
  357. // and how they should be reported. This tells DInput that we will be
  358. // passing a DIJOYSTATE2 structure to IDirectInputDevice::GetDeviceState().
  359. if( FAILED( hr = m_pJoystick->SetDataFormat( &c_dfDIJoystick2 ) ) ) return;
  360. // Set the cooperative level to let DInput know how this device should
  361. // interact with the system and with other DInput applications.
  362. if( FAILED( hr = m_pJoystick->SetCooperativeLevel( (HWND)guiClass::getInstance()->getApp()->allWindows().at(0)->winId(),
  363. DISCL_BACKGROUND | DISCL_NONEXCLUSIVE
  364. //DISCL_FOREGROUND | DISCL_EXCLUSIVE
  365. ) ) ) return;
  366. // Enumerate the joystick objects. The callback function enabled user
  367. // interface elements for objects that are found, and sets the min/max
  368. // values property for discovered axes.
  369. if( FAILED( hr = m_pJoystick->EnumObjects( EnumObjectsCallback,
  370. (VOID*)guiClass::getInstance()->getApp()->allWindows().at(0)->winId(),
  371. DIDFT_ALL ) ) ) return;
  372. m_bPresented = true;
  373. basicThread::init();
  374. };
  375. // Destructor implementation
  376. joysticObject::~joysticObject(){
  377. m_bThreadStatus = TH_ENDED;
  378. // Unacquire the device one last time just in case
  379. // the app tried to exit while the device is still acquired.
  380. if( m_pJoystick ) m_pJoystick->Unacquire();
  381. m_bPresented = false;
  382. // Release any DirectInput objects.
  383. SAFE_RELEASE( m_pJoystick );
  384. SAFE_RELEASE( m_pDI );
  385. };
  386. void joysticObject::m_fThreadProc(void){
  387. HRESULT hr;
  388. m_bThreadStatus = TH_WORKING;
  389. LOG("Thread Started.");
  390. while( m_bThreadStatus == TH_WORKING ){
  391. if( NULL == m_pJoystick ) SLEEP(100);
  392. // Poll the device to read the current state
  393. hr = m_pJoystick->Poll();
  394. if( FAILED( hr ) ){
  395. // DInput is telling us that the input stream has been
  396. // interrupted. We aren't tracking any state between polls, so
  397. // we don't have any special reset that needs to be done. We
  398. // just re-acquire and try again.
  399. hr = m_pJoystick->Acquire();
  400. while( ( hr == DIERR_INPUTLOST ) && ( m_bThreadStatus == TH_WORKING ) ) hr = m_pJoystick->Acquire();
  401. // hr may be DIERR_OTHERAPPHASPRIO or other errors. This
  402. // may occur when the app is minimized or in the process of
  403. // switching, so just try again later
  404. continue;
  405. };
  406. // Get the input's device state
  407. if( FAILED( hr = m_pJoystick->GetDeviceState( sizeof( DIJOYSTATE2 ), &m_sJoystickState ) ) ){
  408. // The device should have been acquired during the Poll()
  409. SLEEP(50);
  410. continue;
  411. };
  412. lAxisX = m_sJoystickState.lX;
  413. lAxisY = m_sJoystickState.lY;
  414. lAxisZ = m_sJoystickState.lZ;
  415. lAxisRz = m_sJoystickState.lRz;
  416. lHat = m_sJoystickState.rglASlider[0];
  417. m_bActive = fabs((float)lAxisX) > 10.f;
  418. if (!m_bActive)m_bActive = fabs((float)lAxisY) > 10.f;
  419. if (!m_bActive)m_bActive = fabs((float)lAxisZ) > 10.f;
  420. if (!m_bActive)m_bActive = fabs((float)lAxisRz) > 10.f;
  421. //if (!m_bActive)m_bActive = fabs((float)lHat) > 10.f;
  422. SLEEP(10);
  423. /*
  424. // Display joystick state to dialog
  425. // Axes
  426. StringCchPrintf( strText, 512, TEXT( "%ld" ), js.lX );
  427. SetWindowText( GetDlgItem( hDlg, IDC_X_AXIS ), strText );
  428. StringCchPrintf( strText, 512, TEXT( "%ld" ), js.lY );
  429. SetWindowText( GetDlgItem( hDlg, IDC_Y_AXIS ), strText );
  430. StringCchPrintf( strText, 512, TEXT( "%ld" ), js.lZ );
  431. SetWindowText( GetDlgItem( hDlg, IDC_Z_AXIS ), strText );
  432. StringCchPrintf( strText, 512, TEXT( "%ld" ), js.lRx );
  433. SetWindowText( GetDlgItem( hDlg, IDC_X_ROT ), strText );
  434. StringCchPrintf( strText, 512, TEXT( "%ld" ), js.lRy );
  435. SetWindowText( GetDlgItem( hDlg, IDC_Y_ROT ), strText );
  436. StringCchPrintf( strText, 512, TEXT( "%ld" ), js.lRz );
  437. SetWindowText( GetDlgItem( hDlg, IDC_Z_ROT ), strText );
  438. // Slider controls
  439. StringCchPrintf( strText, 512, TEXT( "%ld" ), js.rglSlider[0] );
  440. SetWindowText( GetDlgItem( hDlg, IDC_SLIDER0 ), strText );
  441. StringCchPrintf( strText, 512, TEXT( "%ld" ), js.rglSlider[1] );
  442. SetWindowText( GetDlgItem( hDlg, IDC_SLIDER1 ), strText );
  443. // Points of view
  444. StringCchPrintf( strText, 512, TEXT( "%ld" ), js.rgdwPOV[0] );
  445. SetWindowText( GetDlgItem( hDlg, IDC_POV0 ), strText );
  446. StringCchPrintf( strText, 512, TEXT( "%ld" ), js.rgdwPOV[1] );
  447. SetWindowText( GetDlgItem( hDlg, IDC_POV1 ), strText );
  448. StringCchPrintf( strText, 512, TEXT( "%ld" ), js.rgdwPOV[2] );
  449. SetWindowText( GetDlgItem( hDlg, IDC_POV2 ), strText );
  450. StringCchPrintf( strText, 512, TEXT( "%ld" ), js.rgdwPOV[3] );
  451. SetWindowText( GetDlgItem( hDlg, IDC_POV3 ), strText );
  452. // Fill up text with which buttons are pressed
  453. StringCchCopy( strText, 512, TEXT( "" ) );
  454. for( int i = 0; i < MAX_BUTTONS; i++ ){
  455. if( js.rgbButtons[i] & 0x80 ){
  456. TCHAR sz[128];
  457. StringCchPrintf( sz, 128, TEXT( "%02d " ), i );
  458. StringCchCat( strText, 512, sz );
  459. };
  460. };
  461. SetWindowText( GetDlgItem( hDlg, IDC_BUTTONS ), strText );
  462. */
  463. };
  464. m_bThreadStatus = TH_ENDED;
  465. LOG("Thread Ended.");
  466. };
  467. #endif //Windows
  468. #undef LOG
  469. #undef LOG_ERROR