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.

539 lines
20 KiB

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