From a0feb94b670a150e4574f1921cfcfe59049be822 Mon Sep 17 00:00:00 2001 From: Wim Vriend Date: Fri, 11 Jun 2010 18:09:28 +0000 Subject: PPJoy 1st success git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@10 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FaceTrackNoIR.ncb | Bin 31034368 -> 31034368 bytes FaceTrackNoIR.suo | Bin 178688 -> 182272 bytes FaceTrackNoIR/FTServer.cpp | 4 +- FaceTrackNoIR/PPJoyServer.cpp | 130 ++++++++++++++++++++++++++++++------- FaceTrackNoIR/PPJoyServer.h | 30 ++++++++- FaceTrackNoIR/Release/BuildLog.htm | Bin 10992 -> 11008 bytes FaceTrackNoIR/Release/mt.dep | 2 +- FaceTrackNoIR/tracker.cpp | 10 +++ FaceTrackNoIR/tracker.h | 4 +- bin/FaceTrackNoIR.exe | Bin 458752 -> 461312 bytes bin/Settings/IL2.ini | 25 +++++++ bin/images/PPJoy.ico | Bin 0 -> 5166 bytes 12 files changed, 176 insertions(+), 29 deletions(-) create mode 100644 bin/Settings/IL2.ini create mode 100644 bin/images/PPJoy.ico diff --git a/FaceTrackNoIR.ncb b/FaceTrackNoIR.ncb index 90482f62..91579f3a 100644 Binary files a/FaceTrackNoIR.ncb and b/FaceTrackNoIR.ncb differ diff --git a/FaceTrackNoIR.suo b/FaceTrackNoIR.suo index de359e17..44934298 100644 Binary files a/FaceTrackNoIR.suo and b/FaceTrackNoIR.suo differ diff --git a/FaceTrackNoIR/FTServer.cpp b/FaceTrackNoIR/FTServer.cpp index 79d54ec6..ff273cc3 100644 --- a/FaceTrackNoIR/FTServer.cpp +++ b/FaceTrackNoIR/FTServer.cpp @@ -134,8 +134,8 @@ void FTServer::run() { pMemData->data.Y3 = 0; pMemData->data.Y4 = 0; - qDebug() << "FTServer says: pMemData.DataID =" << pMemData->data.DataID; - qDebug() << "FTServer says: ProgramName =" << pMemData->ProgramName; + //qDebug() << "FTServer says: pMemData.DataID =" << pMemData->data.DataID; + //qDebug() << "FTServer says: ProgramName =" << pMemData->ProgramName; ReleaseMutex(hFTMutex); } diff --git a/FaceTrackNoIR/PPJoyServer.cpp b/FaceTrackNoIR/PPJoyServer.cpp index 59c6f675..46a66c44 100644 --- a/FaceTrackNoIR/PPJoyServer.cpp +++ b/FaceTrackNoIR/PPJoyServer.cpp @@ -30,6 +30,10 @@ #include "Tracker.h" #include +long PPJoyServer::PPJoyCorrection = 1470; +long PPJoyServer::analogDefault = (PPJOY_AXIS_MIN+PPJOY_AXIS_MAX)/2 - PPJoyServer::PPJoyCorrection; +static const char* DevName = "\\\\.\\PPJoyIOCTL1"; + /** constructor **/ PPJoyServer::PPJoyServer( Tracker *parent ) { @@ -39,36 +43,116 @@ PPJoyServer::PPJoyServer( Tracker *parent ) { // Create events m_StopThread = CreateEvent(0, TRUE, FALSE, 0); m_WaitThread = CreateEvent(0, TRUE, FALSE, 0); + + // Initialize arrays + for (int i = 0;i < 3;i++) { + centerPos[i] = 0; + centerRot[i] = 0; + } + + /* Open a handle to the control device for the first virtual joystick. */ + /* Virtual joystick devices are names PPJoyIOCTL1 to PPJoyIOCTL16. */ + h = CreateFileA((LPCSTR) DevName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); + + /* Make sure we could open the device! */ + if (h == INVALID_HANDLE_VALUE) + { + QMessageBox::critical(0, "Connection Failed", QString("FaceTrackNoIR failed to connect to Virtual Joystick.\nCheck if it was properly installed!")); + return; + } +} + +/** destructor **/ +PPJoyServer::~PPJoyServer() { + + // Trigger thread to stop + ::SetEvent(m_StopThread); + + // Wait until thread finished + ::WaitForSingleObject(m_WaitThread, INFINITE); + + // Close handles + ::CloseHandle(m_StopThread); + ::CloseHandle(m_WaitThread); + + // + // Free the Virtual Joystick + // + CloseHandle(h); + //terminates the QThread and waits for finishing the QThread + terminate(); + wait(); } /** QThread run @override **/ void PPJoyServer::run() { - //// Init. the data - //TestData.x = 0.0f; - //TestData.y = 0.0f; - //TestData.z = 0.0f; - //TestData.h = 0.0f; - //TestData.p = 0.0f; - //TestData.r = 0.0f; - //TestData.status = 0; - //fg_cmd = 0; - - // Create UDP-sockets - //inSocket = new QUdpSocket(); - //outSocket = new QUdpSocket(); - - //// Connect the inSocket to the port, to receive readyRead messages - //inSocket->bind(QHostAddress::LocalHost, 5551); - - // // Connect the inSocket to the member-function, to read FlightGear commands - //connect(inSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()), Qt::DirectConnection); - exec(); // Exec only returns, when the thread terminates... -} -/** QThread terminate @override **/ -void PPJoyServer::terminate() { + /* Initialise the IOCTL data structure */ + JoyState.Signature= JOYSTICK_STATE_V1; + JoyState.NumAnalog= NUM_ANALOG; // Number of analog values + Analog= JoyState.Analog; // Keep a pointer to the analog array for easy updating + Digital= JoyState.Digital; // Keep a pointer to the digital array for easy updating + JoyState.NumDigital= NUM_DIGITAL; // Number of digital values + + forever + { + // Check event for stop thread + if(::WaitForSingleObject(m_StopThread, 0) == WAIT_OBJECT_0) + { + // Set event + ::SetEvent(m_WaitThread); + return; + } + + Analog[0] = scale2AnalogLimits( virtRotX, -90.0f, 90.0f ); // Pitch + qDebug() << "PPJoyServer says: Pitch =" << Analog[0] << " VirtRotX =" << virtRotX ; + Analog[1] = scale2AnalogLimits( virtRotY, -90.0f, 90.0f ); // Yaw + Analog[2] = scale2AnalogLimits( virtRotZ, -90.0f, 90.0f ); // Roll + Analog[3] = virtPosX + analogDefault; // X + + Analog[5] = virtPosY + analogDefault; // Y (5?) + Analog[6] = virtPosZ + analogDefault; // Z (6?) + + checkAnalogLimits(); + + /* Send request to PPJoy for processing. */ + /* Currently there is no Return Code from PPJoy, this may be added at a */ + /* later stage. So we pass a 0 byte output buffer. */ + if (!DeviceIoControl( h, IOCTL_PPORTJOY_SET_STATE, &JoyState, sizeof(JoyState), NULL, 0, &RetSize, NULL)) + { + return; + } + // just for lower cpu load + msleep(15); + yieldCurrentThread(); + } } +// +// Limit the Joystick values +// +void PPJoyServer::checkAnalogLimits() { + for (int i = 0;i < NUM_ANALOG;i++) { + if (Analog[i]>PPJOY_AXIS_MAX) { + Analog[i]=PPJOY_AXIS_MAX; + } + else if (Analog[i] *rawList ); - float getDegreesFromRads ( float rads ) { return ((rads * 360.0f)/ (2.0f * 3.14159)); } + float getDegreesFromRads ( float rads ) { return (rads * 57.295781f); } // For now, use one slider for all void setSmoothing(int x) { diff --git a/bin/FaceTrackNoIR.exe b/bin/FaceTrackNoIR.exe index 463f086e..fc27716a 100644 Binary files a/bin/FaceTrackNoIR.exe and b/bin/FaceTrackNoIR.exe differ diff --git a/bin/Settings/IL2.ini b/bin/Settings/IL2.ini new file mode 100644 index 00000000..71f730f1 --- /dev/null +++ b/bin/Settings/IL2.ini @@ -0,0 +1,25 @@ +[Tracking] +Smooth=15 +NeutralZone=5 +sensYaw=300 +sensPitch=300 +sensRoll=300 +sensX=100 +sensY=100 +sensZ=100 +invertYaw=false +invertPitch=false +invertRoll=true +invertX=false +invertY=false +invertZ=false +useEWMA=true +redYaw=75 +redPitch=75 +redRoll=75 +redX=75 +redY=75 +redZ=75 + +[GameProtocol] +Selection=3 diff --git a/bin/images/PPJoy.ico b/bin/images/PPJoy.ico new file mode 100644 index 00000000..321e5888 Binary files /dev/null and b/bin/images/PPJoy.ico differ -- cgit v1.2.3