summaryrefslogtreecommitdiffhomepage
path: root/tracker-hatire/thread.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-06-08 02:16:53 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-06-08 02:16:53 +0200
commit9868b751ce89808ef317e212c7620af9bb7e90d2 (patch)
treedc8a2e46e54ae8aecb3c8f7007726959c1631933 /tracker-hatire/thread.cpp
parent91fd6258ccc3ab8bf67f4c27308c2197a8badfa3 (diff)
tracker/hatire: fix breakage
Issue: #139
Diffstat (limited to 'tracker-hatire/thread.cpp')
-rw-r--r--tracker-hatire/thread.cpp46
1 files changed, 22 insertions, 24 deletions
diff --git a/tracker-hatire/thread.cpp b/tracker-hatire/thread.cpp
index cc0f3012..506ccfcf 100644
--- a/tracker-hatire/thread.cpp
+++ b/tracker-hatire/thread.cpp
@@ -88,8 +88,6 @@ hatire_thread::~hatire_thread()
hatire_thread::hatire_thread()
{
- data_read.reserve(65536);
-
connect(this, &QThread::finished, this, &hatire_thread::teardown_serial, Qt::DirectConnection);
connect(this, &hatire_thread::init_serial_port, this, &hatire_thread::init_serial_port_impl, Qt::QueuedConnection);
connect(this, &hatire_thread::serial_info, this, &hatire_thread::serial_info_impl, Qt::QueuedConnection);
@@ -135,8 +133,8 @@ void hatire_thread::run()
com_port.setFileName(HATIRE_DEBUG_LOGFILE);
com_port.open(QIODevice::ReadOnly);
- read_timer.start(10);
connect(&read_timer, &QTimer::timeout, this, &hatire_thread::on_serial_read, Qt::DirectConnection);
+ read_timer.start(5);
#endif
(void) exec();
@@ -302,38 +300,38 @@ void hatire_thread::serial_info_impl()
void hatire_thread::on_serial_read()
{
+ const int sz = com_port.read(buf, sizeof(buf));
+
+ if (sz > 0)
{
+ stat.input(timer.elapsed_ms());
+ timer.start();
+
QMutexLocker lck(&data_mtx);
-#ifndef HATIRE_DEBUG_LOGFILE
- data_read += com_port.readAll();
-#else
- QByteArray tmp = com_port.read(30);
- data_read += tmp;
- if (tmp.length() == 0 && read_timer.isActive())
- {
- qDebug() << "eof";
- read_timer.stop();
- }
-#endif
+ data_read.append(buf, sz);
}
-
- stat.input(timer.elapsed_ms());
- timer.start();
-
- if (throttle_timer.elapsed_ms() >= 3000)
+#if defined HATIRE_DEBUG_LOGFILE
+ else
{
- throttle_timer.start();
- qDebug() << "stat:" << "avg" << stat.avg() << "stddev" << stat.stddev();
+ qDebug() << "eof";
+ read_timer.stop();
}
+#endif
- if (s.serial_bug_workaround)
+ if (s.serial_bug_workaround || sz <= 0)
{
// 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;
+ static constexpr int hz = 90;
+ static 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()