summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2013-12-30 13:26:21 +0100
committerStanislaw Halik <sthalik@misaki.pl>2013-12-30 13:27:26 +0100
commitbfaa79b997032769cf6b2b68f275260f618dbf58 (patch)
tree4e19a7840e5593338cdb9ef14e2099d8bf0fd8d2
parenta54f8dede2cc679d0ef2fe30369cf3764ad3ab54 (diff)
settings framework for rift
-rw-r--r--ftnoir_tracker_rift/ftnoir_tracker_rift.cpp81
-rw-r--r--ftnoir_tracker_rift/ftnoir_tracker_rift.h44
-rw-r--r--ftnoir_tracker_rift/ftnoir_tracker_rift_dialog.cpp115
3 files changed, 42 insertions, 198 deletions
diff --git a/ftnoir_tracker_rift/ftnoir_tracker_rift.cpp b/ftnoir_tracker_rift/ftnoir_tracker_rift.cpp
index da44ea0c..e10db0bf 100644
--- a/ftnoir_tracker_rift/ftnoir_tracker_rift.cpp
+++ b/ftnoir_tracker_rift/ftnoir_tracker_rift.cpp
@@ -8,14 +8,6 @@ using namespace OVR;
Rift_Tracker::Rift_Tracker()
{
- bEnableRoll = true;
- bEnablePitch = true;
- bEnableYaw = true;
-#if 0
- bEnableX = true;
- bEnableY = true;
- bEnableZ = true;
-#endif
should_quit = false;
pManager = NULL;
pSensor = NULL;
@@ -38,10 +30,6 @@ Rift_Tracker::~Rift_Tracker()
void Rift_Tracker::StartTracker(QFrame*)
{
- loadSettings();
- //
- // Startup the Oculus SDK device handling, use the first Rift sensor we find.
- //
System::Init(Log::ConfigureDefaultLog(LogMask_All));
pManager = DeviceManager::Create();
if (pManager != NULL)
@@ -81,80 +69,25 @@ void Rift_Tracker::GetHeadPoseData(double *data)
newHeadPose[Pitch] = pitch;
newHeadPose[Roll] = roll;
newHeadPose[Yaw] = yaw;
- if (useYawSpring)
+ if (s.useYawSpring)
{
- newHeadPose[Yaw] = old_yaw*persistence + (yaw-old_yaw);
- if(newHeadPose[Yaw]>deadzone)newHeadPose[Yaw]-= constant_drift;
- if(newHeadPose[Yaw]<-deadzone)newHeadPose[Yaw]+= constant_drift;
+ newHeadPose[Yaw] = old_yaw*s.persistence + (yaw-old_yaw);
+ if(newHeadPose[Yaw]>s.deadzone)newHeadPose[Yaw]-= s.constant_drift;
+ if(newHeadPose[Yaw]<-s.deadzone)newHeadPose[Yaw]+= s.constant_drift;
old_yaw=yaw;
}
-#if 0
- newHeadPose[TX] = acd.controllers[0].pos[0]/50.0f;
- newHeadPose[TY] = acd.controllers[0].pos[1]/50.0f;
- newHeadPose[TZ] = acd.controllers[0].pos[2]/50.0f;
-
- if (bEnableX) {
- data[TX] = newHeadPose[TX];
- }
- if (bEnableY) {
- data[TY] = newHeadPose[TY];
- }
- if (bEnableY) {
- data[TZ] = newHeadPose[TZ];
- }
-#endif
- if (bEnableYaw) {
+ if (s.bEnableYaw) {
data[Yaw] = newHeadPose[Yaw] * 57.295781f;
}
- if (bEnablePitch) {
+ if (s.bEnablePitch) {
data[Pitch] = newHeadPose[Pitch] * 57.295781f;
}
- if (bEnableRoll) {
+ if (s.bEnableRoll) {
data[Roll] = newHeadPose[Roll] * 57.295781f;
}
}
}
-
-//
-// Load the current Settings from the currently 'active' INI-file.
-//
-void Rift_Tracker::loadSettings() {
-
- qDebug() << "FTNoIR_Tracker::loadSettings says: Starting ";
- QSettings settings("opentrack"); // 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)
-
- qDebug() << "FTNoIR_Tracker::loadSettings says: iniFile = " << currentFile;
-
- iniFile.beginGroup ( "Rift" );
- bEnableRoll = iniFile.value ( "EnableRoll", 1 ).toBool();
- bEnablePitch = iniFile.value ( "EnablePitch", 1 ).toBool();
- bEnableYaw = iniFile.value ( "EnableYaw", 1 ).toBool();
-#if 0
- bEnableX = iniFile.value ( "EnableX", 1 ).toBool();
- bEnableY = iniFile.value ( "EnableY", 1 ).toBool();
- bEnableZ = iniFile.value ( "EnableZ", 1 ).toBool();
-#endif
- useYawSpring = iniFile.value("yaw-spring", false).toBool();
- constant_drift = iniFile.value("constant-drift", 0.000005).toDouble();
- persistence = iniFile.value("persistence", 0.99999).toDouble();
- deadzone = iniFile.value("deadzone", 0.02).toDouble();
- iniFile.endGroup ();
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
-// Factory function that creates instances if the Tracker object.
-
-// Export both decorated and undecorated names.
-// GetTracker - Undecorated name, which can be easily used with GetProcAddress
-// Win32 API function.
-// _GetTracker@0 - Common name decoration for __stdcall functions in C language.
-//#pragma comment(linker, "/export:GetTracker=_GetTracker@0")
-
extern "C" FTNOIR_TRACKER_BASE_EXPORT ITracker* CALLING_CONVENTION GetConstructor()
{
return new Rift_Tracker;
diff --git a/ftnoir_tracker_rift/ftnoir_tracker_rift.h b/ftnoir_tracker_rift/ftnoir_tracker_rift.h
index 3920c6ad..eadf5fa5 100644
--- a/ftnoir_tracker_rift/ftnoir_tracker_rift.h
+++ b/ftnoir_tracker_rift/ftnoir_tracker_rift.h
@@ -8,6 +8,25 @@
#include "facetracknoir/global-settings.h"
#include "OVR.h"
#include <memory>
+#include "facetracknoir/options.hpp"
+using namespace options;
+
+struct settings {
+ pbundle b;
+ value<bool> bEnableYaw, bEnablePitch, bEnableRoll, useYawSpring;
+ value<double> constant_drift, persistence, deadzone;
+ settings() :
+ b(bundle("Rift")),
+ bEnableYaw(b, "EnableYaw", true),
+ bEnablePitch(b, "EnablePitch", true),
+ bEnableRoll(b, "EnableRoll", true),
+ useYawSpring(b, "yaw-spring", false),
+ constant_drift(b, "constant-drift", 0.000005),
+ persistence(b, "persistence", 0.99999),
+ deadzone(b, "deadzone", 0.02)
+ {}
+};
+
class Rift_Tracker : public ITracker
{
public:
@@ -16,7 +35,6 @@ public:
void StartTracker(QFrame *) virt_override;
void GetHeadPoseData(double *data) virt_override;
- void loadSettings();
virtual int preferredHz() virt_override { return 250; }
volatile bool should_quit;
protected:
@@ -27,16 +45,8 @@ private:
OVR::DeviceManager* pManager;
OVR::SensorDevice* pSensor;
OVR::SensorFusion* pSFusion;
- bool bEnableRoll;
- bool bEnablePitch;
- bool bEnableYaw;
-#if 0
- bool bEnableX;
- bool bEnableY;
- bool bEnableZ;
-#endif
- bool useYawSpring;
- double old_yaw, constant_drift, persistence, deadzone;
+ settings s;
+ double old_yaw;
};
// Widget that has controls for FTNoIR protocol client-settings.
@@ -44,10 +54,7 @@ class TrackerControls: public QWidget, public ITrackerDialog
{
Q_OBJECT
public:
-
explicit TrackerControls();
- ~TrackerControls();
- void showEvent (QShowEvent *);
void Initialize(QWidget *parent);
void registerTracker(ITracker *) {}
@@ -55,17 +62,10 @@ public:
private:
Ui::UIRiftControls ui;
- void loadSettings();
- void save();
-
- /** helper **/
- bool settingsDirty;
-
+ settings s;
private slots:
void doOK();
void doCancel();
- void settingChanged() { settingsDirty = true; }
- void settingChanged(int) { settingsDirty = true; }
};
//*******************************************************************************************************
diff --git a/ftnoir_tracker_rift/ftnoir_tracker_rift_dialog.cpp b/ftnoir_tracker_rift/ftnoir_tracker_rift_dialog.cpp
index 2efefbb3..5d3b30c1 100644
--- a/ftnoir_tracker_rift/ftnoir_tracker_rift_dialog.cpp
+++ b/ftnoir_tracker_rift/ftnoir_tracker_rift_dialog.cpp
@@ -17,28 +17,16 @@ QWidget()
connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK()));
connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel()));
- connect(ui.chkEnableRoll, SIGNAL(stateChanged(int)), this, SLOT(settingChanged(int)));
- connect(ui.chkEnablePitch, SIGNAL(stateChanged(int)), this, SLOT(settingChanged(int)));
- connect(ui.chkEnableYaw, SIGNAL(stateChanged(int)), this, SLOT(settingChanged(int)));
-#if 0
- connect(ui.chkEnableX, SIGNAL(stateChanged(int)), this, SLOT(settingChanged(int)));
- connect(ui.chkEnableY, SIGNAL(stateChanged(int)), this, SLOT(settingChanged(int)));
- connect(ui.chkEnableZ, SIGNAL(stateChanged(int)), this, SLOT(settingChanged(int)));
-#endif
- // Load the settings from the current .INI-file
- loadSettings();
+ tie_setting(s.bEnableYaw, ui.chkEnableYaw);
+ tie_setting(s.bEnablePitch, ui.chkEnablePitch);
+ tie_setting(s.bEnableRoll, ui.chkEnableRoll);
+
+ tie_setting(s.constant_drift, ui.constantDrift);
+ tie_setting(s.deadzone, ui.deadzone);
+ tie_setting(s.persistence, ui.persistence);
+ tie_setting(s.useYawSpring, ui.yawSpring);
}
-//
-// Destructor for server-dialog
-//
-TrackerControls::~TrackerControls() {
- qDebug() << "~TrackerControls() says: started";
-}
-
-//
-// Initialize tracker-client-dialog
-//
void TrackerControls::Initialize(QWidget *parent) {
QPoint offsetpos(100, 100);
@@ -52,15 +40,10 @@ void TrackerControls::Initialize(QWidget *parent) {
// OK clicked on server-dialog
//
void TrackerControls::doOK() {
- save();
+ s.b->save();
this->close();
}
-// override show event
-void TrackerControls::showEvent ( QShowEvent * ) {
- loadSettings();
-}
-
//
// Cancel clicked on server-dialog
//
@@ -68,24 +51,19 @@ void TrackerControls::doCancel() {
//
// Ask if changed Settings should be saved
//
- if (settingsDirty) {
- int ret = QMessageBox::question ( this, "Settings have changed", "Do you want to save the settings?", QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard );
-
- qDebug() << "doCancel says: answer =" << ret;
-
+ if (s.b->modifiedp()) {
+ int ret = QMessageBox::question ( this, "Settings have changed", "Do you want to save the settings?", QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
switch (ret) {
case QMessageBox::Save:
- save();
+ s.b->save();
this->close();
break;
case QMessageBox::Discard:
+ s.b->revert();
this->close();
break;
case QMessageBox::Cancel:
- // Cancel was clicked
- break;
default:
- // should never be reached
break;
}
}
@@ -94,73 +72,6 @@ void TrackerControls::doCancel() {
}
}
-
-//
-// Load the current Settings from the currently 'active' INI-file.
-//
-void TrackerControls::loadSettings() {
-
-// qDebug() << "loadSettings says: Starting ";
- QSettings settings("opentrack"); // 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)
-
-// qDebug() << "loadSettings says: iniFile = " << currentFile;
-
- iniFile.beginGroup ( "Rift" );
- ui.chkEnableRoll->setChecked(iniFile.value ( "EnableRoll", 1 ).toBool());
- ui.chkEnablePitch->setChecked(iniFile.value ( "EnablePitch", 1 ).toBool());
- ui.chkEnableYaw->setChecked(iniFile.value ( "EnableYaw", 1 ).toBool());
-#if 0
- ui.chkEnableX->setChecked(iniFile.value ( "EnableX", 1 ).toBool());
- ui.chkEnableY->setChecked(iniFile.value ( "EnableY", 1 ).toBool());
- ui.chkEnableZ->setChecked(iniFile.value ( "EnableZ", 1 ).toBool());
-#endif
- ui.yawSpring->setChecked(iniFile.value("yaw-spring", true).toBool());
- ui.deadzone->setValue(iniFile.value("deadzone", 0.02).toDouble());
- ui.constantDrift->setValue(iniFile.value("constant-drift", 0.000005).toDouble());
- ui.persistence->setValue(iniFile.value("persistence", 0.9999).toDouble());
- iniFile.endGroup ();
-
- settingsDirty = false;
-}
-
-//
-// Save the current Settings to the currently 'active' INI-file.
-//
-void TrackerControls::save() {
- QSettings settings("opentrack"); // 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)
-
- iniFile.beginGroup ( "Rift" );
- iniFile.setValue ( "EnableRoll", ui.chkEnableRoll->isChecked() );
- iniFile.setValue ( "EnablePitch", ui.chkEnablePitch->isChecked() );
- iniFile.setValue ( "EnableYaw", ui.chkEnableYaw->isChecked() );
-#if 0
- iniFile.setValue ( "EnableX", ui.chkEnableX->isChecked() );
- iniFile.setValue ( "EnableY", ui.chkEnableY->isChecked() );
- iniFile.setValue ( "EnableZ", ui.chkEnableZ->isChecked() );
-#endif
- iniFile.setValue("yaw-spring", ui.yawSpring->isChecked());
- iniFile.setValue("deadzone", ui.deadzone->value());
- iniFile.setValue("constant-drift", ui.constantDrift->value());
- iniFile.setValue("persistence", ui.persistence->value());
- iniFile.endGroup ();
-
- settingsDirty = false;
-}
-////////////////////////////////////////////////////////////////////////////////
-// Factory function that creates instances if the Tracker-settings dialog object.
-
-// Export both decorated and undecorated names.
-// GetTrackerDialog - Undecorated name, which can be easily used with GetProcAddress
-// Win32 API function.
-// _GetTrackerDialog@0 - Common name decoration for __stdcall functions in C language.
-//#pragma comment(linker, "/export:GetTrackerDialog=_GetTrackerDialog@0")
-
extern "C" FTNOIR_TRACKER_BASE_EXPORT ITrackerDialog* CALLING_CONVENTION GetDialog( )
{
return new TrackerControls;