diff options
Diffstat (limited to 'tracker-hatire')
-rwxr-xr-x | tracker-hatire/thread.cpp | 15 | ||||
-rwxr-xr-x | tracker-hatire/thread.hpp | 5 |
2 files changed, 17 insertions, 3 deletions
diff --git a/tracker-hatire/thread.cpp b/tracker-hatire/thread.cpp index ace4198c..e0bd445f 100755 --- a/tracker-hatire/thread.cpp +++ b/tracker-hatire/thread.cpp @@ -294,9 +294,6 @@ void hatire_thread::serial_info_impl() void hatire_thread::on_serial_read() { - constexpr int hz = 90; - constexpr int ms = 1000/hz; - { QMutexLocker lck(&data_mtx); #ifndef HATIRE_DEBUG_LOGFILE @@ -311,8 +308,20 @@ void hatire_thread::on_serial_read() } #endif } + + stat.input(timer.elapsed_ms()); + timer.start(); + + if (throttle_timer.elapsed_ms() >= 1000) + { + throttle_timer.start(); + qDebug() << "stat:" << "avg" << stat.avg() << "stddev" << stat.stddev(); + } + // qt can fire QSerialPort::readyRead() needlessly, causing a busy loop. // see https://github.com/opentrack/opentrack/issues/327#issuecomment-207941003 + constexpr int hz = 90; + constexpr int ms = 1000/hz; portable::sleep(ms); } diff --git a/tracker-hatire/thread.hpp b/tracker-hatire/thread.hpp index f36d114e..44866e51 100755 --- a/tracker-hatire/thread.hpp +++ b/tracker-hatire/thread.hpp @@ -8,6 +8,9 @@ #include <QFile> #include <QCoreApplication> +#include "opentrack/variance.hpp" +#include "opentrack-compat/timer.hpp" + enum results { result_ok, @@ -100,6 +103,8 @@ class hatire_thread : public QThread QByteArray data_read; serial_t com_port; thread_settings s; + variance stat; + Timer timer, throttle_timer; void run() override; |