summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2018-10-06 11:26:26 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-06 19:38:28 -0700
commit88f4c06b993daa1d669aad71f90d92c4ebdb4c9c (patch)
treed56f1817ef686285df83f7f543de8939c3ad99db /core
parentec532b8f5963221ff5aad37799ace869dacb76a5 (diff)
downloadsubsurface-88f4c06b993daa1d669aad71f90d92c4ebdb4c9c.tar.gz
qt-ble: add support to wait for descriptor write completion
When we enable notifications, we actually want to make sure to wait for that write to have completed before we start communicating with the device, because otherwise we might lose notification events. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'core')
-rw-r--r--core/qt-ble.cpp2
-rw-r--r--core/qt-ble.h2
2 files changed, 4 insertions, 0 deletions
diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp
index eae10e6b1..0ecad50c3 100644
--- a/core/qt-ble.cpp
+++ b/core/qt-ble.cpp
@@ -92,6 +92,7 @@ void BLEObject::characteristicWritten(const QLowEnergyCharacteristic &c, const Q
void BLEObject::writeCompleted(const QLowEnergyDescriptor&, const QByteArray&)
{
qDebug() << "BLE write completed";
+ desc_written++;
}
void BLEObject::addService(const QBluetoothUuid &newService)
@@ -489,6 +490,7 @@ dc_status_t qt_ble_open(void **io, dc_context_t *, const char *devaddr, dc_user_
qDebug() << "now writing \"0x0100\" to the descriptor" << d.uuid().toString();
ble->preferredService()->writeDescriptor(d, QByteArray::fromHex("0100"));
+ WAITFOR(ble->descriptorWritten(), 1000);
break;
}
}
diff --git a/core/qt-ble.h b/core/qt-ble.h
index ddf628e60..eb028f9b9 100644
--- a/core/qt-ble.h
+++ b/core/qt-ble.h
@@ -24,6 +24,7 @@ public:
dc_status_t read(void* data, size_t size, size_t *actual);
inline QLowEnergyService *preferredService() { return preferred; }
+ inline int descriptorWritten() { return desc_written; }
dc_status_t select_preferred_service(void);
public slots:
@@ -43,6 +44,7 @@ private:
bool isCharacteristicWritten;
dc_user_device_t *device;
unsigned int hw_credit = 0;
+ unsigned int desc_written = 0;
QList<QUuid> hwAllCharacteristics = {
"{00000001-0000-1000-8000-008025000000}", // HW_OSTC_BLE_DATA_RX