summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2014-09-09 07:46:15 +0200
committerStanislaw Halik <sthalik@misaki.pl>2014-09-09 07:46:15 +0200
commiteb9af9a745933f1e816a963ce2497f92f352159f (patch)
treefbd0b353d3226be4fd550ea3d35dede190fa33e3
parent54004b14d20d3b07db88e5a08a9c89a48b3efc17 (diff)
account for joy hot-unplug shenanigans and read failures
-rw-r--r--ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp
index 806ba91e..34ac0dca 100644
--- a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp
+++ b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp
@@ -161,18 +161,26 @@ void FTNoIR_Tracker::GetHeadPoseData(double *data)
if( !g_pDI || !g_pJoystick)
return;
- auto hr = g_pJoystick->Poll();
- if( FAILED( hr ))
- {
- hr = g_pJoystick->Acquire();
- for (int i = 0; hr == DIERR_INPUTLOST && i < 200; i++)
- hr = g_pJoystick->Acquire();
- if (hr != DI_OK)
+ bool ok = false;
+
+ for (int i = 0; i < 100; i++)
+ {
+ if (!FAILED(g_pJoystick->Poll()))
{
- qDebug() << "joy read failure" << hr;
- return;
+ ok = true;
+ break;
}
- }
+ if (g_pJoystick->Acquire() != DI_OK)
+ continue;
+ else
+ ok = true;
+ break;
+ }
+
+ if (!ok)
+ return;
+
+ HRESULT hr = 0;
if( FAILED( hr = g_pJoystick->GetDeviceState( sizeof( js ), &js ) ) )
return;