#pragma once #include "ftnoir_tracker_hat_settings.h" #include #include #include #include #include #include #include "opentrack/variance.hpp" #include "opentrack-compat/timer.hpp" enum results { result_ok, result_open_error, result_error, }; //#define HATIRE_DEBUG_LOGFILE "d:/putty-hatire.log" #ifdef HATIRE_DEBUG_LOGFILE # include # include #endif #ifdef __GNUC__ # define unused(t, i) t __attribute__((unused)) i #else # define unused(t, i) t i #endif struct serial_result { serial_result() : code(result_ok) {} serial_result(results code, const QString& error) : error(error), code(code) {} QString error; results code; }; struct Diag : public QFile { Diag() { setFileName(QCoreApplication::applicationDirPath() + "/HATDiagnostics.txt"); } }; class hatire_thread : public QThread { Q_OBJECT #ifdef HATIRE_DEBUG_LOGFILE using serial_t = QFile; QTimer read_timer; #else using serial_t = QSerialPort; #endif QByteArray data_read; serial_t com_port; TrackerSettings s; variance stat; Timer timer, throttle_timer; void run() override; static inline QByteArray to_latin1(const QString& str) { return str.toLatin1(); } private slots: void on_serial_read(); void teardown_serial(); void sendcmd_impl(unused(const QByteArray, &cmd)); void sendcmd_str_impl(const QString& str) { sendcmd(str.toLatin1()); } void serial_info_impl(); serial_result init_serial_port_impl(); signals: void serial_debug_info(const QByteArray &MsgInfo); void sendcmd(const QByteArray& cmd); void sendcmd_str(const QString& cmd); void serial_info(); serial_result init_serial_port(); public: void start(); ~hatire_thread() override; hatire_thread(); QByteArray& send_data_read_nolock(); void Log(const QString& message); QMutex data_mtx; };