summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ftnoir_tracker_hatire/ftnoir_tracker_hat.cpp207
-rw-r--r--ftnoir_tracker_hatire/ftnoir_tracker_hat.h44
-rw-r--r--ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.cpp198
-rw-r--r--ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.h47
-rw-r--r--ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.cpp145
-rw-r--r--ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.h124
6 files changed, 240 insertions, 525 deletions
diff --git a/ftnoir_tracker_hatire/ftnoir_tracker_hat.cpp b/ftnoir_tracker_hatire/ftnoir_tracker_hat.cpp
index f902b207..dc4b2879 100644
--- a/ftnoir_tracker_hatire/ftnoir_tracker_hat.cpp
+++ b/ftnoir_tracker_hatire/ftnoir_tracker_hat.cpp
@@ -39,7 +39,6 @@ FTNoIR_Tracker::FTNoIR_Tracker()
HAT.Trans[1]=0;
HAT.Trans[2]=0;
-
// prepare & reserve QByteArray
dataRead.resize(4096);
dataRead.clear();
@@ -47,8 +46,6 @@ FTNoIR_Tracker::FTNoIR_Tracker()
Begin.append((char) 0xAA);
End.append((char) 0x55);
End.append((char) 0x55);
-
- settings.load_ini();
}
FTNoIR_Tracker::~FTNoIR_Tracker()
@@ -64,20 +61,18 @@ FTNoIR_Tracker::~FTNoIR_Tracker()
//send CENTER to Arduino
void FTNoIR_Tracker::notifyCenter() {
- sendcmd(sCmdCenter);
+ sendcmd(static_cast<QString>(settings.CmdCenter).toLatin1());
}
//send ZERO to Arduino
bool FTNoIR_Tracker::notifyZeroed() {
- sendcmd(sCmdZero);
+ sendcmd(static_cast<QString>(settings.CmdZero).toLatin1());
return true;
}
-
-
//send RESET to Arduino
void FTNoIR_Tracker::reset() {
- sendcmd(sCmdReset);
+ sendcmd(static_cast<QString>(settings.CmdReset).toLatin1());
}
@@ -266,39 +261,91 @@ void FTNoIR_Tracker::StopTracker( bool exit )
#else
void FTNoIR_Tracker::StartTracker(QFrame*)
{
+ static const int databits_lookup[] = {
+ 5,
+ 6,
+ 7,
+ 8,
+ -1
+ };
+
+ struct Local {
+ static int idx(int max, int value)
+ {
+ if (value < 0)
+ return 0;
+ if (max > value)
+ return value;
+ return max - 1;
+ }
+ };
+
+ static const int parity_lookup[] = {
+ QSerialPort::NoParity,
+ QSerialPort::EvenParity,
+ QSerialPort::OddParity,
+ QSerialPort::SpaceParity,
+ QSerialPort::MarkParity,
+ QSerialPort::UnknownParity
+ };
+
+ static const int stopbits_lookup[] = {
+ QSerialPort::OneStop,
+ QSerialPort::OneAndHalfStop,
+ QSerialPort::TwoStop,
+ QSerialPort::UnknownStopBits
+ };
+
+ static const int flowctl_lookup[] = {
+ QSerialPort::NoFlowControl,
+ QSerialPort::HardwareControl,
+ QSerialPort::SoftwareControl,
+ };
+
+ static const int baudrate_lookup[] = {
+ QSerialPort::Baud1200,
+ QSerialPort::Baud2400,
+ QSerialPort::Baud4800,
+ QSerialPort::Baud9600,
+ QSerialPort::Baud19200,
+ QSerialPort::Baud38400,
+ QSerialPort::Baud57600,
+ QSerialPort::Baud115200,
+ QSerialPort::UnknownBaud
+ };
+
CptError=0;
dataRead.clear();
frame_cnt=0;
-
- settings.load_ini();
- applysettings(settings);
ComPort = new QSerialPort(this);
- ComPort->setPortName(sSerialPortName);
- if (ComPort->open(QIODevice::ReadWrite ) == true) {
+ {
+ ComPort->setPortName(QSerialPortInfo::availablePorts().value(settings.SerialPortName).portName());
+ }
+ if (ComPort->open(QIODevice::ReadWrite ) == true) {
connect(ComPort, SIGNAL(readyRead()), this, SLOT(SerialRead()));
if (
- ComPort->setBaudRate((QSerialPort::BaudRate)iBaudRate)
- && ComPort->setDataBits((QSerialPort::DataBits)iDataBits)
- && ComPort->setParity((QSerialPort::Parity)iParity)
- && ComPort->setStopBits((QSerialPort::StopBits)iStopBits)
- && ComPort->setFlowControl((QSerialPort::FlowControl)iFlowControl)
+ ComPort->setBaudRate(baudrate_lookup[Local::idx(8, settings.pBaudRate)])
+ && ComPort->setDataBits((QSerialPort::DataBits)databits_lookup[Local::idx(4, settings.pDataBits)])
+ && ComPort->setParity((QSerialPort::Parity)parity_lookup[Local::idx(5, settings.pParity)])
+ && ComPort->setStopBits((QSerialPort::StopBits)stopbits_lookup[Local::idx(3, settings.pStopBits)])
+ && ComPort->setFlowControl((QSerialPort::FlowControl)flowctl_lookup[Local::idx(3, settings.pFlowControl)])
&& ComPort->clear(QSerialPort::AllDirections)
- && ComPort->setDataErrorPolicy(QSerialPort::IgnorePolicy)
- ) {
+ && ComPort->setDataErrorPolicy(QSerialPort::IgnorePolicy)
+ ){
// Wait init arduino sequence
- for (int i = 1; i <=iDelayInit; i+=50) {
+ for (int i = 1; i <=settings.DelayInit; i+=50) {
if (ComPort->waitForReadyRead(50)) break;
}
- sendcmd(sCmdInit);
+ sendcmd(static_cast<QString>(settings.CmdInit).toLatin1());
// Wait init MPU sequence
- for (int i = 1; i <=iDelayStart; i+=50) {
+ for (int i = 1; i <=settings.DelayStart; i+=50) {
if (ComPort->waitForReadyRead(50)) break;
}
// Send START cmd to IMU
- sendcmd(sCmdStart);
+ sendcmd(static_cast<QString>(settings.CmdStart).toLatin1());
// Wait start MPU sequence
- for (int i = 1; i <=iDelaySeq; i+=50) {
+ for (int i = 1; i <=settings.DelaySeq; i+=50) {
if (ComPort->waitForReadyRead(50)) break;
}
} else {
@@ -329,7 +376,7 @@ void FTNoIR_Tracker::GetHeadPoseData(THeadPoseData *data)
while (dataRead.length()>=30) {
if ((dataRead.startsWith(Begin) && ( dataRead.mid(28,2)==End )) ) { // .Begin==0xAAAA .End==0x5555
QDataStream datastream(dataRead.left(30));
- if (bBigEndian) datastream.setByteOrder(QDataStream::BigEndian );
+ if (settings.BigEndian) datastream.setByteOrder(QDataStream::BigEndian );
else datastream.setByteOrder(QDataStream::LittleEndian );
datastream>>ArduinoData;
frame_cnt++;
@@ -359,34 +406,45 @@ void FTNoIR_Tracker::GetHeadPoseData(THeadPoseData *data)
#ifdef OPENTRACK_API
data[frame_cnt] = (long) HAT.Code;
- if (bEnableYaw) {
- if (bInvertYaw ) data[Yaw] = (double) HAT.Rot[iYawAxe] * -1.0f;
- else data[Yaw] = (double) HAT.Rot[iYawAxe];
+ struct Fun {
+ static int clamp3(int foo)
+ {
+ if (foo > 2)
+ return 2;
+ if (foo < 0)
+ return 0;
+ return foo;
+ }
+ };
+
+ if (settings.EnableYaw) {
+ if (settings.InvertYaw) data[Yaw] = (double) HAT.Rot[Fun::clamp3(settings.YawAxe)] * -1.0f;
+ else data[Yaw] = (double) HAT.Rot[Fun::clamp3(settings.YawAxe)];
}
- if (bEnablePitch) {
- if (bInvertPitch) data[Pitch] = (double) HAT.Rot[iPitchAxe] * -1.0f;
- else data[Pitch] = (double) HAT.Rot[iPitchAxe];
+ if (settings.EnablePitch) {
+ if (settings.InvertPitch) data[Pitch] = (double) HAT.Rot[Fun::clamp3(settings.PitchAxe)] * -1.0f;
+ else data[Pitch] = (double) HAT.Rot[Fun::clamp3(settings.InvertPitch)];
}
- if (bEnableRoll) {
- if (bInvertRoll) data[Roll] = (double) HAT.Rot[iRollAxe] * -1.0f;
- else data[Roll] = (double) HAT.Rot[iRollAxe];
+ if (settings.EnableRoll) {
+ if (settings.InvertRoll) data[Roll] = (double) HAT.Rot[Fun::clamp3(settings.RollAxe)] * -1.0f;
+ else data[Roll] = (double) HAT.Rot[Fun::clamp3(settings.RollAxe)];
}
- if (bEnableX) {
- if (bInvertX) data[TX] =(double) HAT.Trans[iXAxe]* -1.0f;
- else data[TX] = HAT.Trans[iXAxe];
+ if (settings.EnableX) {
+ if (settings.InvertX) data[TX] =(double) HAT.Trans[Fun::clamp3(settings.XAxe)]* -1.0f;
+ else data[TX] = HAT.Trans[Fun::clamp3(settings.XAxe)];
}
- if (bEnableY) {
- if (bInvertY) data[TY] =(double) HAT.Trans[iYAxe]* -1.0f;
- else data[TY] = HAT.Trans[iYAxe];
+ if (settings.EnableY) {
+ if (settings.InvertY) data[TY] =(double) HAT.Trans[Fun::clamp3(settings.YAxe)]* -1.0f;
+ else data[TY] = HAT.Trans[Fun::clamp3(settings.YAxe)];
}
- if (bEnableZ) {
- if (bInvertZ) data[TZ] = HAT.Trans[iZAxe]* -1.0f;
- else data[TZ] = HAT.Trans[iZAxe];
+ if (settings.EnableZ) {
+ if (settings.InvertZ) data[TZ] = HAT.Trans[Fun::clamp3(settings.ZAxe)]* -1.0f;
+ else data[TZ] = HAT.Trans[Fun::clamp3(settings.ZAxe)];
}
#else
data->frame_number = (long) HAT.Code;
@@ -421,72 +479,13 @@ void FTNoIR_Tracker::GetHeadPoseData(THeadPoseData *data)
else data->z = (double) HAT.Trans[iZAxe];
}
#endif
-
- // For debug
- //data->x=dataRead.length();
- //data->y=CptError;
}
-
-
-//
-// Apply modification Settings
-//
void FTNoIR_Tracker::applysettings(const TrackerSettings& settings){
QMutexLocker lck(&mutex);
- sSerialPortName= settings.SerialPortName;
-
- bEnableRoll = settings.EnableRoll;
- bEnablePitch = settings.EnablePitch;
- bEnableYaw = settings.EnableYaw;
- bEnableX = settings.EnableX;
- bEnableY = settings.EnableY;
- bEnableZ = settings.EnableZ;
-
- bInvertRoll = settings.InvertRoll;
- bInvertPitch = settings.InvertPitch;
- bInvertYaw = settings.InvertYaw;
- bInvertX = settings.InvertX;
- bInvertY = settings.InvertY;
- bInvertZ = settings.InvertZ;
-
- iRollAxe= settings.RollAxe;
- iPitchAxe= settings.PitchAxe;
- iYawAxe= settings.YawAxe;
- iXAxe= settings.XAxe;
- iYAxe= settings.YAxe;
- iZAxe= settings.ZAxe;
-
- iBaudRate=settings.pBaudRate;
- iDataBits=settings.pDataBits;
- iParity=settings.pParity;
- iStopBits=settings.pStopBits;
- iFlowControl=settings.pFlowControl;
-
- sCmdStart= settings.CmdStart.toLatin1();
- sCmdStop= settings.CmdStop.toLatin1();
- sCmdInit= settings.CmdInit.toLatin1();
- sCmdReset= settings.CmdReset.toLatin1();
- sCmdCenter= settings.CmdCenter.toLatin1();
- sCmdZero= settings.CmdZero.toLatin1();
-
- iDelayInit=settings.DelayInit;
- iDelayStart=settings.DelayStart;
- iDelaySeq=settings.DelaySeq;
-
- bBigEndian=settings.BigEndian;
+ settings.b->reload();
}
-
-
-////////////////////////////////////////////////////////////////////////////////
-// 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.
-////////////////////////////////////////////////////////////////////////////////
#ifdef OPENTRACK_API
extern "C" FTNOIR_TRACKER_BASE_EXPORT ITracker* CALLING_CONVENTION GetConstructor()
#else
diff --git a/ftnoir_tracker_hatire/ftnoir_tracker_hat.h b/ftnoir_tracker_hatire/ftnoir_tracker_hat.h
index ec1125b9..a4243c38 100644
--- a/ftnoir_tracker_hatire/ftnoir_tracker_hat.h
+++ b/ftnoir_tracker_hatire/ftnoir_tracker_hat.h
@@ -62,51 +62,7 @@ private:
int frame_cnt;
TrackerSettings settings;
-
- bool bEnableRoll;
- bool bEnablePitch;
- bool bEnableYaw;
- bool bEnableX;
- bool bEnableY;
- bool bEnableZ;
-
- bool bInvertRoll;
- bool bInvertPitch;
- bool bInvertYaw;
- bool bInvertX;
- bool bInvertY;
- bool bInvertZ;
-
- int iRollAxe;
- int iPitchAxe;
- int iYawAxe;
- int iXAxe;
- int iYAxe;
- int iZAxe;
-
- QByteArray sCmdStart;
- QByteArray sCmdStop;
- QByteArray sCmdInit;
- QByteArray sCmdReset;
- QByteArray sCmdCenter;
- QByteArray sCmdZero;
-
- int iDelayInit;
- int iDelayStart;
- int iDelaySeq;
-
- bool bBigEndian;
-
- QString sSerialPortName;
- QSerialPort::BaudRate iBaudRate;
- QSerialPort::DataBits iDataBits;
- QSerialPort::Parity iParity;
- QSerialPort::StopBits iStopBits;
- QSerialPort::FlowControl iFlowControl;
-
int CptError;
-
-
};
diff --git a/ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.cpp b/ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.cpp
index 14b6ef0d..0ef723c9 100644
--- a/ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.cpp
+++ b/ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.cpp
@@ -37,11 +37,10 @@
//
// Constructor for server-settings-dialog
//
-TrackerControls::TrackerControls() : theTracker(NULL), settingsDirty(false), timer(this)
+TrackerControls::TrackerControls() : theTracker(NULL), timer(this)
{
ui.setupUi( this );
- settings.load_ini();
ui.label_version->setText(VER_FILEVERSION_STR);
@@ -49,21 +48,13 @@ TrackerControls::TrackerControls() : theTracker(NULL), settingsDirty(false), tim
ui.cbSerialPort->clear();
foreach (QSerialPortInfo PortInfo , QSerialPortInfo::availablePorts() ) {
ui.cbSerialPort->addItem(PortInfo.portName());
- }
-
+ }
// Stop if no SerialPort dispo
if (ui.cbSerialPort->count()<1) {
QMessageBox::critical(this,"FaceTrackNoIR Error", "No SerialPort avaible");
} else {
-
- int indxport =ui.cbSerialPort->findText(settings.SerialPortName,Qt::MatchExactly );
- if (indxport!=-1) {
- ui.cbSerialPort->setCurrentIndex(indxport);
- } else {
- QMessageBox::warning(this,"FaceTrackNoIR Error", "Selected SerialPort modified");
- ui.cbSerialPort-> setCurrentIndex(indxport);
- }
+ ui.cbSerialPort->setCurrentIndex(settings.SerialPortName);
}
// Serial config
ui.QCB_Serial_baudRate->clear();
@@ -72,122 +63,79 @@ TrackerControls::TrackerControls() : theTracker(NULL), settingsDirty(false), tim
ui.QCB_Serial_baudRate->addItem(QLatin1String("38400"),QSerialPort::Baud38400);
ui.QCB_Serial_baudRate->addItem(QLatin1String("57600"),QSerialPort:: Baud57600);
ui.QCB_Serial_baudRate->addItem(QLatin1String("115200"),QSerialPort::Baud115200);
- ui.QCB_Serial_baudRate->setCurrentIndex(ui.QCB_Serial_baudRate->findData(settings.pBaudRate));
ui.QCB_Serial_dataBits->clear();
ui.QCB_Serial_dataBits->addItem(QLatin1String("5"), QSerialPort::Data5);
ui.QCB_Serial_dataBits->addItem(QLatin1String("6"), QSerialPort::Data6);
ui.QCB_Serial_dataBits->addItem(QLatin1String("7"), QSerialPort::Data7);
ui.QCB_Serial_dataBits->addItem(QLatin1String("8"), QSerialPort::Data8);
- ui.QCB_Serial_dataBits->setCurrentIndex(ui.QCB_Serial_dataBits->findData(settings.pDataBits));
ui.QCB_Serial_parity->clear();
ui.QCB_Serial_parity->addItem(QLatin1String("None"), QSerialPort::NoParity);
ui.QCB_Serial_parity->addItem(QLatin1String("Even"), QSerialPort::EvenParity);
ui.QCB_Serial_parity->addItem(QLatin1String("Odd"), QSerialPort::OddParity);
- ui.QCB_Serial_parity->addItem(QLatin1String("Mark"), QSerialPort::MarkParity);
ui.QCB_Serial_parity->addItem(QLatin1String("Space"), QSerialPort::SpaceParity);
- ui.QCB_Serial_parity->setCurrentIndex(ui.QCB_Serial_parity->findData(settings.pParity));
+ ui.QCB_Serial_parity->addItem(QLatin1String("Mark"), QSerialPort::MarkParity);
ui.QCB_Serial_stopBits->clear();
- ui.QCB_Serial_stopBits->addItem(QLatin1String("1"), QSerialPort::OneStop);
- ui.QCB_Serial_stopBits->addItem(QLatin1String("1.5"), QSerialPort::OneAndHalfStop);
- ui.QCB_Serial_stopBits->addItem(QLatin1String("2"), QSerialPort::TwoStop);
- ui.QCB_Serial_stopBits->setCurrentIndex(ui.QCB_Serial_stopBits->findData(settings.pStopBits));
+ ui.QCB_Serial_stopBits->addItem(QLatin1String("1"));
+ ui.QCB_Serial_stopBits->addItem(QLatin1String("1.5"));
+ ui.QCB_Serial_stopBits->addItem(QLatin1String("2"));
ui.QCB_Serial_flowControl->clear();
- ui.QCB_Serial_flowControl->addItem(QLatin1String("None"), QSerialPort::NoFlowControl);
- ui.QCB_Serial_flowControl->addItem(QLatin1String("RTS/CTS"), QSerialPort::HardwareControl);
- ui.QCB_Serial_flowControl->addItem(QLatin1String("XON/XOFF"), QSerialPort::SoftwareControl);
- ui.QCB_Serial_flowControl->setCurrentIndex(ui.QCB_Serial_flowControl->findData(settings.pFlowControl));
-
-
- ui.chkEnableRoll->setChecked(settings.EnableRoll);
- ui.chkEnablePitch->setChecked(settings.EnablePitch);
- ui.chkEnableYaw->setChecked(settings.EnableYaw);
- ui.chkEnableX->setChecked(settings.EnableX);
- ui.chkEnableY->setChecked(settings.EnableY);
- ui.chkEnableZ->setChecked(settings.EnableZ);
-
- ui.chkInvertRoll->setChecked(settings.InvertRoll);
- ui.chkInvertPitch->setChecked(settings.InvertPitch);
- ui.chkInvertYaw->setChecked(settings.InvertYaw);
- ui.chkInvertX->setChecked(settings.InvertX);
- ui.chkInvertY->setChecked(settings.InvertY);
- ui.chkInvertZ->setChecked(settings.InvertZ);
-
-
- ui.cb_roll->setCurrentIndex(settings.RollAxe);
- ui.cb_pitch->setCurrentIndex(settings.PitchAxe);
- ui.cb_yaw->setCurrentIndex(settings.YawAxe);
- ui.cb_x->setCurrentIndex(settings.XAxe);
- ui.cb_y->setCurrentIndex(settings.YAxe);
- ui.cb_z->setCurrentIndex(settings.ZAxe);
-
- ui.le_cmd_start->setText(settings.CmdStart);
- ui.le_cmd_stop->setText(settings.CmdStop);
- ui.le_cmd_init->setText(settings.CmdInit);
- ui.le_cmd_reset->setText(settings.CmdReset);
- ui.le_cmd_center->setText(settings.CmdCenter);
- ui.le_cmd_zero->setText(settings.CmdZero);
-
- ui.spb_BeforeInit->setValue(settings.DelayInit);
- ui.spb_BeforeStart->setValue(settings.DelayStart);
- ui.spb_AfterStart->setValue(settings.DelaySeq);
-
- ui.cb_Endian->setChecked(settings.BigEndian);
-
+ ui.QCB_Serial_flowControl->addItem(QLatin1String("None"));
+ ui.QCB_Serial_flowControl->addItem(QLatin1String("RTS/CTS"));
+ ui.QCB_Serial_flowControl->addItem(QLatin1String("XON/XOFF"));
+
+ tie_setting(settings.EnableRoll, ui.chkEnableRoll);
+ tie_setting(settings.EnablePitch, ui.chkEnablePitch);
+ tie_setting(settings.EnableYaw, ui.chkEnableYaw);
+ tie_setting(settings.EnableX, ui.chkEnableX);
+ tie_setting(settings.EnableY, ui.chkEnableY);
+ tie_setting(settings.EnableZ, ui.chkEnableZ);
+
+ tie_setting(settings.InvertRoll, ui.chkInvertRoll);
+ tie_setting(settings.InvertPitch, ui.chkInvertPitch);
+ tie_setting(settings.InvertYaw, ui.chkInvertYaw);
+ tie_setting(settings.InvertX, ui.chkInvertX);
+ tie_setting(settings.InvertY, ui.chkInvertY);
+ tie_setting(settings.InvertZ, ui.chkInvertZ);
+
+ tie_setting(settings.RollAxe, ui.cb_roll);
+ tie_setting(settings.RollAxe, ui.cb_roll);
+ tie_setting(settings.RollAxe, ui.cb_roll);
+
+ tie_setting(settings.XAxe, ui.cb_x);
+ tie_setting(settings.YAxe, ui.cb_y);
+ tie_setting(settings.ZAxe, ui.cb_z);
+
+ tie_setting(settings.CmdStart, ui.le_cmd_start);
+ tie_setting(settings.CmdStop, ui.le_cmd_stop);
+ tie_setting(settings.CmdInit, ui.le_cmd_init);
+ tie_setting(settings.CmdReset, ui.le_cmd_reset);
+ tie_setting(settings.CmdCenter, ui.le_cmd_center);
+ tie_setting(settings.CmdZero, ui.le_cmd_zero);
+
+ tie_setting(settings.DelayInit, ui.spb_BeforeInit);
+ tie_setting(settings.DelayStart, ui.spb_BeforeStart);
+ tie_setting(settings.DelaySeq, ui.spb_AfterStart);
+
+ tie_setting(settings.BigEndian, ui.cb_Endian);
+
+ tie_setting(settings.pBaudRate, ui.QCB_Serial_baudRate);
+ tie_setting(settings.pDataBits, ui.QCB_Serial_dataBits);
+ tie_setting(settings.pParity, ui.QCB_Serial_parity);
+ tie_setting(settings.pStopBits, ui.QCB_Serial_stopBits);
+ tie_setting(settings.pFlowControl, ui.QCB_Serial_flowControl);
+
+ tie_setting(settings.SerialPortName, ui.cbSerialPort);
// Connect Qt signals to member-functions
connect(ui.btnOK, SIGNAL(clicked()), this, SLOT(doOK()));
connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel()));
connect(ui.btnSave, SIGNAL(clicked()), this, SLOT(doSave()));
-
- connect(ui.cbSerialPort, SIGNAL(currentIndexChanged(QString)), this,SLOT(set_mod_port(QString)) );
-
- connect( ui.chkEnableRoll,SIGNAL(toggled(bool)), this,SLOT(set_ena_roll(bool)) );
- connect( ui.chkEnablePitch,SIGNAL(toggled(bool)), this,SLOT(set_ena_pitch(bool)) );
- connect( ui.chkEnableYaw,SIGNAL(toggled(bool)), this,SLOT(set_ena_yaw(bool)) );
- connect( ui.chkEnableX,SIGNAL(toggled(bool)), this,SLOT(set_ena_x(bool)) );
- connect( ui.chkEnableY,SIGNAL(toggled(bool)), this,SLOT(set_ena_y(bool)) );
- connect( ui.chkEnableZ,SIGNAL(toggled(bool)), this,SLOT(set_ena_z(bool)) );
-
- connect( ui.chkInvertRoll,SIGNAL(toggled(bool)), this,SLOT(set_inv_roll(bool)) );
- connect( ui.chkInvertPitch,SIGNAL(toggled(bool)), this,SLOT(set_inv_pitch(bool)) );
- connect( ui.chkInvertYaw,SIGNAL(toggled(bool)), this,SLOT(set_inv_yaw(bool)) );
- connect( ui.chkInvertX,SIGNAL(toggled(bool)), this,SLOT(set_inv_x(bool)) );
- connect( ui.chkInvertY,SIGNAL(toggled(bool)), this,SLOT(set_inv_y(bool)) );
- connect( ui.chkInvertZ,SIGNAL(toggled(bool)), this,SLOT(set_inv_z(bool)) );
-
- connect(ui.cb_roll, SIGNAL(currentIndexChanged(int)), this,SLOT(set_rot_roll(int)));
- connect(ui.cb_pitch, SIGNAL(currentIndexChanged(int)),this,SLOT(set_rot_pitch(int)));
- connect(ui.cb_yaw, SIGNAL(currentIndexChanged(int)), this,SLOT(set_rot_yaw(int)));
- connect(ui.cb_x, SIGNAL(currentIndexChanged(int)), this,SLOT(set_acc_x(int)));
- connect(ui.cb_y, SIGNAL(currentIndexChanged(int)), this,SLOT(set_acc_y(int)));
- connect(ui.cb_z, SIGNAL(currentIndexChanged(int)), this,SLOT(set_acc_z(int)));
-
- connect(ui.le_cmd_start, SIGNAL(textEdited (QString )), this,SLOT(set_cmd_start(QString)));
- connect(ui.le_cmd_stop, SIGNAL(textEdited ( QString )), this,SLOT(set_cmd_stop(QString)));
- connect(ui.le_cmd_init, SIGNAL(textChanged ( QString )), this,SLOT(set_cmd_init(QString)));
- connect(ui.le_cmd_reset, SIGNAL(textChanged ( QString )), this,SLOT(set_cmd_reset(QString)));
- connect(ui.le_cmd_center, SIGNAL(textChanged ( QString )),this,SLOT(set_cmd_center(QString)));
- connect(ui.le_cmd_zero, SIGNAL(textChanged ( QString )),this,SLOT(set_cmd_zero(QString)));
-
- connect(ui.spb_BeforeInit, SIGNAL(valueChanged ( int )), this,SLOT(set_DelayInit(int)));
- connect(ui.spb_BeforeStart, SIGNAL(valueChanged ( int )), this,SLOT(set_DelayStart(int)));
- connect(ui.spb_AfterStart, SIGNAL(valueChanged ( int )), this,SLOT(set_DelaySeq(int)));
-
- connect( ui.cb_Endian,SIGNAL(toggled(bool)), this,SLOT(set_endian(bool)) );
-
-
- connect(ui.QCB_Serial_baudRate, SIGNAL(currentIndexChanged(int)), this,SLOT(set_mod_baud(int)) );
- connect(ui.QCB_Serial_dataBits, SIGNAL(currentIndexChanged(int)), this,SLOT(set_mod_dataBits(int)) );
- connect(ui.QCB_Serial_parity, SIGNAL(currentIndexChanged(int)), this,SLOT(set_mod_parity(int)) );
- connect(ui.QCB_Serial_stopBits, SIGNAL(currentIndexChanged(int)), this,SLOT(set_mod_stopBits(int)) );
- connect(ui.QCB_Serial_flowControl, SIGNAL(currentIndexChanged(int)), this,SLOT(set_mod_flowControl(int)) );
-
connect(ui.btnReset, SIGNAL(clicked()), this, SLOT(doReset()));
connect(ui.btnCenter, SIGNAL(clicked()), this, SLOT(doCenter()));
connect(ui.btnZero, SIGNAL(clicked()), this, SLOT(doZero()));
@@ -196,7 +144,6 @@ TrackerControls::TrackerControls() : theTracker(NULL), settingsDirty(false), tim
connect(ui.btn_icone, SIGNAL(clicked()), this, SLOT(doSerialInfo()));
connect(&timer,SIGNAL(timeout()), this,SLOT(poll_tracker_info()));
-
}
//
@@ -218,16 +165,6 @@ void TrackerControls::Initialize(QWidget *parent) {
//
-// Apply online settings to tracker
-//
-void TrackerControls::settings_changed()
-{
- settingsDirty = true;
- if (theTracker) theTracker->applysettings(settings);
-}
-
-
-//
// Center asked to ARDUINO
//
void TrackerControls::doCenter() {
@@ -299,8 +236,9 @@ void TrackerControls::WriteMsgInfo(const QByteArray &MsgInfo)
void TrackerControls::doSave() {
- settingsDirty=false;
- settings.save_ini();
+ settings.b->save();
+ if (theTracker)
+ theTracker->applysettings(settings);
}
@@ -308,8 +246,9 @@ void TrackerControls::doSave() {
// OK clicked on server-dialog
//
void TrackerControls::doOK() {
- settingsDirty=false;
- settings.save_ini();
+ settings.b->save();
+ if (theTracker)
+ theTracker->applysettings(settings);
this->close();
}
@@ -320,14 +259,15 @@ 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 );
+ if (settings.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:
- settings.save_ini();
+ settings.b->save();
close();
break;
case QMessageBox::Discard:
+ settings.b->revert();
close();
break;
case QMessageBox::Cancel:
@@ -348,7 +288,7 @@ void TrackerControls::registerTracker(ITracker *tracker) {
theTracker = static_cast<FTNoIR_Tracker*>(tracker);
connect(theTracker, SIGNAL(sendMsgInfo(QByteArray)),this , SLOT(WriteMsgInfo(QByteArray)));
- if (isVisible() && settingsDirty) theTracker->applysettings(settings);
+ if (isVisible() && settings.b->modifiedp()) theTracker->applysettings(settings);
ui.cbSerialPort->setEnabled(false);
ui.pteINFO->clear();
@@ -367,16 +307,6 @@ void TrackerControls::unRegisterTracker() {
ui.lab_vtps->setText("");
}
-
-
-
-////////////////////////////////////////////////////////////////////////////////
-// 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.
#ifdef OPENTRACK_API
extern "C" FTNOIR_TRACKER_BASE_EXPORT ITrackerDialog* CALLING_CONVENTION GetDialog( )
#else
diff --git a/ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.h b/ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.h
index e413ded6..82c69e0d 100644
--- a/ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.h
+++ b/ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.h
@@ -25,7 +25,6 @@ public:
void Initialize(QWidget *parent) virt_override;
void registerTracker(ITracker *tracker) virt_override;
void unRegisterTracker() virt_override;
-
private:
Ui::UIHATControls ui;
FTNoIR_Tracker *theTracker;
@@ -35,49 +34,7 @@ public slots:
void WriteMsgInfo(const QByteArray &MsgInfo);
protected slots:
- void set_mod_port(const QString & val) { settings.SerialPortName =val; settings_changed(); }
- void set_ena_roll(bool val) { settings.EnableRoll = val; settings_changed(); }
- void set_ena_pitch(bool val) { settings.EnablePitch = val; settings_changed(); }
- void set_ena_yaw(bool val) { settings.EnableYaw = val; settings_changed(); }
- void set_ena_x(bool val) { settings.EnableX = val; settings_changed(); }
- void set_ena_y(bool val) { settings.EnableY = val; settings_changed(); }
- void set_ena_z(bool val) { settings.EnableZ = val; settings_changed(); }
-
- void set_inv_roll(bool val) { settings.InvertRoll = val; settings_changed(); }
- void set_inv_pitch(bool val) { settings.InvertPitch = val; settings_changed(); }
- void set_inv_yaw(bool val) { settings.InvertYaw = val; settings_changed(); }
- void set_inv_x(bool val) { settings.InvertX = val; settings_changed(); }
- void set_inv_y(bool val) { settings.InvertY = val; settings_changed(); }
- void set_inv_z(bool val) { settings.InvertZ = val; settings_changed(); }
-
-
- void set_rot_roll(int val) { settings.RollAxe = val; settings_changed(); }
- void set_rot_pitch(int val) { settings.PitchAxe = val; settings_changed(); }
- void set_rot_yaw(int val) { settings.YawAxe = val; settings_changed(); }
- void set_acc_x(int val) { settings.XAxe = val; settings_changed(); }
- void set_acc_y(int val) { settings.YAxe = val; settings_changed(); }
- void set_acc_z(int val) { settings.ZAxe = val; settings_changed(); }
-
- void set_cmd_start(const QString &val) { settings.CmdStart = val; settings_changed(); }
- void set_cmd_stop(const QString &val) { settings.CmdStop = val; settings_changed(); }
- void set_cmd_init(const QString &val) { settings.CmdInit = val; settings_changed(); }
- void set_cmd_reset(const QString &val) { settings.CmdReset = val; settings_changed(); }
- void set_cmd_center(const QString &val) { settings.CmdCenter = val; settings_changed(); }
- void set_cmd_zero(const QString &val) { settings.CmdZero = val; settings_changed(); }
-
- void set_DelayInit(int val) { settings.DelayInit = val; settings_changed(); }
- void set_DelayStart(int val) { settings.DelayStart = val; settings_changed(); }
- void set_DelaySeq(int val) { settings.DelaySeq = val; settings_changed(); }
-
- void set_endian(bool val) { settings.BigEndian = val; settings_changed(); }
-
- void set_mod_baud(int val) { settings.pBaudRate = static_cast<QSerialPort::BaudRate>(ui.QCB_Serial_baudRate->itemData(val).toInt()) ; settings_changed(); }
- void set_mod_dataBits(int val) { settings.pDataBits = static_cast<QSerialPort::DataBits>(ui.QCB_Serial_dataBits->itemData(val).toInt()) ; settings_changed(); }
- void set_mod_parity(int val) { settings.pParity = static_cast<QSerialPort::Parity>(ui.QCB_Serial_parity->itemData(val).toInt()) ; settings_changed(); }
- void set_mod_stopBits(int val) { settings.pStopBits = static_cast<QSerialPort::StopBits>(ui.QCB_Serial_stopBits->itemData(val).toInt()); settings_changed(); }
- void set_mod_flowControl(int val) { settings.pFlowControl = static_cast<QSerialPort::FlowControl>(ui.QCB_Serial_flowControl->itemData(val).toInt()) ; settings_changed(); }
-
- void doOK();
+ void doOK();
void doCancel();
void doSave();
void doReset();
@@ -88,8 +45,6 @@ protected slots:
void doSerialInfo();
protected:
- bool settingsDirty;
- void settings_changed();
TrackerSettings settings;
QTimer timer;
};
diff --git a/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.cpp b/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.cpp
deleted file mode 100644
index 0be912f2..00000000
--- a/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.cpp
+++ /dev/null
@@ -1,145 +0,0 @@
-/********************************************************************************
-* 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: http://facetracknoir.sourceforge.net/home/default.htm *
-* *
-* Copyright (C) 2012 FuraX49 (HAT Tracker plugins) *
-* Homepage: http://hatire.sourceforge.net *
-* *
-* 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 <QCoreApplication>
-#include <QSettings>
-#include <QVariant>
-
-#include "ftnoir_tracker_hat_settings.h"
-
-void TrackerSettings::load_ini()
-{
- 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( "HAT" );
-
- SerialPortName=iniFile.value ( "PortName" ).toString();
-
- EnableRoll = iniFile.value( "EnableRoll", 1 ).toBool();
- EnablePitch = iniFile.value( "EnablePitch", 1 ).toBool();
- EnableYaw = iniFile.value( "EnableYaw", 1 ).toBool();
- EnableX = iniFile.value( "EnableX", 0 ).toBool();
- EnableY = iniFile.value( "EnableY", 0 ).toBool();
- EnableZ = iniFile.value( "EnableZ", 0 ).toBool();
-
-
- InvertRoll = iniFile.value( "InvertRoll", 1 ).toBool();
- InvertPitch = iniFile.value( "InvertPitch", 1 ).toBool();
- InvertYaw = iniFile.value( "InvertYaw", 1 ).toBool();
- InvertX = iniFile.value( "InvertX", 0 ).toBool();
- InvertY = iniFile.value( "InvertY", 0 ).toBool();
- InvertZ = iniFile.value( "InvertZ", 0 ).toBool();
-
-
- RollAxe=iniFile.value("RollAxe",1).toInt();
- PitchAxe=iniFile.value("PitchAxe",2).toInt();
- YawAxe=iniFile.value("YawAxe",0).toInt();
- XAxe=iniFile.value("XAxe",1).toInt();
- YAxe=iniFile.value("YAxe",2).toInt();
- ZAxe=iniFile.value("ZAxe",0).toInt();
-
-
- CmdStart=iniFile.value ( "CmdStart").toString();
- CmdStop=iniFile.value ( "CmdStop" ).toString();
- CmdInit=iniFile.value ( "CmdInit" ).toString();
- CmdReset=iniFile.value ( "CmdReset" ).toString();
- CmdCenter=iniFile.value ( "CmdCenter" ).toString();
- CmdZero=iniFile.value ( "CmdZero" ).toString();
-
- DelayInit=iniFile.value("DelayInit",0).toInt();
- DelayStart=iniFile.value("DelayStart",0).toInt();
- DelaySeq=iniFile.value("DelaySeq",0).toInt();
-
- BigEndian=iniFile.value("BigEndian",0).toBool();
-
-
- pBaudRate=static_cast<QSerialPort::BaudRate>(iniFile.value("BaudRate",QSerialPort::Baud115200).toInt());
- pDataBits=static_cast<QSerialPort::DataBits>(iniFile.value("DataBits",QSerialPort::Data8).toInt());
- pParity=static_cast<QSerialPort::Parity>(iniFile.value("Parity",QSerialPort::NoParity).toInt());
- pStopBits=static_cast<QSerialPort::StopBits>(iniFile.value("StopBits",QSerialPort::OneStop).toInt());
- pFlowControl=static_cast<QSerialPort::FlowControl>(iniFile.value("FlowControl",QSerialPort::HardwareControl).toInt());
-
- iniFile.endGroup();
-}
-
-
-void TrackerSettings::save_ini() const
-{
-
- 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 ( "HAT" );
-
- iniFile.setValue ( "PortName",SerialPortName );
-
- iniFile.setValue( "EnableRoll", EnableRoll );
- iniFile.setValue( "EnablePitch", EnablePitch );
- iniFile.setValue( "EnableYaw", EnableYaw );
- iniFile.setValue( "EnableX", EnableX );
- iniFile.setValue( "EnableY", EnableY );
- iniFile.setValue( "EnableZ", EnableZ );
-
- iniFile.setValue( "InvertRoll", InvertRoll );
- iniFile.setValue( "InvertPitch", InvertPitch );
- iniFile.setValue( "InvertYaw", InvertYaw );
- iniFile.setValue( "InvertX", InvertX );
- iniFile.setValue( "InvertY", InvertY );
- iniFile.setValue( "InvertZ", InvertZ );
-
- iniFile.setValue ( "RollAxe", RollAxe );
- iniFile.setValue ( "PitchAxe", PitchAxe );
- iniFile.setValue ( "YawAxe",YawAxe );
- iniFile.setValue ( "XAxe", XAxe );
- iniFile.setValue ( "YAxe", YAxe );
- iniFile.setValue ( "ZAxe", ZAxe );
-
- iniFile.setValue ( "CmdStart",CmdStart.toLatin1());
- iniFile.setValue ( "CmdStop",CmdStop.toLatin1());
- iniFile.setValue ( "CmdInit",CmdInit.toLatin1());
- iniFile.setValue ( "CmdReset",CmdReset.toLatin1());
- iniFile.setValue ( "CmdCenter",CmdCenter.toLatin1() );
- iniFile.setValue ( "CmdZero",CmdZero.toLatin1() );
-
- iniFile.setValue ( "DelayInit",DelayInit);
- iniFile.setValue ( "DelayStart",DelayStart);
- iniFile.setValue ( "DelaySeq",DelaySeq);
-
- iniFile.setValue("BigEndian",BigEndian);
-
- iniFile.setValue("BaudRate",pBaudRate);
- iniFile.setValue("DataBits",pDataBits);
- iniFile.setValue("Parity",pParity);
- iniFile.setValue("StopBits",pStopBits);
- iniFile.setValue("FlowControl",pFlowControl);
-
-
- iniFile.endGroup();
-}
-
diff --git a/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.h b/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.h
index 2e84bde8..8739394f 100644
--- a/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.h
+++ b/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.h
@@ -5,61 +5,81 @@
* copyright notice and this permission notice appear in all copies.
*/
-#ifndef FTNOIR_TRACKER_HAT_SETTINGS_H
-#define FTNOIR_TRACKER_HAT_SETTINGS_H
+#pragma once
#include <QtSerialPort/QSerialPort>
+#include "facetracknoir/options.hpp"
+#include <ftnoir_tracker_base/ftnoir_tracker_types.h>
+using namespace options;
-//-----------------------------------------------------------------------------
struct TrackerSettings
{
-
- void load_ini();
- void save_ini() const;
-
- bool EnableRoll;
- bool EnablePitch;
- bool EnableYaw;
- bool EnableX;
- bool EnableY;
- bool EnableZ;
-
- bool InvertRoll;
- bool InvertPitch;
- bool InvertYaw;
- bool InvertX;
- bool InvertY;
- bool InvertZ;
-
-
- int RollAxe;
- int PitchAxe;
- int YawAxe;
- int XAxe;
- int YAxe;
- int ZAxe;
-
- QString CmdStart;
- QString CmdStop;
- QString CmdInit;
- QString CmdReset;
- QString CmdCenter;
- QString CmdZero;
-
- int DelayInit;
- int DelayStart;
- int DelaySeq;
-
- bool BigEndian;
-
- QString SerialPortName;
- QSerialPort::BaudRate pBaudRate;
- QSerialPort::DataBits pDataBits;
- QSerialPort::Parity pParity;
- QSerialPort::StopBits pStopBits;
- QSerialPort::FlowControl pFlowControl;
-
+ pbundle b;
+ value<bool> EnableRoll,
+ EnablePitch,
+ EnableYaw,
+ EnableX,
+ EnableY,
+ EnableZ,
+ InvertRoll,
+ InvertPitch,
+ InvertYaw,
+ InvertX,
+ InvertY,
+ InvertZ;
+ value<int> RollAxe,
+ PitchAxe,
+ YawAxe,
+ XAxe,
+ YAxe,
+ ZAxe;
+ value<bool> BigEndian;
+ value<QString> CmdStart,
+ CmdStop,
+ CmdInit,
+ CmdReset,
+ CmdCenter,
+ CmdZero;
+ value<int> SerialPortName, DelayInit, DelayStart, DelaySeq;
+ // unfortunately, no way to distinguish this and enum type
+ // hence, string type used -sh
+ value<int> pBaudRate, pDataBits, pParity, pStopBits, pFlowControl;
+ TrackerSettings() :
+ b(bundle("HAT")),
+ EnableRoll(b, "EnableRoll", true),
+ EnablePitch(b, "EnablePitch", true),
+ EnableYaw(b, "EnableYaw", true),
+ EnableX(b, "EnableX", true),
+ EnableY(b, "EnableY", true),
+ EnableZ(b, "EnableZ", true),
+ InvertRoll(b, "InvertRoll", false),
+ InvertPitch(b, "InvertPitch", false),
+ InvertYaw(b, "InvertYaw", false),
+ InvertX(b, "InvertX", false),
+ InvertY(b, "InvertY", false),
+ InvertZ(b, "InvertZ", false),
+ RollAxe(b, "RollAe", 2),
+ PitchAxe(b, "PitchAxe", 1),
+ YawAxe(b, "YawAxe", 0),
+ XAxe(b, "XAxe", 0),
+ YAxe(b, "YAxe", 1),
+ ZAxe(b, "ZAxe", 2),
+ BigEndian(b, "BigEndian", false),
+ CmdStart(b, "CmdStart", ""),
+ CmdStop(b, "CmdStop", ""),
+ CmdInit(b, "CmdInit", ""),
+ CmdReset(b, "CmdReset", ""),
+ CmdCenter(b, "CmdCenter", ""),
+ CmdZero(b, "CmdZero", ""),
+ SerialPortName(b, "PortName", 0),
+ DelayInit(b, "DelayInit", 0),
+ DelayStart(b, "DelayStart", 0),
+ DelaySeq(b, "DelaySeq", 0),
+ pBaudRate(b, "BaudRate", 0),
+ pDataBits(b, "DataBits", 0),
+ pParity(b, "Parity", 0),
+ pStopBits(b, "StopBits", 0),
+ pFlowControl(b, "FlowControl", 0)
+ {
+ }
};
-
-
-#endif //FTNOIR_TRACKER_HAT_SETTINGS_H \ No newline at end of file