diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2013-10-25 00:14:01 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2013-10-25 00:14:01 +0200 |
commit | 136a710a7fe94b9f55a2c297dea266ed2bd60367 (patch) | |
tree | b065d0eecb0feb5a5b142d33c4cf536730765eb0 /ftnoir_tracker_joystick | |
parent | 4e3366194dad626247063b1505f7223836355377 (diff) |
hopefully joy works, at least for me it does
Signed-off-by: Stanislaw Halik <sthalik@misaki.pl>
Diffstat (limited to 'ftnoir_tracker_joystick')
-rw-r--r-- | ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp | 44 | ||||
-rw-r--r-- | ftnoir_tracker_joystick/ftnoir_tracker_joystick.h | 3 | ||||
-rw-r--r-- | ftnoir_tracker_joystick/ftnoir_tracker_joystick_dialog.cpp | 54 |
3 files changed, 57 insertions, 44 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); } } diff --git a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.h b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.h index 813640d3..9dd335cd 100644 --- a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.h +++ b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.h @@ -28,8 +28,6 @@ #include <oleauto.h> #include <shellapi.h> -#define AXIS_MAX 16383 - struct DI_ENUM_CONTEXT { GUID preferred_instance; @@ -49,6 +47,7 @@ public: LPDIRECTINPUT8 g_pDI; LPDIRECTINPUTDEVICE8 g_pJoystick; int axes[6]; + int min_[8], max_[8]; GUID preferred; int joyid; QMutex mtx; diff --git a/ftnoir_tracker_joystick/ftnoir_tracker_joystick_dialog.cpp b/ftnoir_tracker_joystick/ftnoir_tracker_joystick_dialog.cpp index 80431b99..af3613d9 100644 --- a/ftnoir_tracker_joystick/ftnoir_tracker_joystick_dialog.cpp +++ b/ftnoir_tracker_joystick/ftnoir_tracker_joystick_dialog.cpp @@ -100,18 +100,18 @@ void TrackerControls::doCancel() { void TrackerControls::loadSettings() { - QSettings settings("opentrack"); // Registry settings (in HK_USER) + QSettings settings("opentrack"); // Registry settings (in HK_USER) - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) + QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); + QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) QComboBox* boxen[] = { - ui.comboBox, - ui.comboBox_2, - ui.comboBox_3, ui.comboBox_4, ui.comboBox_5, ui.comboBox_6, + ui.comboBox, + ui.comboBox_2, + ui.comboBox_3, }; iniFile.beginGroup ( "tracker-joy" ); @@ -120,33 +120,35 @@ void TrackerControls::loadSettings() { boxen[i]->setCurrentIndex(iniFile.value(QString("axis-%1").arg(i), 0).toInt()); } ui.joylist->setCurrentIndex(iniFile.value("joyid", -1).toInt()); - iniFile.endGroup (); + iniFile.endGroup (); - settingsDirty = false; + settingsDirty = false; } void TrackerControls::save() { - QSettings settings("opentrack"); // Registry settings (in HK_USER) - - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) + QSettings settings("opentrack"); // Registry settings (in HK_USER) - QComboBox* boxen[] = { - ui.comboBox, - ui.comboBox_2, - ui.comboBox_3, - ui.comboBox_4, - ui.comboBox_5, - ui.comboBox_6, - }; - - iniFile.beginGroup ( "tracker-joy" ); - for (int i = 0; i < 6; i++) + QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); { - iniFile.setValue(QString("axis-%1").arg(i), boxen[i]->currentIndex()); + QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) + + QComboBox* boxen[] = { + ui.comboBox_4, + ui.comboBox_5, + ui.comboBox_6, + ui.comboBox, + ui.comboBox_2, + ui.comboBox_3, + }; + + iniFile.beginGroup ( "tracker-joy" ); + for (int i = 0; i < 6; i++) + { + iniFile.setValue(QString("axis-%1").arg(i), boxen[i]->currentIndex()); + } + iniFile.setValue("joyid", ui.joylist->currentIndex()); + iniFile.endGroup (); } - iniFile.setValue("joyid", ui.joylist->currentIndex()); - iniFile.endGroup (); if(tracker) { |