diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-09-23 11:58:25 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-09-23 17:29:05 -0700 |
commit | 594f13eeafe52eb070c10daad8322ce2074dd4e5 (patch) | |
tree | c52360952f71ecfb0fb41c59f00d69e05cfe8d79 /core/qt-ble.cpp | |
parent | 35b8a4f404de3297cb8d126654e0ec37245a7537 (diff) | |
download | subsurface-594f13eeafe52eb070c10daad8322ce2074dd4e5.tar.gz |
qt-ble: use the WAITFOR() macro rather than open-coding wait loops
This is not only much clearer (and smaller code), but it also lowers the
latency for the waiting, since we don't always wait for the full 100ms.
Get rid of the now unused "waitfor()" function that just unconditionally
waited for 100ms.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'core/qt-ble.cpp')
-rw-r--r-- | core/qt-ble.cpp | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp index b4678aa5c..d84c223c2 100644 --- a/core/qt-ble.cpp +++ b/core/qt-ble.cpp @@ -47,11 +47,6 @@ static int debugCounter; } while (timer.elapsed() < (ms)); \ } while (0) -static void waitFor(int ms) -{ - WAITFOR(false, ms); -} - extern "C" { void BLEObject::serviceStateChanged(QLowEnergyService::ServiceState) @@ -226,11 +221,8 @@ dc_status_t BLEObject::setHwCredit(unsigned int c) QLowEnergyService::WriteWithResponse); /* And wait for the answer*/ - int msec = BLE_TIMEOUT; - while (msec > 0 && !isCharacteristicWritten) { - waitFor(100); - msec -= 100; - } + WAITFOR(isCharacteristicWritten, BLE_TIMEOUT); + if (!isCharacteristicWritten) return DC_STATUS_TIMEOUT; return DC_STATUS_SUCCESS; @@ -318,11 +310,7 @@ dc_status_t qt_ble_open(void **io, dc_context_t *, const char *devaddr, dc_user_ controller->connectToDevice(); // Create a timer. If the connection doesn't succeed after five seconds or no error occurs then stop the opening step - int msec = BLE_TIMEOUT; - while (msec > 0 && controller->state() == QLowEnergyController::ConnectingState) { - waitFor(100); - msec -= 100; - } + WAITFOR(controller->state() != QLowEnergyController::ConnectingState, BLE_TIMEOUT); switch (controller->state()) { case QLowEnergyController::ConnectedState: @@ -350,11 +338,7 @@ dc_status_t qt_ble_open(void **io, dc_context_t *, const char *devaddr, dc_user_ controller->discoverServices(); - msec = BLE_TIMEOUT; - while (msec > 0 && controller->state() == QLowEnergyController::DiscoveringState) { - waitFor(100); - msec -= 100; - } + WAITFOR(controller->state() != QLowEnergyController::DiscoveringState, BLE_TIMEOUT); qDebug() << " .. done discovering services"; if (ble->preferredService() == nullptr) { @@ -365,11 +349,7 @@ dc_status_t qt_ble_open(void **io, dc_context_t *, const char *devaddr, dc_user_ } qDebug() << " .. discovering details"; - msec = BLE_TIMEOUT; - while (msec > 0 && ble->preferredService()->state() == QLowEnergyService::DiscoveringServices) { - waitFor(100); - msec -= 100; - } + WAITFOR(ble->preferredService()->state() != QLowEnergyService::DiscoveringServices, BLE_TIMEOUT); if (ble->preferredService()->state() != QLowEnergyService::ServiceDiscovered) { qDebug() << "failed to find suitable service on" << devaddr; |