diff options
author | Jan Mulder <jlmulder@xs4all.nl> | 2017-07-03 20:56:44 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-07-04 23:46:07 +0900 |
commit | 6031692a39820c0b5466d558e913272edabeb92a (patch) | |
tree | af9a6915cc6a0763d9ae97cf4cf1ab6c571a2179 | |
parent | f6768cedf3f0e05e125bca11ff31c2361d2e880c (diff) | |
download | subsurface-6031692a39820c0b5466d558e913272edabeb92a.tar.gz |
Use waitFor instead of timer
See e79bede0aa5b3bd. We rather use wait in combination
with spinning the event loop.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
-rw-r--r-- | core/qt-ble.cpp | 11 | ||||
-rw-r--r-- | core/qt-ble.h | 1 |
2 files changed, 4 insertions, 8 deletions
diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp index 6ea59cded..3d29c2550 100644 --- a/core/qt-ble.cpp +++ b/core/qt-ble.cpp @@ -60,7 +60,6 @@ void BLEObject::characteristcStateChanged(const QLowEnergyCharacteristic &c, con Q_UNUSED(c) receivedPackets.append(value); - waitForPacket.exit(); } void BLEObject::writeCompleted(const QLowEnergyDescriptor &d, const QByteArray &value) @@ -155,13 +154,11 @@ dc_status_t BLEObject::read(void *data, size_t size, size_t *actual) if (list.isEmpty()) return DC_STATUS_IO; - QTimer timer; int msec = BLE_TIMEOUT; - timer.setSingleShot(true); - - waitForPacket.connect(&timer, SIGNAL(timeout()), SLOT(quit())); - timer.start(msec); - waitForPacket.exec(); + while (msec > 0 && receivedPackets.isEmpty()) { + waitFor(100); + msec -= 100; + }; } // Still no packet? diff --git a/core/qt-ble.h b/core/qt-ble.h index 34c726bb2..6f63870a6 100644 --- a/core/qt-ble.h +++ b/core/qt-ble.h @@ -36,7 +36,6 @@ private: QLowEnergyController *controller = nullptr; QList<QByteArray> receivedPackets; - QEventLoop waitForPacket; bool isCharacteristicWritten; dc_user_device_t *device; |