From acec691b5d6d6373e8f8f41f288d5fb6e2f84215 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 9 May 2016 16:25:31 +0200 Subject: tracker/hatire: add serial 100% cpu usage workaround Issue: #327 --- tracker-hatire/ftnoir_hatcontrols.ui | 304 ++++++++++++--------------- tracker-hatire/ftnoir_tracker_hat_dialog.cpp | 2 + tracker-hatire/ftnoir_tracker_hat_settings.h | 3 +- tracker-hatire/thread.cpp | 13 +- 4 files changed, 142 insertions(+), 180 deletions(-) mode change 100644 => 100755 tracker-hatire/ftnoir_hatcontrols.ui diff --git a/tracker-hatire/ftnoir_hatcontrols.ui b/tracker-hatire/ftnoir_hatcontrols.ui old mode 100644 new mode 100755 index 2d347f08..3ff54618 --- a/tracker-hatire/ftnoir_hatcontrols.ui +++ b/tracker-hatire/ftnoir_hatcontrols.ui @@ -6,8 +6,8 @@ 0 0 - 370 - 740 + 341 + 525 @@ -42,58 +42,14 @@ false - - - - - 0 - 0 - - - - - 80 - 25 - - - - - 80 - 25 - - - - Cancel - - - - - + + - + 0 0 - - - 80 - 25 - - - - - 80 - 25 - - - - OK - - - - - 0 @@ -114,6 +70,15 @@ General + + 4 + + + 4 + + + 4 + @@ -126,6 +91,31 @@ 4 + + + + + 0 + 0 + + + + + 65535 + 16777215 + + + + false + + + QComboBox::AdjustToMinimumContentsLength + + + 0 + + + @@ -145,28 +135,29 @@ - - + + + + Buggy serial port uses too much CPU + + + + + - + 0 0 - 65535 + 65536 16777215 - - false - - - QComboBox::AdjustToMinimumContentsLength - - - 0 + + Workaround @@ -189,22 +180,6 @@ - - - - false - - - - 80 - 20 - - - - Center - - - @@ -852,13 +827,6 @@ Arduino Commands - - - - Delay Init - - - @@ -866,20 +834,6 @@ - - - - Command for Initialising Arduino - - - - - - - Delay Start - - - @@ -894,27 +848,24 @@ - - - - Delay Sequence + + + + Command for Initialising Arduino - - + + - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Delay after Start Command in ms</span></p></body></html> - - - 5000 + Command for Stop send sequence - - 50 + + + + + + Center: @@ -925,17 +876,10 @@ p, li { white-space: pre-wrap; } - - - - Command for Stop send sequence - - - - - + + - Center: + Reset: @@ -946,6 +890,13 @@ p, li { white-space: pre-wrap; } + + + + Command for Reset Arduino + + + @@ -960,20 +911,6 @@ p, li { white-space: pre-wrap; } - - - - Reset: - - - - - - - Command for Reset Arduino - - - @@ -989,7 +926,26 @@ p, li { white-space: pre-wrap; } - + + + + + 51 + 19 + + + + <html><head/><body><p>Indicate at OpenTrack speed sketch FPS to adjust CPU </p></body></html> + + + 10 + + + 200 + + + + @@ -1012,7 +968,7 @@ p, li { white-space: pre-wrap; } - + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> @@ -1029,22 +985,40 @@ p, li { white-space: pre-wrap; } - - - - - 51 - 19 - + + + + + 0 + 0 + - - <html><head/><body><p>Indicate at OpenTrack speed sketch FPS to adjust CPU </p></body></html> + + Delay - - 10 + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Delay after Start Command in ms</span></p></body></html> - 200 + 5000 + + + 50 + + + + + + + Delay after startup @@ -1172,34 +1146,18 @@ p, li { white-space: pre-wrap; } - - - - - 80 - 25 - - - - - 80 - 25 - - - - Save + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok - btnOK - btnSave - btnCancel cbSerialPort btnZero - btnCenter btnReset chkEnableYaw cb_yaw @@ -1219,9 +1177,7 @@ p, li { white-space: pre-wrap; } chkEnableZ cb_z chkInvertZ - spb_BeforeInit le_cmd_init - spb_BeforeStart le_cmd_start spb_AfterStart le_cmd_stop diff --git a/tracker-hatire/ftnoir_tracker_hat_dialog.cpp b/tracker-hatire/ftnoir_tracker_hat_dialog.cpp index 60ddd14a..734619c9 100755 --- a/tracker-hatire/ftnoir_tracker_hat_dialog.cpp +++ b/tracker-hatire/ftnoir_tracker_hat_dialog.cpp @@ -98,6 +98,8 @@ TrackerControls::TrackerControls() : 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); + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); diff --git a/tracker-hatire/ftnoir_tracker_hat_settings.h b/tracker-hatire/ftnoir_tracker_hat_settings.h index 92dacd42..53ab8870 100755 --- a/tracker-hatire/ftnoir_tracker_hat_settings.h +++ b/tracker-hatire/ftnoir_tracker_hat_settings.h @@ -22,7 +22,7 @@ struct TrackerSettings : opts value DelayInit, DelayStart, DelaySeq; - value BigEndian, EnableLogging; + value BigEndian, EnableLogging, serial_bug_workaround; value QSerialPortName; @@ -63,6 +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), QSerialPortName(b, "serial-port-name", ""), pBaudRate(b, "baud-rate", QSerialPort::Baud115200), pDataBits(b, "data-bits", QSerialPort::Data8), diff --git a/tracker-hatire/thread.cpp b/tracker-hatire/thread.cpp index 238c5fdd..d512e463 100755 --- a/tracker-hatire/thread.cpp +++ b/tracker-hatire/thread.cpp @@ -309,11 +309,14 @@ void hatire_thread::on_serial_read() 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); + 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); + } } QByteArray& hatire_thread::send_data_read_nolock() -- cgit v1.2.3