From aa575640fcc3c2ad41f68986ee6263f11630adf8 Mon Sep 17 00:00:00 2001 From: Wim Vriend Date: Sun, 3 Feb 2013 15:14:14 +0000 Subject: Changed FreeTrack 2.0 concerning TIRViews. It needs to start first. Added 'disable beep' to KeyboardShortcutDialog. git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@260 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FTNoIR_Protocol_FT/FTNoIR_FTcontrols.ui | 161 ++++++++++++++++++++--- FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.cpp | 133 ++++++++++++------- FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.h | 3 +- FTNoIR_Protocol_FT/ftnoir_protocol_FT_dialog.cpp | 29 +++- FaceTrackNoIR/FTNoIR_KeyboardShortcuts.ui | 15 ++- FaceTrackNoIR/FaceTrackNoIR.cpp | 10 +- FaceTrackNoIR/tracker.cpp | 39 ++++-- FaceTrackNoIR/tracker.h | 1 + 8 files changed, 298 insertions(+), 93 deletions(-) diff --git a/FTNoIR_Protocol_FT/FTNoIR_FTcontrols.ui b/FTNoIR_Protocol_FT/FTNoIR_FTcontrols.ui index 29cba42b..980b2943 100644 --- a/FTNoIR_Protocol_FT/FTNoIR_FTcontrols.ui +++ b/FTNoIR_Protocol_FT/FTNoIR_FTcontrols.ui @@ -6,12 +6,12 @@ 0 0 - 411 - 112 + 588 + 263 - FreeTrack settings FaceTrackNoIR + FreeTrack 2.0 settings FaceTrackNoIR @@ -25,7 +25,149 @@ - + + + + + + 0 + 70 + + + + TIRViews + + + + + 70 + 20 + 88 + 17 + + + + Qt::RightToLeft + + + Use TIRViews + + + + + + 180 + 10 + 301 + 16 + + + + TIRViews is only required for some older games (like CFS3). + + + + + + 180 + 30 + 421 + 16 + + + + For it to work, TIRViews.dll must be placed in the FaceTrackNoIR program folder. + + + true + + + + + + 180 + 50 + 251 + 16 + + + + If the checkbox is disabled, the DLL was not found. + + + + + + + + + 0 + 70 + + + + TrackIR.exe + + + + + 13 + 20 + 145 + 17 + + + + Qt::RightToLeft + + + Start dummy TrackIR.exe + + + + + + 180 + 10 + 351 + 16 + + + + Some programs check, to see if a process called TrackIR.exe is running, + + + + + + 180 + 30 + 261 + 16 + + + + before enabling head-tracking (EZCA is one of them). + + + true + + + + + + 180 + 50 + 231 + 16 + + + + Check the checkbox, to overcome this problem. + + + + @@ -54,17 +196,6 @@ - - - - - - There are no settings necessary for the FreeTrack protocol. - - - - - diff --git a/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.cpp b/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.cpp index 159d3c31..7a1d898e 100644 --- a/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.cpp +++ b/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.cpp @@ -26,6 +26,7 @@ ********************************************************************************/ /* Modifications (last one on top): + 20130203 - WVR: Added Tirviews and dummy checkboxes to the Settings dialog. This is necessary for CFS3 etc. 20130125 - WVR: Upgraded to FT2.0: now the FreeTrack protocol supports all TIR-enabled games. 20110401 - WVR: Moved protocol to a DLL, convenient for installation etc. 20101224 - WVR: Base class is no longer inheriting QThread. sendHeadposeToGame @@ -42,6 +43,9 @@ FTNoIR_Protocol::FTNoIR_Protocol() { comhandle = 0; + useTIRViews = false; + useDummyExe = false; + loadSettings(); ProgramName = ""; intGameID = 0; @@ -49,6 +53,7 @@ FTNoIR_Protocol::FTNoIR_Protocol() dummyTrackIR = 0; viewsStart = 0; viewsStop = 0; + } /** destructor **/ @@ -88,11 +93,11 @@ FTNoIR_Protocol::~FTNoIR_Protocol() FTDestroyMapping(); } -/** helper to Auto-destruct **/ -void FTNoIR_Protocol::Release() -{ - delete this; -} +///** helper to Auto-destruct **/ +//void FTNoIR_Protocol::Release() +//{ +// delete this; +//} void FTNoIR_Protocol::Initialize() { @@ -113,20 +118,28 @@ QStringList gameLine; QFile file(QCoreApplication::applicationDirPath() + "/Settings/FaceTrackNoIR Supported Games.csv"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){ qDebug()<< "cannot read file!"; - return false; + + QString strError("Cannot load file: " + file.fileName()); + sprintf_s(pMemData->ProgramName, 99, strError.toAscii()); + file.close(); + + // + // Return true anyway, because maybe it's V160 compatible. + // + return true; } CSV csv(&file); gameLine = csv.parseLine(); while (gameLine.count() > 2) { - qDebug() << "Column 0: " << gameLine.at(0); // No. - qDebug() << "Column 1: " << gameLine.at(1); // Game Name - qDebug() << "Column 2: " << gameLine.at(2); // Game Protocol - qDebug() << "Column 3: " << gameLine.at(3); // Supported since version - qDebug() << "Column 4: " << gameLine.at(4); // Verified - qDebug() << "Column 5: " << gameLine.at(5); // By - qDebug() << "Column 6: " << gameLine.at(6); // International ID - qDebug() << "Column 7: " << gameLine.at(7); // FaceTrackNoIR ID + //qDebug() << "Column 0: " << gameLine.at(0); // No. + //qDebug() << "Column 1: " << gameLine.at(1); // Game Name + //qDebug() << "Column 2: " << gameLine.at(2); // Game Protocol + //qDebug() << "Column 3: " << gameLine.at(3); // Supported since version + //qDebug() << "Column 4: " << gameLine.at(4); // Verified + //qDebug() << "Column 5: " << gameLine.at(5); // By + //qDebug() << "Column 6: " << gameLine.at(6); // International ID + //qDebug() << "Column 7: " << gameLine.at(7); // FaceTrackNoIR ID // // If the gameID was found, fill the shared memory @@ -149,7 +162,8 @@ QStringList gameLine; // // If the gameID was NOT found, fill only the name "Unknown game connected" // - sprintf_s(pMemData->ProgramName, 99, gameLine.at(1).toAscii()); + QString strUnknown("Unknown game connected (ID = " + gameID + ")"); + sprintf_s(pMemData->ProgramName, 99, strUnknown.toAscii()); file.close(); return true; } @@ -158,6 +172,18 @@ QStringList gameLine; // Load the current Settings from the currently 'active' INI-file. // void FTNoIR_Protocol::loadSettings() { + QSettings settings("Abbequerque Inc.", "FaceTrackNoIR"); // 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) + + // + // Use the settings-section from the deprecated fake-TIR protocol, as they are most likely to be found there. + // + iniFile.beginGroup ( "FTIR" ); + useTIRViews = iniFile.value ( "useTIRViews", 0 ).toBool(); + useDummyExe = iniFile.value ( "useDummyExe", 1 ).toBool(); + iniFile.endGroup (); } // @@ -254,46 +280,11 @@ PDWORD_PTR MsgResult = 0; QString gameID = QString(pMemData->GameID); // QString gameID = QString("2304"); - qDebug() << "sendHeadposeToGame: gameID = " << gameID; +// qDebug() << "sendHeadposeToGame: gameID = " << gameID; if (gameID.length() > 0) { if ( gameID.toInt() != intGameID ) { if (getGameData( gameID ) ) { SendMessageTimeout( (HWND) hMainWindow, RegisterWindowMessageA(FT_PROGRAMID), 0, 0, 0, 2000, MsgResult); - - // - // Check if TIRViews or dummy TrackIR.exe is required for this game - // - QString ftnID = QString(pMemData->FTNID); - if (ftnID.length() >= 22) { - if (ftnID.at(20) != '0') { - FTIRViewsLib.setFileName(QCoreApplication::applicationDirPath() + "/TIRViews.dll"); - FTIRViewsLib.load(); - - viewsStart = (importTIRViewsStart) FTIRViewsLib.resolve("TIRViewsStart"); - if (viewsStart == NULL) { - qDebug() << "FTServer::run() says: TIRViewsStart function not found in DLL!"; - } - else { - qDebug() << "FTServer::run() says: TIRViewsStart executed!"; - viewsStart(); - } - - // - // Load the Stop function from TIRViews.dll. Call it when terminating the thread. - // - viewsStop = (importTIRViewsStop) FTIRViewsLib.resolve("TIRViewsStop"); - if (viewsStop == NULL) { - qDebug() << "FTServer::run() says: TIRViewsStop function not found in DLL!"; - } - } - if (ftnID.at(21) != '0') { - QString program = QCoreApplication::applicationDirPath() + "/TrackIR.exe"; - dummyTrackIR = new QProcess(); - dummyTrackIR->start(program); - - qDebug() << "FTServer::run() says: TrackIR.exe executed!"; - } - } } intGameID = gameID.toInt(); } @@ -336,6 +327,46 @@ bool FTNoIR_Protocol::checkServerInstallationOK( HANDLE handle ) settings.setValue( "Path" , aLocation ); settingsTIR.setValue( "Path" , aLocation ); + // + // TIRViews must be started first, or the NPClient DLL will never be loaded. + // + if (useTIRViews) { + + QString aFileName = QCoreApplication::applicationDirPath() + "/TIRViews.dll"; + if ( QFile::exists( aFileName ) ) { + + FTIRViewsLib.setFileName(aFileName); + FTIRViewsLib.load(); + + viewsStart = (importTIRViewsStart) FTIRViewsLib.resolve("TIRViewsStart"); + if (viewsStart == NULL) { + qDebug() << "FTServer::run() says: TIRViewsStart function not found in DLL!"; + } + else { + qDebug() << "FTServer::run() says: TIRViewsStart executed!"; + viewsStart(); + } + + // + // Load the Stop function from TIRViews.dll. Call it when terminating the thread. + // + viewsStop = (importTIRViewsStop) FTIRViewsLib.resolve("TIRViewsStop"); + if (viewsStop == NULL) { + qDebug() << "FTServer::run() says: TIRViewsStop function not found in DLL!"; + } + } + } + + // + // Check if TIRViews or dummy TrackIR.exe is required for this game + // + if (useDummyExe) { + QString program = QCoreApplication::applicationDirPath() + "/TrackIR.exe"; + dummyTrackIR = new QProcess(); + dummyTrackIR->start(program); + + qDebug() << "FTServer::run() says: TrackIR.exe executed!"; + } } catch(...) { diff --git a/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.h b/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.h index 12a20ee8..00f124f6 100644 --- a/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.h +++ b/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.h @@ -73,10 +73,11 @@ private: // Private properties QString ProgramName; -// QLibrary FTClientLib; QLibrary FTIRViewsLib; QProcess *dummyTrackIR; int intGameID; + bool useTIRViews; // Needs to be in the Settings dialog + bool useDummyExe; float getRadsFromDegrees ( float degrees ) { return (degrees * 0.017453f); } bool getGameData( QString gameID ); diff --git a/FTNoIR_Protocol_FT/ftnoir_protocol_FT_dialog.cpp b/FTNoIR_Protocol_FT/ftnoir_protocol_FT_dialog.cpp index 62584b43..678b3a5f 100644 --- a/FTNoIR_Protocol_FT/ftnoir_protocol_FT_dialog.cpp +++ b/FTNoIR_Protocol_FT/ftnoir_protocol_FT_dialog.cpp @@ -50,7 +50,18 @@ QWidget() // Connect Qt signals to member-functions connect(ui.btnOK, SIGNAL(clicked()), this, SLOT(doOK())); connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel())); -// connect(ui.chkTIRViews, SIGNAL(stateChanged(int)), this, SLOT(chkTIRViewsChanged())); + connect(ui.chkTIRViews, SIGNAL(stateChanged(int)), this, SLOT(chkTIRViewsChanged())); + connect(ui.chkStartDummy, SIGNAL(stateChanged(int)), this, SLOT(settingChanged())); + + aFileName = QCoreApplication::applicationDirPath() + "/TIRViews.dll"; + if ( !QFile::exists( aFileName ) ) { + ui.chkTIRViews->setChecked( false ); + ui.chkTIRViews->setEnabled ( false ); + save(); + } + else { + ui.chkTIRViews->setEnabled ( true ); + } theProtocol = NULL; @@ -65,11 +76,6 @@ FTControls::~FTControls() { qDebug() << "~FTControls() says: started"; } -void FTControls::Release() -{ - delete this; -} - // // Initialize tracker-client-dialog // @@ -144,6 +150,11 @@ void FTControls::loadSettings() { // ui.chkTIRViews->setChecked (iniFile.value ( "useTIRViews", 0 ).toBool()); iniFile.endGroup (); + iniFile.beginGroup ( "FTIR" ); + ui.chkTIRViews->setChecked (iniFile.value ( "useTIRViews", 0 ).toBool()); + ui.chkStartDummy->setChecked (iniFile.value ( "useDummyExe", 1 ).toBool()); + iniFile.endGroup (); + settingsDirty = false; } @@ -157,7 +168,11 @@ void FTControls::save() { QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) iniFile.beginGroup ( "FT" ); -// iniFile.setValue ( "useTIRViews", ui.chkTIRViews->isChecked() ); + iniFile.endGroup (); + + iniFile.beginGroup ( "FTIR" ); + iniFile.setValue ( "useTIRViews", ui.chkTIRViews->isChecked() ); + iniFile.setValue ( "useDummyExe", ui.chkStartDummy->isChecked() ); iniFile.endGroup (); settingsDirty = false; diff --git a/FaceTrackNoIR/FTNoIR_KeyboardShortcuts.ui b/FaceTrackNoIR/FTNoIR_KeyboardShortcuts.ui index 021c6ce6..e9f3facb 100644 --- a/FaceTrackNoIR/FTNoIR_KeyboardShortcuts.ui +++ b/FaceTrackNoIR/FTNoIR_KeyboardShortcuts.ui @@ -6,7 +6,7 @@ 0 0 - 672 + 687 438 @@ -682,6 +682,19 @@ + + + + + 80 + 16777215 + + + + Disable Beep + + + diff --git a/FaceTrackNoIR/FaceTrackNoIR.cpp b/FaceTrackNoIR/FaceTrackNoIR.cpp index ccd667d0..c9a05dc9 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.cpp +++ b/FaceTrackNoIR/FaceTrackNoIR.cpp @@ -23,6 +23,7 @@ *********************************************************************************/ /* Modifications (last one on top): + 20130201 - WVR: Load FreeTrack 2.0 protocol instead of fake TrackIR (which is now obsolete). 20130101 - WVR: Added "None" to filter-listbox to remove "use advanced filtering". 20121209 - WVR: Pre-v170 DLLs will not be added to the Listbox. Initial selection was changed (made case-insensitive). 20121014 - WVR: Added second Tracker Source for Arduino solution. The two will be mutually exclusive. @@ -494,7 +495,7 @@ void FaceTrackNoIR::loadSettings() { // Put the filename in the window-title. // QFileInfo pathInfo ( currentFile ); - setWindowTitle ( "FaceTrackNoIR (1.7 alpha 10) - " + pathInfo.fileName() ); + setWindowTitle ( "FaceTrackNoIR (1.7) - " + pathInfo.fileName() ); // // Get a List of all the INI-files in the (currently active) Settings-folder. @@ -543,6 +544,7 @@ void FaceTrackNoIR::loadSettings() { if (selectedProtocolName.length() == 0) { int index = iniFile.value ( "Selection", 0 ).toInt(); switch ( index ) { + case TRACKIR: case FREE_TRACK: selectedProtocolName = QString("FTNoIR_Protocol_FT.dll"); break; @@ -559,10 +561,6 @@ void FaceTrackNoIR::loadSettings() { selectedProtocolName = QString("FTNoIR_Protocol_FSUIPC.dll"); break; - case TRACKIR: - selectedProtocolName = QString("FTNoIR_Protocol_FTIR.dll"); - break; - case FLIGHTGEAR: selectedProtocolName = QString("FTNoIR_Protocol_FG.dll"); break; @@ -1920,6 +1918,7 @@ int keyindex; ui.chkCenterShift->setChecked (iniFile.value ( "Shift_Center", 0 ).toBool()); ui.chkCenterCtrl->setChecked (iniFile.value ( "Ctrl_Center", 0 ).toBool()); ui.chkCenterAlt->setChecked (iniFile.value ( "Alt_Center", 0 ).toBool()); + ui.chkDisableBeep->setChecked (iniFile.value ( "Disable_Beep", 0 ).toBool()); // GameZero key ui.cbxGameZeroMouseKey->setCurrentIndex( iniFile.value ( "MouseKey_GameZero", 0 ).toInt() ); @@ -2002,6 +2001,7 @@ void KeyboardShortcutDialog::save() { iniFile.setValue ( "Shift_Center", ui.chkCenterShift->isChecked() ); iniFile.setValue ( "Ctrl_Center", ui.chkCenterCtrl->isChecked() ); iniFile.setValue ( "Alt_Center", ui.chkCenterAlt->isChecked() ); + iniFile.setValue ( "Disable_Beep", ui.chkDisableBeep->isChecked() ); iniFile.setValue ( "MouseKey_GameZero", ui.cbxGameZeroMouseKey->currentIndex()); iniFile.setValue ( "Keycode_GameZero", keyList.at( ui.cbxGameZeroKey->currentIndex() ) ); diff --git a/FaceTrackNoIR/tracker.cpp b/FaceTrackNoIR/tracker.cpp index 1266ab01..1dd2cf1b 100644 --- a/FaceTrackNoIR/tracker.cpp +++ b/FaceTrackNoIR/tracker.cpp @@ -23,6 +23,7 @@ *********************************************************************************/ /* Modifications (last one on top): + 20130201 - WVR: Remove the Protocol, when stopping the Thread. 20121215 - WVR: Fixed crash after message: protocol not installed correctly... by terminating the thread. 20120921 - WVR: Fixed centering when no filter is selected. 20120917 - WVR: Added Mouse-buttons to ShortKeys. @@ -102,6 +103,7 @@ TShortKey Tracker::CenterKey; // ShortKey to Center headposition TShortKey Tracker::StartStopKey; // ShortKey to Start/stop tracking TShortKey Tracker::InhibitKey; // ShortKey to inhibit axis while tracking TShortKey Tracker::GameZeroKey; // ShortKey to Set Game Zero +bool Tracker::DisableBeep = false; // Disable beep when center //TShortKey Tracker::AxisReverseKey; // ShortKey to start/stop axis reverse while tracking int Tracker::CenterMouseKey; // ShortKey to Center headposition @@ -278,6 +280,14 @@ Tracker::~Tracker() { pSecondTracker = NULL; } + // + // Remove the Protocol + // + if (pProtocol) { + delete pProtocol; + pProtocol = NULL; + } + // Close handles ::CloseHandle(m_StopThread); ::CloseHandle(m_WaitThread); @@ -642,7 +652,9 @@ bool bTracker2Confid = false; // if ((Tracker::do_center) || ((bInitialCenter1 && bTracker1Confid ) || (bInitialCenter2 && bTracker2Confid))) { - MessageBeep (MB_ICONASTERISK); + if (!DisableBeep) { + MessageBeep (MB_ICONASTERISK); // Acknowledge the key-press with a beep. + } if (pTracker && bTracker1Confid) { pTracker->notifyCenter(); // Send 'center' to the tracker bInitialCenter1 = false; @@ -923,9 +935,9 @@ float sum = 0; // Load the current Settings from the currently 'active' INI-file. // void Tracker::loadSettings() { -int NeutralZone; -int sensYaw, sensPitch, sensRoll; -int sensX, sensY, sensZ; +//int NeutralZone; +//int sensYaw, sensPitch, sensRoll; +//int sensX, sensY, sensZ; qDebug() << "Tracker::loadSettings says: Starting "; QSettings settings("Abbequerque Inc.", "FaceTrackNoIR"); // Registry settings (in HK_USER) @@ -938,15 +950,15 @@ int sensX, sensY, sensZ; // // Read the Tracking settings, to fill the curves. // - iniFile.beginGroup ( "Tracking" ); - NeutralZone = iniFile.value ( "NeutralZone", 5 ).toInt(); - sensYaw = iniFile.value ( "sensYaw", 100 ).toInt(); - sensPitch = iniFile.value ( "sensPitch", 100 ).toInt(); - sensRoll = iniFile.value ( "sensRoll", 100 ).toInt(); - sensX = iniFile.value ( "sensX", 100 ).toInt(); - sensY = iniFile.value ( "sensY", 100 ).toInt(); - sensZ = iniFile.value ( "sensZ", 100 ).toInt(); - iniFile.endGroup (); + //iniFile.beginGroup ( "Tracking" ); + //NeutralZone = iniFile.value ( "NeutralZone", 5 ).toInt(); + //sensYaw = iniFile.value ( "sensYaw", 100 ).toInt(); + //sensPitch = iniFile.value ( "sensPitch", 100 ).toInt(); + //sensRoll = iniFile.value ( "sensRoll", 100 ).toInt(); + //sensX = iniFile.value ( "sensX", 100 ).toInt(); + //sensY = iniFile.value ( "sensY", 100 ).toInt(); + //sensZ = iniFile.value ( "sensZ", 100 ).toInt(); + //iniFile.endGroup (); // // Read the keyboard shortcuts. @@ -959,6 +971,7 @@ int sensX, sensY, sensZ; CenterKey.shift = iniFile.value ( "Shift_Center", 0 ).toBool(); CenterKey.ctrl = iniFile.value ( "Ctrl_Center", 0 ).toBool(); CenterKey.alt = iniFile.value ( "Alt_Center", 0 ).toBool(); + DisableBeep = iniFile.value ( "Disable_Beep", 0 ).toBool(); // StartStop key StartStopMouseKey = iniFile.value ( "MouseKey_StartStop", 0 ).toInt(); diff --git a/FaceTrackNoIR/tracker.h b/FaceTrackNoIR/tracker.h index 0ddd5df4..4b161293 100644 --- a/FaceTrackNoIR/tracker.h +++ b/FaceTrackNoIR/tracker.h @@ -188,6 +188,7 @@ private: static int StartStopMouseKey; // ShortKey to Start/stop tracking static int InhibitMouseKey; // ShortKey to disable one or more axis during tracking static int GameZeroMouseKey; // ShortKey to Set Game Zero + static bool DisableBeep; // Disable Beep when center is pressed // Flags to start/stop/reset tracking static bool confid; // Tracker data is OK -- cgit v1.2.3