summaryrefslogtreecommitdiffhomepage
path: root/proto-fsuipc
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-10-30 09:16:32 +0100
committerStanislaw Halik <sthalik@misaki.pl>2015-10-30 09:16:32 +0100
commit0739d5b595be9492c1e574192eba12174111e52c (patch)
tree01225d2335ff784b35b59a5438f8ea1e07535486 /proto-fsuipc
parent05b2f05b72c706908e961eff8c0e4aa70dcadbd3 (diff)
also rename protocol -> proto
Diffstat (limited to 'proto-fsuipc')
-rw-r--r--proto-fsuipc/CMakeLists.txt11
-rw-r--r--proto-fsuipc/fsuipc-protocol.qrc5
-rw-r--r--proto-fsuipc/ftnoir_fsuipccontrols.ui134
-rw-r--r--proto-fsuipc/ftnoir_protocol_fsuipc.cpp149
-rw-r--r--proto-fsuipc/ftnoir_protocol_fsuipc.h90
-rw-r--r--proto-fsuipc/ftnoir_protocol_fsuipc_dialog.cpp43
-rw-r--r--proto-fsuipc/images/fs9.pngbin0 -> 758 bytes
-rw-r--r--proto-fsuipc/images/fs91.pngbin0 -> 1644 bytes
8 files changed, 432 insertions, 0 deletions
diff --git a/proto-fsuipc/CMakeLists.txt b/proto-fsuipc/CMakeLists.txt
new file mode 100644
index 00000000..ec897ae8
--- /dev/null
+++ b/proto-fsuipc/CMakeLists.txt
@@ -0,0 +1,11 @@
+if(WIN32)
+ set(SDK_FSUIPC "" CACHE PATH "FSUIPC for older MS FSX path")
+ if(SDK_FSUIPC)
+ opentrack_boilerplate(opentrack-proto-fsuipc)
+ target_link_libraries(opentrack-proto-fsuipc ${SDK_FSUIPC}/FSUIPC_User.lib)
+ target_include_directories(opentrack-proto-fsuipc SYSTEM PUBLIC ${SDK_FSUIPC})
+ if(MSVC)
+ set_target_properties(opentrack-proto-fsuipc PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBC.lib")
+ endif()
+ endif()
+endif()
diff --git a/proto-fsuipc/fsuipc-protocol.qrc b/proto-fsuipc/fsuipc-protocol.qrc
new file mode 100644
index 00000000..34756f84
--- /dev/null
+++ b/proto-fsuipc/fsuipc-protocol.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>images/fs9.png</file>
+ </qresource>
+</RCC>
diff --git a/proto-fsuipc/ftnoir_fsuipccontrols.ui b/proto-fsuipc/ftnoir_fsuipccontrols.ui
new file mode 100644
index 00000000..637e4dba
--- /dev/null
+++ b/proto-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/proto-fsuipc/ftnoir_protocol_fsuipc.cpp b/proto-fsuipc/ftnoir_protocol_fsuipc.cpp
new file mode 100644
index 00000000..702a92d4
--- /dev/null
+++ b/proto-fsuipc/ftnoir_protocol_fsuipc.cpp
@@ -0,0 +1,149 @@
+/* Homepage http://facetracknoir.sourceforge.net/home/default.htm *
+ * *
+ * ISC License (ISC) *
+ * *
+ * Copyright (c) 2015, Wim Vriend *
+ * *
+ * Permission to use, copy, modify, and/or distribute this software for any *
+ * purpose with or without fee is hereby granted, provided that the above *
+ * copyright notice and this permission notice appear in all copies. *
+ */
+#include "ftnoir_protocol_fsuipc.h"
+#include "opentrack/plugin-api.hpp"
+
+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()
+{
+ FSUIPC_Close();
+ FSUIPCLib.unload();
+}
+
+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::pose(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 checks for already open connections and returns FSUIPC_ERR_OPEN in that case
+ // the connection scope is global for the process. this is why above code doesn't
+ // leak resources or have logic errors. see: http://www.purebasic.fr/english/viewtopic.php?t=31112
+ FSUIPC_Close();
+ }
+ }
+ }
+
+ prevPosX = virtPosX;
+ prevPosY = virtPosY;
+ prevPosZ = virtPosZ;
+ prevRotX = virtRotX;
+ prevRotY = virtRotY;
+ prevRotZ = virtRotZ;
+}
+
+bool FTNoIR_Protocol::correct()
+{
+ qDebug() << "correct says: Starting Function";
+
+ //
+ // Load the DLL.
+ //
+ FSUIPCLib.setFileName( s.LocationOfDLL );
+ if (FSUIPCLib.load() != true) {
+ qDebug() << "correct says: Error loading FSUIPC DLL";
+ return false;
+ }
+ else {
+ qDebug() << "correct says: FSUIPC DLL loaded.";
+ }
+
+ return true;
+}
+
+OPENTRACK_DECLARE_PROTOCOL(FTNoIR_Protocol, FSUIPCControls, FTNoIR_ProtocolDll)
diff --git a/proto-fsuipc/ftnoir_protocol_fsuipc.h b/proto-fsuipc/ftnoir_protocol_fsuipc.h
new file mode 100644
index 00000000..c8e91a42
--- /dev/null
+++ b/proto-fsuipc/ftnoir_protocol_fsuipc.h
@@ -0,0 +1,90 @@
+/* Homepage http://facetracknoir.sourceforge.net/home/default.htm *
+ * *
+ * ISC License (ISC) *
+ * *
+ * Copyright (c) 2015, Wim Vriend *
+ * *
+ * Permission to use, copy, modify, and/or distribute this software for any *
+ * purpose with or without fee is hereby granted, provided that the above *
+ * copyright notice and this permission notice appear in all copies. *
+ */
+#pragma once
+#ifndef INCLUDED_FSUIPCSERVER_H
+#define INCLUDED_FSUIPCSERVER_H
+
+#include <windows.h>
+#include <stdlib.h>
+#include "FSUIPC_User.h"
+#include "opentrack/plugin-api.hpp"
+#include "ui_ftnoir_fsuipccontrols.h"
+#include <QMessageBox>
+#include <QSettings>
+#include <QLibrary>
+#include <QProcess>
+#include <QDebug>
+#include <QFile>
+#include <QFileDialog>
+#include "opentrack/options.hpp"
+using namespace options;
+
+#define FSUIPC_FILENAME "C:\\Program Files\\Microsoft Games\\Flight Simulator 9\\Modules\\FSUIPC.dll"
+
+struct settings : opts {
+ value<QString> LocationOfDLL;
+ settings() :
+ opts("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();
+ ~FTNoIR_Protocol() override;
+ bool correct();
+ void pose(const double* headpose);
+ QString game_name() {
+ 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 IProtocolDialog
+{
+ Q_OBJECT
+public:
+ FSUIPCControls();
+ void register_protocol(IProtocol *) {}
+ void unregister_protocol() {}
+private:
+ Ui::UICFSUIPCControls ui;
+ settings s;
+private slots:
+ void doOK();
+ void doCancel();
+ void getLocationOfDLL();
+};
+
+class FTNoIR_ProtocolDll : public Metadata
+{
+public:
+ QString name() { return QString("FSUIPC -- Microsoft FS2002/FS2004"); }
+ QIcon icon() { return QIcon(":/images/fs9.png"); }
+};
+
+
+#endif//INCLUDED_FSUIPCSERVER_H
+//END
diff --git a/proto-fsuipc/ftnoir_protocol_fsuipc_dialog.cpp b/proto-fsuipc/ftnoir_protocol_fsuipc_dialog.cpp
new file mode 100644
index 00000000..d573420a
--- /dev/null
+++ b/proto-fsuipc/ftnoir_protocol_fsuipc_dialog.cpp
@@ -0,0 +1,43 @@
+/* Homepage http://facetracknoir.sourceforge.net/home/default.htm *
+ * *
+ * ISC License (ISC) *
+ * *
+ * Copyright (c) 2015, Wim Vriend *
+ * *
+ * Permission to use, copy, modify, and/or distribute this software for any *
+ * purpose with or without fee is hereby granted, provided that the above *
+ * copyright notice and this permission notice appear in all copies. *
+ */
+#include "ftnoir_protocol_fsuipc.h"
+#include "opentrack/plugin-api.hpp"
+
+FSUIPCControls::FSUIPCControls()
+{
+ 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->reload();
+ 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;
+ }
+}
+
diff --git a/proto-fsuipc/images/fs9.png b/proto-fsuipc/images/fs9.png
new file mode 100644
index 00000000..914c9dcb
--- /dev/null
+++ b/proto-fsuipc/images/fs9.png
Binary files differ
diff --git a/proto-fsuipc/images/fs91.png b/proto-fsuipc/images/fs91.png
new file mode 100644
index 00000000..f9540d1d
--- /dev/null
+++ b/proto-fsuipc/images/fs91.png
Binary files differ