summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_tracker_joystick
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2014-09-13 11:24:01 +0200
committerStanislaw Halik <sthalik@misaki.pl>2014-09-13 11:32:36 +0200
commit9e21f5ef4e0dc00452ff0b6a940edc2d51114ec3 (patch)
tree04381ff1210dd05700342b5790dc460ed5442cd6 /ftnoir_tracker_joystick
parentd82575fafb5f5887dd1938dfc9d04f7c65eae269 (diff)
joy: Fix API misuse
Issue: #38
Diffstat (limited to 'ftnoir_tracker_joystick')
-rw-r--r--ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp21
-rw-r--r--ftnoir_tracker_joystick/ftnoir_tracker_joystick.h2
2 files changed, 7 insertions, 16 deletions
diff --git a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp
index d3f5806b..54573af6 100644
--- a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp
+++ b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp
@@ -3,6 +3,7 @@
#undef NDEBUG
#include <QMutexLocker>
#include <stdlib.h>
+#include <utility>
FTNoIR_Tracker::FTNoIR_Tracker() :
g_pDI(nullptr),
@@ -10,8 +11,6 @@ FTNoIR_Tracker::FTNoIR_Tracker() :
iter(-1),
mtx(QMutex::Recursive)
{
- for (int i = 0; i < 6; i++)
- min_[i] = max_[i] = 0;
GUID bar = {0};
}
@@ -51,8 +50,6 @@ static BOOL CALLBACK EnumObjectsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
{
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};
@@ -60,15 +57,14 @@ static BOOL CALLBACK EnumObjectsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
diprg.diph.dwHeaderSize = sizeof( DIPROPHEADER );
diprg.diph.dwHow = DIPH_BYID;
diprg.diph.dwObj = pdidoi->dwType;
+ diprg.lMax = 65535;
+ diprg.lMin = -65536;
// 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++;
}
@@ -222,13 +218,8 @@ void FTNoIR_Tracker::GetHeadPoseData(double *data)
{
data[i] = 0;
}
- else {
- auto mid = (min_[idx] + max_[idx]) / 2;
- auto val = values[idx] - mid;
-
- int scale = val > 0 ? abs(max_[idx] - mid) : -abs(mid - min_[idx]);
- data[i] = abs(val) * limits[i] / scale;
- }
+ else
+ data[i] = values[i] * limits[i] / AXIS_MAX;
}
}
diff --git a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.h b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.h
index 2c1bc731..1135b609 100644
--- a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.h
+++ b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.h
@@ -61,12 +61,12 @@ public:
void reload();
LPDIRECTINPUT8 g_pDI;
LPDIRECTINPUTDEVICE8 g_pJoystick;
- int min_[8], max_[8];
QMutex mtx;
QFrame* frame;
DIDEVICEINSTANCE def;
int iter; // XXX bad style
settings s;
+ static const constexpr int AXIS_MAX = 65535;
};
class TrackerControls: public QWidget, public ITrackerDialog