diff options
Diffstat (limited to 'ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.cpp')
-rw-r--r-- | ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.cpp | 198 |
1 files changed, 64 insertions, 134 deletions
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 |