Commit 8dcf6c4d authored by Lorenz Meier's avatar Lorenz Meier

SerialLink: Continue to run the app event loop while connecting

The earlier sleep calls disabled the app event queue, leading to "beachballing" in Mac OS and a visible boot delay / jitter. Running the event loop actively while waiting prevents the UI from freezing.
parent 5c56bd03
......@@ -157,7 +157,12 @@ bool SerialLink::_hardwareConnect(QSerialPort::SerialPortError& error, QString&
if (_port) {
qCDebug(SerialLinkLog) << "SerialLink:" << QString::number((long)this, 16) << "closing port";
_port->close();
QGC::SLEEP::usleep(50000);
// Wait 50 ms while continuing to run the event queue
for (unsigned i = 0; i < 10; i++) {
QGC::SLEEP::usleep(5000);
qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
}
delete _port;
_port = NULL;
}
......@@ -169,12 +174,22 @@ bool SerialLink::_hardwareConnect(QSerialPort::SerialPortError& error, QString&
qCDebug(SerialLinkLog) << "Not connecting to a bootloader, waiting for 2nd chance";
const unsigned retry_limit = 12;
unsigned retries;
for (retries = 0; retries < retry_limit; retries++) {
if (!_isBootloader()) {
QGC::SLEEP::msleep(500);
// Wait 500 ms while continuing to run the event loop
for (unsigned i = 0; i < 100; i++) {
QGC::SLEEP::msleep(5);
qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
}
break;
}
QGC::SLEEP::msleep(500);
// Wait 500 ms while continuing to run the event loop
for (unsigned i = 0; i < 100; i++) {
QGC::SLEEP::msleep(5);
qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
}
}
// Check limit
if (retries == retry_limit) {
......@@ -199,10 +214,17 @@ bool SerialLink::_hardwareConnect(QSerialPort::SerialPortError& error, QString&
#ifdef __android__
_port->open(QIODevice::ReadWrite);
#else
for (int openRetries = 0; openRetries < 4; openRetries++) {
// Try to open the port three times
for (int openRetries = 0; openRetries < 3; openRetries++) {
if (!_port->open(QIODevice::ReadWrite)) {
qCDebug(SerialLinkLog) << "Port open failed, retrying";
QGC::SLEEP::msleep(500);
// Wait 250 ms while continuing to run the event loop
for (unsigned i = 0; i < 50; i++) {
QGC::SLEEP::msleep(5);
qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
}
qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
} else {
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment