diff options
Diffstat (limited to 'tracker-hatire')
-rw-r--r-- | tracker-hatire/CMakeLists.txt | 7 | ||||
-rw-r--r-- | tracker-hatire/ftnoir_hatcontrols.ui | 118 | ||||
-rw-r--r-- | tracker-hatire/ftnoir_tracker_hat.cpp | 45 | ||||
-rw-r--r-- | tracker-hatire/ftnoir_tracker_hat.h | 23 | ||||
-rw-r--r-- | tracker-hatire/ftnoir_tracker_hat_dialog.cpp | 14 | ||||
-rw-r--r-- | tracker-hatire/ftnoir_tracker_hat_dialog.h | 4 | ||||
-rw-r--r-- | tracker-hatire/ftnoir_tracker_hat_settings.h | 4 | ||||
-rw-r--r-- | tracker-hatire/lang/nl_NL.ts | 19 | ||||
-rw-r--r-- | tracker-hatire/lang/ru_RU.ts | 19 | ||||
-rw-r--r-- | tracker-hatire/lang/stub.ts | 19 | ||||
-rw-r--r-- | tracker-hatire/lang/zh_CN.ts | 21 | ||||
-rw-r--r-- | tracker-hatire/thread.cpp | 50 | ||||
-rw-r--r-- | tracker-hatire/thread.hpp | 9 |
13 files changed, 170 insertions, 182 deletions
diff --git a/tracker-hatire/CMakeLists.txt b/tracker-hatire/CMakeLists.txt index 39431724..01dd52b9 100644 --- a/tracker-hatire/CMakeLists.txt +++ b/tracker-hatire/CMakeLists.txt @@ -1,5 +1,8 @@ if(Qt5SerialPort_FOUND) otr_module(tracker-hatire) - target_link_libraries(opentrack-tracker-hatire ${Qt5SerialPort_LIBRARIES}) - target_include_directories(opentrack-tracker-hatire SYSTEM PUBLIC ${Qt5SerialPort_INCLUDE_DIRS}) + target_link_libraries(${self} ${Qt5SerialPort_LIBRARIES}) + target_include_directories(${self} SYSTEM PUBLIC ${Qt5SerialPort_INCLUDE_DIRS}) + if (WIN32 OR APPLE) + otr_install_lib(Qt5::SerialPort .) + endif() endif() diff --git a/tracker-hatire/ftnoir_hatcontrols.ui b/tracker-hatire/ftnoir_hatcontrols.ui index c9a449b1..758d8e51 100644 --- a/tracker-hatire/ftnoir_hatcontrols.ui +++ b/tracker-hatire/ftnoir_hatcontrols.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>389</width> - <height>528</height> + <height>497</height> </rect> </property> <property name="minimumSize"> @@ -103,7 +103,7 @@ <bool>false</bool> </property> <property name="sizeAdjustPolicy"> - <enum>QComboBox::AdjustToMinimumContentsLength</enum> + <enum>QComboBox::AdjustToContents</enum> </property> <property name="modelColumn"> <number>0</number> @@ -129,38 +129,6 @@ </property> </widget> </item> - <item row="1" column="1"> - <widget class="QCheckBox" name="serial_bug_workaround"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> - <horstretch>6</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Buggy serial port uses too much CPU</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_6"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>3</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="maximumSize"> - <size> - <width>65536</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Workaround</string> - </property> - </widget> - </item> </layout> </widget> </item> @@ -1168,16 +1136,6 @@ p, li { white-space: pre-wrap; } <string>Serial Parameters</string> </property> <layout class="QGridLayout" name="gridLayout_8"> - <item row="0" column="1"> - <widget class="QComboBox" name="QCB_Serial_baudRate"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - </widget> - </item> <item row="3" column="1"> <widget class="QComboBox" name="QCB_Serial_stopBits"> <property name="sizePolicy"> @@ -1195,6 +1153,13 @@ p, li { white-space: pre-wrap; } </property> </widget> </item> + <item row="0" column="0"> + <widget class="QLabel" name="baudRateLabel"> + <property name="text"> + <string>BaudRate:</string> + </property> + </widget> + </item> <item row="2" column="1"> <widget class="QComboBox" name="QCB_Serial_parity"> <property name="sizePolicy"> @@ -1205,13 +1170,10 @@ p, li { white-space: pre-wrap; } </property> </widget> </item> - <item row="4" column="1"> - <widget class="QComboBox" name="QCB_Serial_flowControl"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> + <item row="1" column="0"> + <widget class="QLabel" name="dataBitsLabel"> + <property name="text"> + <string>Data bits</string> </property> </widget> </item> @@ -1222,6 +1184,16 @@ p, li { white-space: pre-wrap; } </property> </widget> </item> + <item row="0" column="1"> + <widget class="QComboBox" name="QCB_Serial_baudRate"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> <item row="2" column="0"> <widget class="QLabel" name="parityLabel"> <property name="text"> @@ -1229,15 +1201,18 @@ p, li { white-space: pre-wrap; } </property> </widget> </item> - <item row="0" column="0"> - <widget class="QLabel" name="baudRateLabel"> - <property name="text"> - <string>BaudRate:</string> + <item row="1" column="1"> + <widget class="QComboBox" name="QCB_Serial_dataBits"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> </property> </widget> </item> - <item row="1" column="1"> - <widget class="QComboBox" name="QCB_Serial_dataBits"> + <item row="4" column="1"> + <widget class="QComboBox" name="QCB_Serial_flowControl"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <horstretch>0</horstretch> @@ -1246,10 +1221,23 @@ p, li { white-space: pre-wrap; } </property> </widget> </item> - <item row="1" column="0"> - <widget class="QLabel" name="dataBitsLabel"> + <item row="5" column="0"> + <widget class="QLabel" name="label_6"> <property name="text"> - <string>Data bits</string> + <string>DTR</string> + </property> + </widget> + </item> + <item row="5" column="1"> + <widget class="QCheckBox" name="QCB_Serial_dtr"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> </property> </widget> </item> @@ -1403,6 +1391,7 @@ p, li { white-space: pre-wrap; } </layout> </widget> <tabstops> + <tabstop>tabWidget</tabstop> <tabstop>cbSerialPort</tabstop> <tabstop>btnZero</tabstop> <tabstop>btnReset</tabstop> @@ -1425,24 +1414,27 @@ p, li { white-space: pre-wrap; } <tabstop>cb_z</tabstop> <tabstop>chkInvertZ</tabstop> <tabstop>le_cmd_init</tabstop> + <tabstop>spb_BeforeInit</tabstop> <tabstop>le_cmd_start</tabstop> + <tabstop>spb_BeforeStart</tabstop> <tabstop>spb_AfterStart</tabstop> <tabstop>le_cmd_stop</tabstop> <tabstop>le_cmd_center</tabstop> <tabstop>le_cmd_zero</tabstop> - <tabstop>le_cmd_reset</tabstop> <tabstop>spb_Fps</tabstop> + <tabstop>le_cmd_reset</tabstop> <tabstop>cb_Endian</tabstop> <tabstop>QCB_Serial_baudRate</tabstop> <tabstop>QCB_Serial_dataBits</tabstop> <tabstop>QCB_Serial_parity</tabstop> <tabstop>QCB_Serial_stopBits</tabstop> <tabstop>QCB_Serial_flowControl</tabstop> + <tabstop>QCB_Serial_dtr</tabstop> + <tabstop>btn_icone</tabstop> + <tabstop>chkEnableLogging</tabstop> <tabstop>lineSend</tabstop> <tabstop>btnSend</tabstop> <tabstop>pteINFO</tabstop> - <tabstop>tabWidget</tabstop> - <tabstop>btn_icone</tabstop> </tabstops> <resources> <include location="ftnoir_hat.qrc"/> diff --git a/tracker-hatire/ftnoir_tracker_hat.cpp b/tracker-hatire/ftnoir_tracker_hat.cpp index 9ac44cf2..9948c30e 100644 --- a/tracker-hatire/ftnoir_tracker_hat.cpp +++ b/tracker-hatire/ftnoir_tracker_hat.cpp @@ -15,23 +15,15 @@ hatire::hatire() { - HAT.Rot[0]=0; - HAT.Rot[1]=0; - HAT.Rot[2]=0; - HAT.Trans[0]=0; - HAT.Trans[1]=0; - HAT.Trans[2]=0; - - Begin.append((unsigned char) 0xAA); - Begin.append((unsigned char) 0xAA); - End.append((unsigned char) 0x55); - End.append((unsigned char) 0x55); -} -hatire::~hatire() -{ + Begin.append((unsigned char) 0xAA); + Begin.append((unsigned char) 0xAA); + End.append((unsigned char) 0x55); + End.append((unsigned char) 0x55); } +hatire::~hatire() = default; + //send RESET to Arduino void hatire::reset() { @@ -130,29 +122,26 @@ void hatire::data(double *data) } for (unsigned k = 0; k < 3; k++) - HAT.Rot[k] = clamp(HAT.Rot[k], -180, 180); + HAT.Rot[k] = std::clamp(HAT.Rot[k], -180.f, 180.f); const struct { + double& place; + float input; bool enable; bool sign; - float input; - double& place; } spec[] = { - { s.EnableX, s.InvertX, HAT.Trans[s.XAxis], data[TX] }, - { s.EnableY, s.InvertY, HAT.Trans[s.YAxis], data[TY] }, - { s.EnableZ, s.InvertZ, HAT.Trans[s.ZAxis], data[TZ] }, - { s.EnableYaw, s.InvertYaw, HAT.Rot[s.YawAxis], data[Yaw] }, - { s.EnablePitch, s.InvertPitch, HAT.Rot[s.PitchAxis], data[Pitch] }, - { s.EnableRoll, s.InvertRoll, HAT.Rot[s.RollAxis], data[Roll] }, + { data[TX], HAT.Trans[s.XAxis], s.EnableX, s.InvertX, }, + { data[TY], HAT.Trans[s.YAxis], s.EnableY, s.InvertY, }, + { data[TZ], HAT.Trans[s.ZAxis], s.EnableZ, s.InvertZ, }, + { data[Yaw], HAT.Rot[s.YawAxis], s.EnableYaw, s.InvertYaw }, + { data[Pitch], HAT.Rot[s.PitchAxis], s.EnablePitch, s.InvertPitch }, + { data[Roll], HAT.Rot[s.RollAxis], s.EnableRoll, s.InvertRoll }, }; - for (unsigned i = 0; i < std::size(spec); i++) - { - auto& k = spec[i]; - k.place = (k.sign ? -1 : 1) * (k.enable ? k.input : 0); - } + for (auto& k : spec) + k.place = (k.sign ? -1 : 1) * (k.enable ? (double)k.input : 0); } #include "ftnoir_tracker_hat_dialog.h" diff --git a/tracker-hatire/ftnoir_tracker_hat.h b/tracker-hatire/ftnoir_tracker_hat.h index 0f4b2c9c..16e39c7d 100644 --- a/tracker-hatire/ftnoir_tracker_hat.h +++ b/tracker-hatire/ftnoir_tracker_hat.h @@ -20,34 +20,35 @@ class hatire : public QObject, public ITracker public: hatire(); - ~hatire(); + ~hatire() override; - module_status start_tracker(QFrame*); - void data(double *data); + module_status start_tracker(QFrame*) override; + void data(double *data) override; //void center(); //bool notifyZeroed(); void reset(); - void get_info( int *tps ); + void get_info(int *tps); void serial_info(); void send_serial_command(const QByteArray& x); hatire_thread t; + private: - TArduinoData ArduinoData, HAT; + TArduinoData ArduinoData {}, HAT {}; QByteArray Begin; QByteArray End; TrackerSettings s; - int frame_cnt; - - std::atomic<int> CptError; + int frame_cnt = 0; - static inline QByteArray to_latin1(const QString& str) { return str.toLatin1(); } + std::atomic<int> CptError { 0 }; }; class hatire_metadata : public Metadata { - QString name() { return otr_tr("Hatire Arduino"); } - QIcon icon() { return QIcon(":/images/hat.png"); } + Q_OBJECT + + QString name() override { return tr("Hatire Arduino"); } + QIcon icon() override { return QIcon(":/images/hat.png"); } }; diff --git a/tracker-hatire/ftnoir_tracker_hat_dialog.cpp b/tracker-hatire/ftnoir_tracker_hat_dialog.cpp index 6fb17361..7cede5ca 100644 --- a/tracker-hatire/ftnoir_tracker_hat_dialog.cpp +++ b/tracker-hatire/ftnoir_tracker_hat_dialog.cpp @@ -32,6 +32,10 @@ dialog_hatire::dialog_hatire() : theTracker(nullptr), timer(this) 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->addItem(QLatin1String("230400"),(QSerialPort::BaudRate)230400); + ui.QCB_Serial_baudRate->addItem(QLatin1String("250000"),(QSerialPort::BaudRate)250000); + ui.QCB_Serial_baudRate->addItem(QLatin1String("500000"),(QSerialPort::BaudRate)500000); + ui.QCB_Serial_baudRate->addItem(QLatin1String("1000000"),(QSerialPort::BaudRate)1000000); ui.QCB_Serial_dataBits->clear(); ui.QCB_Serial_dataBits->addItem(QLatin1String("5"), QSerialPort::Data5); @@ -91,6 +95,7 @@ dialog_hatire::dialog_hatire() : theTracker(nullptr), timer(this) tie_setting(s.DelaySeq, ui.spb_AfterStart); tie_setting(s.BigEndian, ui.cb_Endian); + tie_setting(s.pDTR, ui.QCB_Serial_dtr); tie_setting(s.pBaudRate, ui.QCB_Serial_baudRate); tie_setting(s.pDataBits, ui.QCB_Serial_dataBits); @@ -98,8 +103,6 @@ dialog_hatire::dialog_hatire() : theTracker(nullptr), timer(this) tie_setting(s.pParity, ui.QCB_Serial_parity); tie_setting(s.pStopBits, ui.QCB_Serial_stopBits); - tie_setting(s.serial_bug_workaround, ui.serial_bug_workaround); - tie_setting(s.QSerialPortName, ui.cbSerialPort); connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); @@ -118,8 +121,7 @@ dialog_hatire::dialog_hatire() : theTracker(nullptr), timer(this) //connect(ui.lineSend,SIGNAL(keyPressEvent),this,SLOT(on_lineSend_returnPressed()) ); } -dialog_hatire::~dialog_hatire() { -} +dialog_hatire::~dialog_hatire() = default; void dialog_hatire::Initialize(QWidget *parent) { @@ -180,8 +182,8 @@ void dialog_hatire::poll_tracker_info() int frame_cnt; theTracker->get_info(&frame_cnt); - ui.lab_vtps->setText(QString::number(frame_cnt*(1000/last_time.elapsed()))); - last_time.restart(); + ui.lab_vtps->setText(QString::number(frame_cnt*(1000/last_time.elapsed_ms()))); + last_time.start(); } } diff --git a/tracker-hatire/ftnoir_tracker_hat_dialog.h b/tracker-hatire/ftnoir_tracker_hat_dialog.h index 7577445c..c578f22f 100644 --- a/tracker-hatire/ftnoir_tracker_hat_dialog.h +++ b/tracker-hatire/ftnoir_tracker_hat_dialog.h @@ -1,12 +1,12 @@ #pragma once #include "api/plugin-api.hpp" +#include "compat/timer.hpp" #include "ftnoir_tracker_hat_settings.h" #include "ftnoir_tracker_hat.h" #include "ui_ftnoir_hatcontrols.h" #include <QObject> #include <QWidget> -#include <QTime> #include <QTimer> #include <QMessageBox> #include <QMetaType> @@ -25,7 +25,7 @@ public: private: Ui::UIHATControls ui; hatire *theTracker; - QTime last_time; + Timer last_time; public slots: void WriteMsgInfo(const QByteArray &MsgInfo); diff --git a/tracker-hatire/ftnoir_tracker_hat_settings.h b/tracker-hatire/ftnoir_tracker_hat_settings.h index 7e9f7244..b17042c7 100644 --- a/tracker-hatire/ftnoir_tracker_hat_settings.h +++ b/tracker-hatire/ftnoir_tracker_hat_settings.h @@ -22,7 +22,7 @@ struct TrackerSettings : opts value<int> DelayInit, DelayStart, DelaySeq; - value<bool> BigEndian, EnableLogging, serial_bug_workaround; + value<bool> BigEndian, EnableLogging, pDTR; value<QString> QSerialPortName; @@ -63,7 +63,7 @@ struct TrackerSettings : opts DelaySeq(b, "after-start-delay", 0), BigEndian(b, "is-big-endian", false), EnableLogging(b, "enable-logging", false), - serial_bug_workaround(b, "serial-bug-workaround", false), + pDTR(b, "data-terminal-ready", false), QSerialPortName(b, "serial-port-name", ""), pBaudRate(b, "baud-rate", QSerialPort::Baud115200), pDataBits(b, "data-bits", QSerialPort::Data8), diff --git a/tracker-hatire/lang/nl_NL.ts b/tracker-hatire/lang/nl_NL.ts index 616e4f9b..af8cbd2c 100644 --- a/tracker-hatire/lang/nl_NL.ts +++ b/tracker-hatire/lang/nl_NL.ts @@ -16,14 +16,6 @@ <translation type="unfinished"></translation> </message> <message> - <source>Buggy serial port uses too much CPU</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Workaround</source> - <translation type="unfinished"></translation> - </message> - <message> <source>Zero</source> <translation type="unfinished"></translation> </message> @@ -277,6 +269,10 @@ p, li { white-space: pre-wrap; } <source>Enable logging to diagnostic file</source> <translation type="unfinished"></translation> </message> + <message> + <source>DTR</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>dialog_hatire</name> @@ -305,6 +301,13 @@ p, li { white-space: pre-wrap; } </message> </context> <context> + <name>hatire_metadata</name> + <message> + <source>Hatire Arduino</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> <name>hatire_thread</name> <message> <source>Timeout during writing command</source> diff --git a/tracker-hatire/lang/ru_RU.ts b/tracker-hatire/lang/ru_RU.ts index c27a8615..16052702 100644 --- a/tracker-hatire/lang/ru_RU.ts +++ b/tracker-hatire/lang/ru_RU.ts @@ -16,14 +16,6 @@ <translation type="unfinished"></translation> </message> <message> - <source>Buggy serial port uses too much CPU</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Workaround</source> - <translation type="unfinished"></translation> - </message> - <message> <source>Zero</source> <translation type="unfinished"></translation> </message> @@ -277,6 +269,10 @@ p, li { white-space: pre-wrap; } <source>Enable logging to diagnostic file</source> <translation type="unfinished"></translation> </message> + <message> + <source>DTR</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>dialog_hatire</name> @@ -305,6 +301,13 @@ p, li { white-space: pre-wrap; } </message> </context> <context> + <name>hatire_metadata</name> + <message> + <source>Hatire Arduino</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> <name>hatire_thread</name> <message> <source>Timeout during writing command</source> diff --git a/tracker-hatire/lang/stub.ts b/tracker-hatire/lang/stub.ts index 5ccf7fe1..90c8e616 100644 --- a/tracker-hatire/lang/stub.ts +++ b/tracker-hatire/lang/stub.ts @@ -16,14 +16,6 @@ <translation type="unfinished"></translation> </message> <message> - <source>Buggy serial port uses too much CPU</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Workaround</source> - <translation type="unfinished"></translation> - </message> - <message> <source>Zero</source> <translation type="unfinished"></translation> </message> @@ -277,6 +269,10 @@ p, li { white-space: pre-wrap; } <source>Enable logging to diagnostic file</source> <translation type="unfinished"></translation> </message> + <message> + <source>DTR</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>dialog_hatire</name> @@ -305,6 +301,13 @@ p, li { white-space: pre-wrap; } </message> </context> <context> + <name>hatire_metadata</name> + <message> + <source>Hatire Arduino</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> <name>hatire_thread</name> <message> <source>Timeout during writing command</source> diff --git a/tracker-hatire/lang/zh_CN.ts b/tracker-hatire/lang/zh_CN.ts index 5ccf7fe1..d80cfa28 100644 --- a/tracker-hatire/lang/zh_CN.ts +++ b/tracker-hatire/lang/zh_CN.ts @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> -<TS version="2.1"> +<TS version="2.1" language="zh_CN"> <context> <name>UIHATControls</name> <message> @@ -16,14 +16,6 @@ <translation type="unfinished"></translation> </message> <message> - <source>Buggy serial port uses too much CPU</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Workaround</source> - <translation type="unfinished"></translation> - </message> - <message> <source>Zero</source> <translation type="unfinished"></translation> </message> @@ -277,6 +269,10 @@ p, li { white-space: pre-wrap; } <source>Enable logging to diagnostic file</source> <translation type="unfinished"></translation> </message> + <message> + <source>DTR</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>dialog_hatire</name> @@ -305,6 +301,13 @@ p, li { white-space: pre-wrap; } </message> </context> <context> + <name>hatire_metadata</name> + <message> + <source>Hatire Arduino</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> <name>hatire_thread</name> <message> <source>Timeout during writing command</source> diff --git a/tracker-hatire/thread.cpp b/tracker-hatire/thread.cpp index 6025d74c..7d61a90a 100644 --- a/tracker-hatire/thread.cpp +++ b/tracker-hatire/thread.cpp @@ -1,13 +1,15 @@ #include "thread.hpp" -#include "compat/sleep.hpp" #include "compat/base-path.hpp" +#include "compat/sleep.hpp" + #include <utility> +#include <cstring> #include <QTextStream> #include <QTime> -#include <QDebug> +#include <QByteArray> -#include <cstring> +#include <QDebug> void hatire_thread::sendcmd_impl(const QByteArray &cmd) { @@ -25,7 +27,7 @@ void hatire_thread::sendcmd_impl(const QByteArray &cmd) Log(logMess); com_port.write(cmd); if (!com_port.waitForBytesWritten(1000)) { - emit serial_debug_info_str(tr("Timeout during writing command")); + serial_debug_info_str(tr("Timeout during writing command")); } else { Msg.append("\r\n"); @@ -43,7 +45,7 @@ void hatire_thread::sendcmd_impl(const QByteArray &cmd) emit serial_debug_info(Msg); #endif } else { - emit serial_debug_info_str(tr("COM port not open")); + serial_debug_info_str(tr("COM port not open")); } } #endif @@ -69,7 +71,7 @@ void hatire_thread::Log(const QString& message) { QTextStream out(&flDiagnostics); QString milliSeconds; - milliSeconds = QString("%1").arg(QTime::currentTime().msec(), 3, 10, QChar('0')); + milliSeconds = QStringLiteral("%1").arg(QTime::currentTime().msec(), 3, 10, QChar('0')); // We have a file out << QTime::currentTime().toString() << "." << milliSeconds << ": " << message << "\r\n"; flDiagnostics.close(); @@ -109,7 +111,7 @@ void hatire_thread::teardown_serial() { QByteArray msg; Log("Tracker shut down"); - com_port.write(to_latin1(s.CmdStop)); + com_port.write(s.CmdStop->toUtf8()); if (!com_port.waitForBytesWritten(1000)) { emit serial_debug_info("TimeOut in writing CMD"); @@ -118,12 +120,13 @@ void hatire_thread::teardown_serial() { msg.append("\r\n"); msg.append("SEND '"); - msg.append(s.CmdStop); + msg.append(s.CmdStop->toUtf8()); msg.append("'\r\n"); } emit serial_debug_info(msg); - disconnect(&com_port, SIGNAL(readyRead()), nullptr, nullptr); + // XXX does this make any sense? -sh 20180703 + //disconnect(&com_port, SIGNAL(readyRead()), nullptr, nullptr); com_port.close(); } } @@ -146,7 +149,7 @@ void hatire_thread::run() void hatire_thread::serial_debug_info_str(const QString& str) { - serial_debug_info(str.toUtf8()); + emit serial_debug_info(str.toLatin1()); } serial_result hatire_thread::init_serial_port_impl() @@ -165,8 +168,8 @@ serial_result hatire_thread::init_serial_port_impl() && com_port.setParity((QSerialPort::Parity)s.pParity) && com_port.setStopBits((QSerialPort::StopBits)s.pStopBits) && com_port.setFlowControl((QSerialPort::FlowControl)s.pFlowControl) + && com_port.setDataTerminalReady(s.pDTR) && com_port.clear(QSerialPort::AllDirections) - && com_port.setDataErrorPolicy(QSerialPort::IgnorePolicy) ) { Log(tr("Port Parameters set")); @@ -198,7 +201,7 @@ serial_result hatire_thread::init_serial_port_impl() } Log(tr("Waiting on init")); qDebug() << QTime::currentTime() << " HAT send INIT "; - sendcmd_str(s.CmdInit); + emit sendcmd_str(s.CmdInit); // Wait init MPU sequence for (int i = 1; i <= s.DelayStart; i+=50) { @@ -206,7 +209,7 @@ serial_result hatire_thread::init_serial_port_impl() } // Send START cmd to IMU qDebug() << QTime::currentTime() << " HAT send START "; - sendcmd_str(s.CmdStart); + emit sendcmd_str(s.CmdStart); // Wait start MPU sequence for (int i = 1; i <=s.DelaySeq; i+=50) @@ -239,13 +242,13 @@ void hatire_thread::serial_info_impl() if (com_port.isOpen()) { msg.append("\r\n"); - msg.append(com_port.portName()); + msg.append(com_port.portName().toUtf8()); msg.append("\r\n"); msg.append("BAUDRATE :"); - msg.append(QString::number(com_port.baudRate())); + msg.append(QString::number(com_port.baudRate()).toLatin1()); msg.append("\r\n"); msg.append("DataBits :"); - msg.append(QString::number(com_port.dataBits())); + msg.append(QString::number(com_port.dataBits()).toLatin1()); msg.append("\r\n"); msg.append("Parity :"); @@ -301,13 +304,10 @@ void hatire_thread::serial_info_impl() void hatire_thread::on_serial_read() { - const int sz = com_port.read(buf, sizeof(buf)); + const int sz = (int)com_port.read(buf, sizeof(buf)); if (sz > 0) { - stat.input(timer.elapsed_ms()); - timer.start(); - QMutexLocker lck(&data_mtx); data_read.append(buf, sz); } @@ -319,20 +319,16 @@ void hatire_thread::on_serial_read() } #endif - if (s.serial_bug_workaround || sz <= 0) + if (sz <= 0) { // qt can fire QSerialPort::readyRead() needlessly, causing a busy loop. // see https://github.com/opentrack/opentrack/issues/327#issuecomment-207941003 + + // this probably happens with flaky BT/usb-to-serial converters (?) constexpr int hz = 90; constexpr int ms = 1000/hz; portable::sleep(ms); } - - if (throttle_timer.elapsed_ms() >= 3000) - { - throttle_timer.start(); - qDebug() << "stat:" << "avg" << stat.avg() << "stddev" << stat.stddev(); - } } QByteArray& hatire_thread::send_data_read_nolock() diff --git a/tracker-hatire/thread.hpp b/tracker-hatire/thread.hpp index 93c50c9e..f6bd8d49 100644 --- a/tracker-hatire/thread.hpp +++ b/tracker-hatire/thread.hpp @@ -4,16 +4,12 @@ #include "ftnoir_tracker_hat_settings.h" #include <QSerialPort> -#include <QByteArray> #include <QThread> #include <QMutex> #include <QFile> #include <QCoreApplication> -#include "compat/variance.hpp" -#include "compat/timer.hpp" - enum results { result_ok, @@ -34,7 +30,7 @@ struct serial_result serial_result(results code, const QString& error) : error(error), code(code) {} QString error; - results code; + results code { result_error }; }; class hatire_thread : public QThread @@ -51,12 +47,9 @@ class hatire_thread : public QThread QByteArray data_read; serial_t com_port; TrackerSettings s; - variance stat; - Timer timer, throttle_timer; char buf[1024]; void run() override; - static inline QByteArray to_latin1(const QString& str) { return str.toLatin1(); } void serial_debug_info_str(const QString& str); |