diff options
Diffstat (limited to 'ftnoir_protocol_fsuipc')
| -rw-r--r-- | ftnoir_protocol_fsuipc/fsuipc-protocol.qrc | 5 | ||||
| -rw-r--r-- | ftnoir_protocol_fsuipc/ftnoir_fsuipccontrols.ui | 134 | ||||
| -rw-r--r-- | ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.cpp | 168 | ||||
| -rw-r--r-- | ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.h | 110 | ||||
| -rw-r--r-- | ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc_dialog.cpp | 62 | ||||
| -rw-r--r-- | ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc_dll.cpp | 31 | ||||
| -rw-r--r-- | ftnoir_protocol_fsuipc/images/fs9.png | bin | 0 -> 758 bytes | |||
| -rw-r--r-- | ftnoir_protocol_fsuipc/images/fs91.png | bin | 0 -> 1644 bytes |
8 files changed, 510 insertions, 0 deletions
diff --git a/ftnoir_protocol_fsuipc/fsuipc-protocol.qrc b/ftnoir_protocol_fsuipc/fsuipc-protocol.qrc new file mode 100644 index 00000000..34756f84 --- /dev/null +++ b/ftnoir_protocol_fsuipc/fsuipc-protocol.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>images/fs9.png</file> + </qresource> +</RCC> diff --git a/ftnoir_protocol_fsuipc/ftnoir_fsuipccontrols.ui b/ftnoir_protocol_fsuipc/ftnoir_fsuipccontrols.ui new file mode 100644 index 00000000..6cb066bd --- /dev/null +++ b/ftnoir_protocol_fsuipc/ftnoir_fsuipccontrols.ui @@ -0,0 +1,134 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>UICFSUIPCControls</class>
+ <widget class="QWidget" name="UICFSUIPCControls">
+ <property name="windowModality">
+ <enum>Qt::NonModal</enum>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>512</width>
+ <height>100</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>FSUIPC settings FaceTrackNoIR</string>
+ </property>
+ <property name="windowIcon">
+ <iconset>
+ <normaloff>images/FaceTrackNoIR.png</normaloff>images/FaceTrackNoIR.png</iconset>
+ </property>
+ <property name="layoutDirection">
+ <enum>Qt::LeftToRight</enum>
+ </property>
+ <property name="autoFillBackground">
+ <bool>false</bool>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="2" column="1">
+ <widget class="QPushButton" name="btnCancel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>100</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>100</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Cancel</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="txtLocationOfDLL">
+ <property name="minimumSize">
+ <size>
+ <width>230</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="toolTip">
+ <string>Location of FSUIPC.dll</string>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::Box</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Sunken</enum>
+ </property>
+ <property name="lineWidth">
+ <number>1</number>
+ </property>
+ <property name="text">
+ <string>Location of FSUIPC.dll</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="2">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>The DLL should be located in the Modules/ directory of MS FS 2004</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QPushButton" name="btnOK">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>100</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>100</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>OK</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QPushButton" name="btnFindDLL">
+ <property name="maximumSize">
+ <size>
+ <width>35</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+ <slots>
+ <slot>startEngineClicked()</slot>
+ <slot>stopEngineClicked()</slot>
+ <slot>cameraSettingsClicked()</slot>
+ </slots>
+</ui>
diff --git a/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.cpp b/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.cpp new file mode 100644 index 00000000..632d502a --- /dev/null +++ b/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.cpp @@ -0,0 +1,168 @@ +/******************************************************************************** +* FaceTrackNoIR This program is a private project of the some enthusiastic * +* gamers from Holland, who don't like to pay much for * +* head-tracking. * +* * +* Copyright (C) 2010-2011 Wim Vriend (Developing) * +* Ron Hendriks (Researching and Testing) * +* * +* Homepage * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the * +* Free Software Foundation; either version 3 of the License, or (at your * +* option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but * +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * +* more details. * +* * +* You should have received a copy of the GNU General Public License along * +* with this program; if not, see <http://www.gnu.org/licenses/>. * +* * +* FSUIPCServer FSUIPCServer is the Class, that communicates headpose-data * +* to games, using the FSUIPC.dll. * +********************************************************************************/ +#include "ftnoir_protocol_fsuipc.h" +#include "facetracknoir/global-settings.h" + +/** constructor **/ +FTNoIR_Protocol::FTNoIR_Protocol() +{ + prevPosX = 0.0f; + prevPosY = 0.0f; + prevPosZ = 0.0f; + prevRotX = 0.0f; + prevRotY = 0.0f; + prevRotZ = 0.0f; +} + +FTNoIR_Protocol::~FTNoIR_Protocol() +{ + FSUIPCLib.unload(); +} + +// +// Scale the measured value to the Joystick values +// +int FTNoIR_Protocol::scale2AnalogLimits( float x, float min_x, float max_x ) { +double y; +double local_x; + + local_x = x; + if (local_x > max_x) { + local_x = max_x; + } + if (local_x < min_x) { + local_x = min_x; + } + y = ( 16383 * local_x ) / max_x; + + return (int) y; +} + +void FTNoIR_Protocol::sendHeadposeToGame(const double *headpose ) { + DWORD result; + TFSState pitch; + TFSState yaw; + TFSState roll; + WORD FSZoom; + + float virtPosX; + float virtPosY; + float virtPosZ; + + float virtRotX; + float virtRotY; + float virtRotZ; + +// qDebug() << "FSUIPCServer::run() says: started!"; + + virtRotX = -headpose[Pitch]; // degrees + virtRotY = headpose[Yaw]; + virtRotZ = headpose[Roll]; + + virtPosX = 0.0f; // cm, X and Y are not working for FS2002/2004! + virtPosY = 0.0f; + virtPosZ = headpose[TZ]; + + // + // Init. the FSUIPC offsets (derived from Free-track...) + // + pitch.Control = 66503; + yaw.Control = 66504; + roll.Control = 66505; + + // + // Only do this when the data has changed. This way, the HAT-switch can be used when tracking is OFF. + // + if ((prevPosX != virtPosX) || (prevPosY != virtPosY) || (prevPosZ != virtPosZ) || + (prevRotX != virtRotX) || (prevRotY != virtRotY) || (prevRotZ != virtRotZ)) { + // + // Open the connection + // + FSUIPC_Open(SIM_ANY, &result); + + // + // Check the FS-version + // + if (((result == FSUIPC_ERR_OK) || (result == FSUIPC_ERR_OPEN)) && + ((FSUIPC_FS_Version == SIM_FS2K2) || (FSUIPC_FS_Version == SIM_FS2K4))) { +// qDebug() << "FSUIPCServer::run() says: FSUIPC opened succesfully"; + // + // Write the 4! DOF-data to FS. Only rotations and zoom are possible. + // + pitch.Value = scale2AnalogLimits(virtRotX, -180, 180); + FSUIPC_Write(0x3110, 8, &pitch, &result); + + yaw.Value = scale2AnalogLimits(virtRotY, -180, 180); + FSUIPC_Write(0x3110, 8, &yaw, &result); + + roll.Value = scale2AnalogLimits(virtRotZ, -180, 180); + FSUIPC_Write(0x3110, 8, &roll, &result); + + FSZoom = (WORD) (64/50) * virtPosZ + 64; + FSUIPC_Write(0x832E, 2, &FSZoom, &result); + + // + // Write the data, in one go! + // + FSUIPC_Process(&result); + if (result == FSUIPC_ERR_SENDMSG) { + FSUIPC_Close(); //timeout (1 second) so assume FS closed + } + } + } + + prevPosX = virtPosX; + prevPosY = virtPosY; + prevPosZ = virtPosZ; + prevRotX = virtRotX; + prevRotY = virtRotY; + prevRotZ = virtRotZ; +} + +bool FTNoIR_Protocol::checkServerInstallationOK() +{ + qDebug() << "checkServerInstallationOK says: Starting Function"; + + // + // Load the DLL. + // + FSUIPCLib.setFileName( s.LocationOfDLL ); + if (FSUIPCLib.load() != true) { + qDebug() << "checkServerInstallationOK says: Error loading FSUIPC DLL"; + return false; + } + else { + qDebug() << "checkServerInstallationOK says: FSUIPC DLL loaded."; + } + + return true; +} + +extern "C" FTNOIR_PROTOCOL_BASE_EXPORT FTNoIR_Protocol* CALLING_CONVENTION GetConstructor(void) +{ + return new FTNoIR_Protocol; +} diff --git a/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.h b/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.h new file mode 100644 index 00000000..ff8d3b7f --- /dev/null +++ b/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.h @@ -0,0 +1,110 @@ +/******************************************************************************** +* FaceTrackNoIR This program is a private project of some enthusiastic * +* gamers from Holland, who don't like to pay much for * +* head-tracking. * +* * +* Copyright (C) 2010-2011 Wim Vriend (Developing) * +* Ron Hendriks (Researching and Testing) * +* * +* Homepage * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the * +* Free Software Foundation; either version 3 of the License, or (at your * +* option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but * +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * +* more details. * +* * +* You should have received a copy of the GNU General Public License along * +* with this program; if not, see <http://www.gnu.org/licenses/>. * +* * +* FSUIPCServer FSUIPCServer is the Class, that communicates headpose-data * +* to games, using the FSUIPC.dll. * +********************************************************************************/ +#pragma once +#ifndef INCLUDED_FSUIPCSERVER_H +#define INCLUDED_FSUIPCSERVER_H + +#include <windows.h> +#include <stdlib.h> +#include "FSUIPC_User.h" +#include "facetracknoir/global-settings.h" +#include "ftnoir_protocol_base/ftnoir_protocol_base.h" +#include "ui_ftnoir_fsuipccontrols.h" +#include <QMessageBox> +#include <QSettings> +#include <QLibrary> +#include <QProcess> +#include <QDebug> +#include <QFile> +#include <QFileDialog> +#include "facetracknoir/options.h" +using namespace options; + +#define FSUIPC_FILENAME "C:\\Program Files\\Microsoft Games\\Flight Simulator 9\\Modules\\FSUIPC.dll" + +struct settings { + pbundle b; + value<QString> LocationOfDLL; + settings() : + b(bundle("proto-fsuipc")), + LocationOfDLL(b, "dll-location", FSUIPC_FILENAME) + {} +}; + +#pragma pack(push,1) // All fields in structure must be byte aligned. +typedef struct +{ + int Control; // Control identifier + int Value; // Value of DOF +} TFSState; +#pragma pack(pop) + +class FTNoIR_Protocol : public IProtocol +{ +public: + FTNoIR_Protocol(); + virtual ~FTNoIR_Protocol() virt_override; + bool checkServerInstallationOK(); + void sendHeadposeToGame(const double* headpose); + QString getGameName() { + return "Microsoft Flight Simulator X"; + } +private: + QLibrary FSUIPCLib; + double prevPosX, prevPosY, prevPosZ, prevRotX, prevRotY, prevRotZ; + static int scale2AnalogLimits( float x, float min_x, float max_x ); + settings s; +}; + +class FSUIPCControls: public QWidget, public IProtocolDialog +{ + Q_OBJECT +public: + FSUIPCControls(); + void registerProtocol(IProtocol *) {} + void unRegisterProtocol() {} +private: + Ui::UICFSUIPCControls ui; + settings s; +private slots: + void doOK(); + void doCancel(); + void getLocationOfDLL(); +}; + +class FTNoIR_ProtocolDll : public Metadata +{ +public: + void getFullName(QString *strToBeFilled) { *strToBeFilled = QString("FS2002/FS2004"); } + void getShortName(QString *strToBeFilled) { *strToBeFilled = QString("FSUIPC"); } + void getDescription(QString *strToBeFilled) { *strToBeFilled = QString("Microsoft FS2004 protocol"); } + void getIcon(QIcon *icon) { *icon = QIcon(":/images/fs9.png"); } +}; + + +#endif//INCLUDED_FSUIPCSERVER_H +//END diff --git a/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc_dialog.cpp b/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc_dialog.cpp new file mode 100644 index 00000000..d97cff99 --- /dev/null +++ b/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc_dialog.cpp @@ -0,0 +1,62 @@ +/******************************************************************************** +* FaceTrackNoIR This program is a private project of some enthusiastic * +* gamers from Holland, who don't like to pay much for * +* head-tracking. * +* * +* Copyright (C) 2012 Wim Vriend (Developing) * +* Ron Hendriks (Researching and Testing) * +* * +* Homepage * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the * +* Free Software Foundation; either version 3 of the License, or (at your * +* option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but * +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * +* more details. * +* * +* You should have received a copy of the GNU General Public License along * +* with this program; if not, see <http://www.gnu.org/licenses/>. * +* * +********************************************************************************/ +#include "ftnoir_protocol_fsuipc.h" +#include "facetracknoir/global-settings.h" + +FSUIPCControls::FSUIPCControls() : + QWidget() +{ + ui.setupUi( this ); + connect(ui.btnOK, SIGNAL(clicked()), this, SLOT(doOK())); + connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel())); + connect(ui.btnFindDLL, SIGNAL(clicked()), this, SLOT(getLocationOfDLL())); + + tie_setting(s.LocationOfDLL, ui.txtLocationOfDLL); +} + +void FSUIPCControls::doOK() { + s.b->save(); + this->close(); +} + +void FSUIPCControls::doCancel() { + s.b->revert(); + close(); +} + +void FSUIPCControls::getLocationOfDLL() +{ + QString fileName = QFileDialog::getOpenFileName(this, tr("Locate file"), + ui.txtLocationOfDLL->text(), + tr("FSUIPC DLL file (FSUIPC*.dll);;All Files (*)")); + if (!fileName.isEmpty()) { + s.LocationOfDLL = fileName; + } +} + +extern "C" FTNOIR_PROTOCOL_BASE_EXPORT IProtocolDialog* CALLING_CONVENTION GetDialog(void) +{ + return new FSUIPCControls; +} diff --git a/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc_dll.cpp b/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc_dll.cpp new file mode 100644 index 00000000..57b174c5 --- /dev/null +++ b/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc_dll.cpp @@ -0,0 +1,31 @@ +/******************************************************************************** +* FaceTrackNoIR This program is a private project of some enthusiastic * +* gamers from Holland, who don't like to pay much for * +* head-tracking. * +* * +* Copyright (C) 2012 Wim Vriend (Developing) * +* Ron Hendriks (Researching and Testing) * +* * +* Homepage * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the * +* Free Software Foundation; either version 3 of the License, or (at your * +* option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but * +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * +* more details. * +* * +* You should have received a copy of the GNU General Public License along * +* with this program; if not, see <http://www.gnu.org/licenses/>. * +* * +********************************************************************************/ +#include "ftnoir_protocol_fsuipc.h" +#include "facetracknoir/global-settings.h" + +extern "C" FTNOIR_PROTOCOL_BASE_EXPORT Metadata* CALLING_CONVENTION GetMetadata(void) +{ + return new FTNoIR_ProtocolDll; +} diff --git a/ftnoir_protocol_fsuipc/images/fs9.png b/ftnoir_protocol_fsuipc/images/fs9.png Binary files differnew file mode 100644 index 00000000..914c9dcb --- /dev/null +++ b/ftnoir_protocol_fsuipc/images/fs9.png diff --git a/ftnoir_protocol_fsuipc/images/fs91.png b/ftnoir_protocol_fsuipc/images/fs91.png Binary files differnew file mode 100644 index 00000000..f9540d1d --- /dev/null +++ b/ftnoir_protocol_fsuipc/images/fs91.png |
