summaryrefslogtreecommitdiffhomepage
path: root/tracker-hatire
diff options
context:
space:
mode:
Diffstat (limited to 'tracker-hatire')
-rw-r--r--tracker-hatire/thread.cpp60
1 files changed, 11 insertions, 49 deletions
diff --git a/tracker-hatire/thread.cpp b/tracker-hatire/thread.cpp
index a687cf9c..cc0f3012 100644
--- a/tracker-hatire/thread.cpp
+++ b/tracker-hatire/thread.cpp
@@ -89,7 +89,6 @@ hatire_thread::~hatire_thread()
hatire_thread::hatire_thread()
{
data_read.reserve(65536);
- com_port.setReadBufferSize(2048);
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);
@@ -303,71 +302,34 @@ void hatire_thread::serial_info_impl()
void hatire_thread::on_serial_read()
{
- static char buf[256];
- int sz;
-
-#if !defined HATIRE_DEBUG_LOGFILE
- bool error = false, empty = false;
-#endif
-
{
QMutexLocker lck(&data_mtx);
-
#ifndef HATIRE_DEBUG_LOGFILE
- sz = com_port.read(buf, sizeof(buf));
- error |= sz < 0;
- empty |= sz == 0;
+ data_read += com_port.readAll();
#else
- const int sz = com_port.read(buf, sizeof(buf));
-
- if (sz <= 0 && read_timer.isActive())
+ QByteArray tmp = com_port.read(30);
+ data_read += tmp;
+ if (tmp.length() == 0 && read_timer.isActive())
{
- if (sz < 0)
- qDebug() << "hatire: debug file read error" << com_port.errorString();
qDebug() << "eof";
read_timer.stop();
- return;
}
#endif
}
-#if !defined HATIRE_DEBUG_LOGFILE
- if (error || com_port.error() != QSerialPort::NoError)
- {
- once_only(qDebug() << "hatire serial: error num" << com_port.error() << "num2" << error);
- com_port.clearError(); // XXX must test it
- }
- else if (empty)
- once_only(qDebug() << "hatire serial: empty");
- else
- goto ok;
-#endif
-
- goto fail;
-
-ok:
- data_read.append(buf, sz);
-
- using namespace time_units;
+ stat.input(timer.elapsed_ms());
+ timer.start();
- stat.input(prog1(timer.elapsed<ms>().count(), timer.start()));
-
- if (throttle_timer.elapsed_seconds() >= 1)
+ if (throttle_timer.elapsed_ms() >= 3000)
{
throttle_timer.start();
- qDebug() << "hatire stat:" << "avg" << stat.avg() << "stddev" << stat.stddev();
+ qDebug() << "stat:" << "avg" << stat.avg() << "stddev" << stat.stddev();
}
- if (!s.serial_bug_workaround)
- return;
-
-fail:
- // qt can fire QSerialPort::readyRead() needlessly, causing a busy loop.
- // see https://github.com/opentrack/opentrack/issues/327#issuecomment-207941003
-
- once_only(qDebug() << "hatire: sleeping due to error, pinout:" << int(com_port.pinoutSignals()));
-
+ if (s.serial_bug_workaround)
{
+ // 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);