From eb9af9a745933f1e816a963ce2497f92f352159f Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 9 Sep 2014 07:46:15 +0200 Subject: account for joy hot-unplug shenanigans and read failures --- .../ftnoir_tracker_joystick.cpp | 28 ++++++++++++++-------- 1 file 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; -- cgit v1.2.3