diff options
author | Wim Vriend <facetracknoir@gmail.com> | 2010-06-11 18:09:28 +0000 |
---|---|---|
committer | Wim Vriend <facetracknoir@gmail.com> | 2010-06-11 18:09:28 +0000 |
commit | a0feb94b670a150e4574f1921cfcfe59049be822 (patch) | |
tree | 26491b9b08295d80974a8303ca90370eb4151e63 | |
parent | 602e4770360fb125ebdb129a6b777fe08a433370 (diff) |
PPJoy 1st success
git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@10 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb
-rw-r--r-- | FaceTrackNoIR.ncb | bin | 31034368 -> 31034368 bytes | |||
-rw-r--r-- | FaceTrackNoIR.suo | bin | 178688 -> 182272 bytes | |||
-rw-r--r-- | FaceTrackNoIR/FTServer.cpp | 4 | ||||
-rw-r--r-- | FaceTrackNoIR/PPJoyServer.cpp | 130 | ||||
-rw-r--r-- | FaceTrackNoIR/PPJoyServer.h | 30 | ||||
-rw-r--r-- | FaceTrackNoIR/Release/BuildLog.htm | bin | 10992 -> 11008 bytes | |||
-rw-r--r-- | FaceTrackNoIR/Release/mt.dep | 2 | ||||
-rw-r--r-- | FaceTrackNoIR/tracker.cpp | 10 | ||||
-rw-r--r-- | FaceTrackNoIR/tracker.h | 4 | ||||
-rw-r--r-- | bin/FaceTrackNoIR.exe | bin | 458752 -> 461312 bytes | |||
-rw-r--r-- | bin/Settings/IL2.ini | 25 | ||||
-rw-r--r-- | bin/images/PPJoy.ico | bin | 0 -> 5166 bytes |
12 files changed, 176 insertions, 29 deletions
diff --git a/FaceTrackNoIR.ncb b/FaceTrackNoIR.ncb Binary files differindex 90482f62..91579f3a 100644 --- a/FaceTrackNoIR.ncb +++ b/FaceTrackNoIR.ncb diff --git a/FaceTrackNoIR.suo b/FaceTrackNoIR.suo Binary files differindex de359e17..44934298 100644 --- a/FaceTrackNoIR.suo +++ b/FaceTrackNoIR.suo 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 <Winsock.h>
+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]<PPJOY_AXIS_MIN) {
+ Analog[i]=PPJOY_AXIS_MIN;
+ }
+ }
+}
+
+//
+// Scale the measured value to the Joystick values
+//
+long PPJoyServer::scale2AnalogLimits( float x, float min_x, float max_x ) {
+double y;
+
+ y = ((PPJOY_AXIS_MAX - PPJOY_AXIS_MIN)/(max_x - min_x)) * x + ((PPJOY_AXIS_MAX - PPJOY_AXIS_MIN)/2) + PPJOY_AXIS_MIN;
+ qDebug() << "scale2AnalogLimits says: long_y =" << y;
+
+ return (long) y;
+}
//END
diff --git a/FaceTrackNoIR/PPJoyServer.h b/FaceTrackNoIR/PPJoyServer.h index f6c9b66f..83b3617a 100644 --- a/FaceTrackNoIR/PPJoyServer.h +++ b/FaceTrackNoIR/PPJoyServer.h @@ -43,6 +43,20 @@ using namespace std; class Tracker; // pre-define parent-class to avoid circular includes
+#define NUM_ANALOG 7 /* Number of analog values which we will provide */
+#define NUM_DIGITAL 1 /* Number of digital values which we will provide */
+
+#pragma pack(push,1) /* All fields in structure must be byte aligned. */
+typedef struct
+{
+ unsigned long Signature; /* Signature to identify packet to PPJoy IOCTL */
+ char NumAnalog; /* Num of analog values we pass */
+ long Analog[NUM_ANALOG]; /* Analog values */
+ char NumDigital; /* Num of digital values we pass */
+ char Digital[NUM_DIGITAL]; /* Digital values */
+} JOYSTICK_STATE;
+#pragma pack(pop)
+
class PPJoyServer : public QThread {
Q_OBJECT
@@ -50,12 +64,11 @@ public: // public member methods
PPJoyServer( Tracker *parent );
- virtual ~PPJoyServer() {};
+ ~PPJoyServer();
// protected member methods
protected:
void run();
- void terminate();
private slots:
// void readPendingDatagrams();
@@ -67,6 +80,16 @@ private: Tracker *headTracker; // For upstream messages...
+ HANDLE h;
+ JOYSTICK_STATE JoyState;
+ DWORD RetSize;
+ DWORD rc;
+ long *Analog;
+ char *Digital;
+
+ static long analogDefault,PPJoyCorrection;
+ long centerPos[3],centerRot[3];
+
/** member variables for saving the head pose **/
float virtPosX;
float virtPosY;
@@ -76,6 +99,9 @@ private: float virtRotY;
float virtRotZ;
+ void checkAnalogLimits();
+ long scale2AnalogLimits( float x, float min_x, float max_x );
+
public:
void setVirtRotX(float rot) { virtRotX = rot; }
void setVirtRotY(float rot) { virtRotY = rot; }
diff --git a/FaceTrackNoIR/Release/BuildLog.htm b/FaceTrackNoIR/Release/BuildLog.htm Binary files differindex 4c7f9692..695a0f33 100644 --- a/FaceTrackNoIR/Release/BuildLog.htm +++ b/FaceTrackNoIR/Release/BuildLog.htm diff --git a/FaceTrackNoIR/Release/mt.dep b/FaceTrackNoIR/Release/mt.dep index ad86a4c9..07307278 100644 --- a/FaceTrackNoIR/Release/mt.dep +++ b/FaceTrackNoIR/Release/mt.dep @@ -1 +1 @@ -Manifest resource last updated at 13:38:23.50 on vr 11-06-2010
+Manifest resource last updated at 20:05:54.09 on vr 11-06-2010
diff --git a/FaceTrackNoIR/tracker.cpp b/FaceTrackNoIR/tracker.cpp index 9141dde7..724475f2 100644 --- a/FaceTrackNoIR/tracker.cpp +++ b/FaceTrackNoIR/tracker.cpp @@ -87,6 +87,7 @@ Tracker::Tracker() { server_FT = new FTServer; // Create the new thread (on the heap)
server_FG = new FGServer ( this ); // Create the new thread (on the heap)
+ server_PPJoy = new PPJoyServer ( this ); // Create the new thread (on the heap)
}
/** destructor empty **/
@@ -94,6 +95,7 @@ Tracker::~Tracker() { server_FT->deleteLater();
server_FG->deleteLater();
+ server_PPJoy->deleteLater();
// Trigger thread to stop
::SetEvent(m_StopThread);
@@ -149,6 +151,7 @@ void Tracker::setup(QWidget *head, FaceTrackNoIR *parent) { // return;
server_FT->start(); // Should start at the push of a button?
server_FG->start(); //
+ server_PPJoy->start(); //
}
/** QThread run method @override **/
@@ -341,6 +344,7 @@ void Tracker::run() { Pitch.newPos = getSmoothFromList( &Pitch.rawList ) - Pitch.offset_headPos;
}
server_FT->setVirtRotX ( Tracker::Pitch.invert * Tracker::Pitch.sens * Pitch.newPos );
+ server_PPJoy->setVirtRotX ( getDegreesFromRads (Tracker::Pitch.invert * Tracker::Pitch.sens * Pitch.newPos ) );
if (Tracker::useFilter) {
Yaw.newPos = lowPassFilter ( getSmoothFromList( &Yaw.rawList ) - Yaw.offset_headPos,
@@ -350,6 +354,7 @@ void Tracker::run() { Yaw.newPos = getSmoothFromList( &Yaw.rawList ) - Yaw.offset_headPos;
}
server_FT->setVirtRotY ( Tracker::Yaw.invert * Tracker::Yaw.sens * Yaw.newPos );
+ server_PPJoy->setVirtRotY ( getDegreesFromRads ( Tracker::Yaw.invert * Tracker::Yaw.sens * Yaw.newPos ) );
if (Tracker::useFilter) {
Roll.newPos = lowPassFilter ( getSmoothFromList( &Roll.rawList ) - Roll.offset_headPos,
@@ -359,11 +364,16 @@ void Tracker::run() { Roll.newPos = getSmoothFromList( &Roll.rawList ) - Roll.offset_headPos;
}
server_FT->setVirtRotZ ( Tracker::Roll.invert * Tracker::Roll.sens * Roll.newPos );
+ server_PPJoy->setVirtRotZ ( getDegreesFromRads (Tracker::Roll.invert * Tracker::Roll.sens * Roll.newPos ) );
server_FT->setVirtPosX ( ( Tracker::X.invert * Tracker::X.sens * (getSmoothFromList( &X.rawList ) - X.offset_headPos) ) * 1000.0f);
server_FT->setVirtPosY ( ( Tracker::Y.invert * Tracker::Y.sens * (getSmoothFromList( &Y.rawList ) - Y.offset_headPos) ) * 1000.0f );
server_FT->setVirtPosZ ( ( Tracker::Z.invert * Tracker::Z.sens * (getSmoothFromList( &Z.rawList ) - Z.offset_headPos - Tracker::Z.initial_headPos) ) * 1000.0f );
+ server_PPJoy->setVirtPosX ( ( Tracker::X.invert * Tracker::X.sens * (getSmoothFromList( &X.rawList ) - X.offset_headPos) ) * 1000.0f);
+ server_PPJoy->setVirtPosY ( ( Tracker::Y.invert * Tracker::Y.sens * (getSmoothFromList( &Y.rawList ) - Y.offset_headPos) ) * 1000.0f );
+ server_PPJoy->setVirtPosZ ( ( Tracker::Z.invert * Tracker::Z.sens * (getSmoothFromList( &Z.rawList ) - Z.offset_headPos - Tracker::Z.initial_headPos) ) * 1000.0f );
+
server_FG->setVirtRotX ( getDegreesFromRads ( Tracker::Pitch.invert * Tracker::Pitch.sens * (getSmoothFromList( &Pitch.rawList ) - Pitch.offset_headPos) ) );
server_FG->setVirtRotY ( getDegreesFromRads ( Tracker::Yaw.invert * Tracker::Yaw.sens * (getSmoothFromList( &Yaw.rawList ) - Yaw.offset_headPos) ) );
server_FG->setVirtRotZ ( getDegreesFromRads ( Tracker::Roll.invert * Tracker::Roll.sens * (getSmoothFromList( &Roll.rawList ) - Roll.offset_headPos) ) );
diff --git a/FaceTrackNoIR/tracker.h b/FaceTrackNoIR/tracker.h index 23768f95..732d2a8d 100644 --- a/FaceTrackNoIR/tracker.h +++ b/FaceTrackNoIR/tracker.h @@ -37,6 +37,7 @@ #include "FTServer.h" // Freetrack-server
#include "FGServer.h" // FlightGear-server
+#include "PPJoyServer.h" // Virtual Joystick
// include the DirectX Library files
#pragma comment (lib, "dinput8.lib")
@@ -117,6 +118,7 @@ private: FTServer *server_FT; // Freetrack Server
FGServer *server_FG; // FlightGear Server
+ PPJoyServer *server_PPJoy; // PPJoy Server
protected:
// qthread override run method
@@ -178,7 +180,7 @@ public: static void setNeutralZone(int x) { rotNeutralZone = (x * 2.0f * 3.14159)/360.0f; }
float getSmoothFromList ( QList<float> *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 Binary files differindex 463f086e..fc27716a 100644 --- a/bin/FaceTrackNoIR.exe +++ b/bin/FaceTrackNoIR.exe 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 Binary files differnew file mode 100644 index 00000000..321e5888 --- /dev/null +++ b/bin/images/PPJoy.ico |