diff options
Diffstat (limited to 'ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp')
-rw-r--r-- | ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp | 82 |
1 files changed, 29 insertions, 53 deletions
diff --git a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp index f9789dce..bb1076dd 100644 --- a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp +++ b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp @@ -1,17 +1,13 @@ #include "ftnoir_tracker_joystick.h" -#include "facetracknoir/global-settings.h" -#undef NDEBUG +#include "facetracknoir/plugin-support.h" #include <QMutexLocker> FTNoIR_Tracker::FTNoIR_Tracker() : g_pDI(nullptr), g_pJoystick(nullptr), - iter(-1), - mtx(QMutex::Recursive) + mtx(QMutex::Recursive), + iter(-1) { - for (int i = 0; i < 6; i++) - min_[i] = max_[i] = 0; - GUID bar = {0}; } void FTNoIR_Tracker::reload() @@ -45,13 +41,13 @@ FTNoIR_Tracker::~FTNoIR_Tracker() } } +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" + static BOOL CALLBACK EnumObjectsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi, VOID* pContext ) { auto self = (FTNoIR_Tracker*) pContext; - // For axes that are returned, set the DIPROP_RANGE property for the - // enumerated axis in order to scale min/max values. if( pdidoi->dwType & DIDFT_AXIS ) { DIPROPRANGE diprg = {0}; @@ -59,15 +55,12 @@ static BOOL CALLBACK EnumObjectsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi, diprg.diph.dwHeaderSize = sizeof( DIPROPHEADER ); diprg.diph.dwHow = DIPH_BYID; diprg.diph.dwObj = pdidoi->dwType; + diprg.lMax = FTNoIR_Tracker::AXIS_MAX; + diprg.lMin = -FTNoIR_Tracker::AXIS_MAX; - // Set the range for the axis - - if( FAILED( self->g_pJoystick->GetProperty( DIPROP_RANGE, &diprg.diph ) ) ) + if( FAILED( self->g_pJoystick->SetProperty( DIPROP_RANGE, &diprg.diph ) ) ) return DIENUM_STOP; - self->min_[self->iter] = diprg.lMin; - self->max_[self->iter] = diprg.lMax; - qDebug() << "axis" << self->iter << diprg.lMin << diprg.lMax; self->iter++; } @@ -138,8 +131,6 @@ void FTNoIR_Tracker::StartTracker(QFrame* frame) goto fail; } - qDebug() << "joy init success"; - return; fail: @@ -161,18 +152,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; @@ -196,35 +195,12 @@ void FTNoIR_Tracker::GetHeadPoseData(double *data) 90, 180 }; - - int axes[] = { - s.axis_0, - s.axis_1, - s.axis_2, - s.axis_3, - s.axis_4, - s.axis_5 - }; - + for (int i = 0; i < 6; i++) - { - auto idx = axes[i] - 1; - if (idx < 0 || idx > 7) - { - data[i] = 0; - } - else { - auto mid = (min_[idx] + max_[idx]) / 2; - auto val = values[idx] - mid; - - auto max = (max_[idx] - min_[idx]) / 2; - auto min = (min_[idx] - max_[idx]) / -2; - data[i] = val * limits[i] / (double) (val >= 0 ? max : min); - } - } + data[i] = values[i] * limits[i] / AXIS_MAX; } -extern "C" FTNOIR_TRACKER_BASE_EXPORT ITracker* CALLING_CONVENTION GetConstructor() +extern "C" OPENTRACK_EXPORT ITracker* GetConstructor() { return new FTNoIR_Tracker; } |