summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2013-10-25 00:14:01 +0200
committerStanislaw Halik <sthalik@misaki.pl>2013-10-25 00:14:01 +0200
commit136a710a7fe94b9f55a2c297dea266ed2bd60367 (patch)
treeb065d0eecb0feb5a5b142d33c4cf536730765eb0 /ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp
parent4e3366194dad626247063b1505f7223836355377 (diff)
hopefully joy works, at least for me it does
Signed-off-by: Stanislaw Halik <sthalik@misaki.pl>
Diffstat (limited to 'ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp')
-rw-r--r--ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp44
1 files changed, 28 insertions, 16 deletions
diff --git a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp
index 97ac77e9..a132f472 100644
--- a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp
+++ b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp
@@ -21,9 +21,9 @@ FTNoIR_Tracker::FTNoIR_Tracker() :
mtx(QMutex::Recursive)
{
for (int i = 0; i < 6; i++)
- axes[i] = -1;
- GUID foo = {0};
- preferred = foo;
+ axes[i] = min_[i] = max_[i] = 0;
+ GUID bar = {0};
+ preferred = bar;
}
void FTNoIR_Tracker::reload()
@@ -68,15 +68,19 @@ static BOOL CALLBACK EnumObjectsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
diprg.diph.dwHeaderSize = sizeof( DIPROPHEADER );
diprg.diph.dwHow = DIPH_BYID;
diprg.diph.dwObj = pdidoi->dwType;
- diprg.lMin = -AXIS_MAX;
- diprg.lMax = AXIS_MAX;
// Set the range for the axis
- if( FAILED( self->g_pJoystick->SetProperty( DIPROP_RANGE, &diprg.diph ) ) )
+
+ if( FAILED( self->g_pJoystick->GetProperty( 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++;
}
- return DIENUM_CONTINUE;
+ return self->iter == 8 ? DIENUM_STOP : DIENUM_CONTINUE;
}
static BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, VOID* pContext )
@@ -94,6 +98,7 @@ static BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance
void FTNoIR_Tracker::StartTracker(QFrame* frame)
{
QMutexLocker foo(&mtx);
+ this->frame = frame;
iter = 0;
loadSettings();
auto hr = CoInitialize( nullptr );
@@ -134,7 +139,7 @@ void FTNoIR_Tracker::StartTracker(QFrame* frame)
goto fail;
}
- if (FAILED(g_pJoystick->SetDataFormat(&c_dfDIJoystick2)))
+ if (FAILED(g_pJoystick->SetDataFormat(&c_dfDIJoystick)))
{
qDebug() << "format";
goto fail;
@@ -146,6 +151,8 @@ void FTNoIR_Tracker::StartTracker(QFrame* frame)
goto fail;
}
+ iter = 0;
+
if( FAILED( hr = g_pJoystick->EnumObjects( EnumObjectsCallback,
( VOID* )this, DIDFT_ALL )))
{
@@ -171,9 +178,9 @@ fail:
bool FTNoIR_Tracker::GiveHeadPoseData(double *data)
{
QMutexLocker foo(&mtx);
- DIJOYSTATE2 js;
+ DIJOYSTATE js = {0};
- if( !g_pJoystick)
+ if( !g_pDI || !g_pJoystick)
return false;
start:
@@ -186,21 +193,21 @@ start:
goto start;
}
- if( FAILED( hr = g_pJoystick->GetDeviceState( sizeof( DIJOYSTATE2 ), &js ) ) )
+ if( FAILED( hr = g_pJoystick->GetDeviceState( sizeof( js ), &js ) ) )
return false;
const LONG values[] = {
- js.lX,
- js.lY,
- js.lZ,
js.lRx,
js.lRy,
js.lRz,
+ js.lX,
+ js.lY,
+ js.lZ,
js.rglSlider[0],
js.rglSlider[1]
};
- const double max[] = {
+ const double limits[] = {
100,
100,
100,
@@ -217,7 +224,12 @@ start:
data[i] = 0;
}
else {
- data[i] = values[i] * max[i] / (double) AXIS_MAX;
+ 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);
}
}