diff options
-rw-r--r-- | core/qt-ble.cpp | 14 | ||||
-rw-r--r-- | core/qt-ble.h | 3 | ||||
-rw-r--r-- | core/qtserialbluetooth.cpp | 2 |
3 files changed, 17 insertions, 2 deletions
diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp index 0ecad50c3..ba75c8472 100644 --- a/core/qt-ble.cpp +++ b/core/qt-ble.cpp @@ -131,6 +131,7 @@ BLEObject::BLEObject(QLowEnergyController *c, dc_user_device_t *d) device = d; debugCounter = 0; isCharacteristicWritten = false; + timeout = BLE_TIMEOUT; } BLEObject::~BLEObject() @@ -203,7 +204,7 @@ dc_status_t BLEObject::read(void *data, size_t size, size_t *actual) qDebug() << QTime::currentTime() << "packet WAIT"; - WAITFOR(!receivedPackets.isEmpty(), BLE_TIMEOUT); + WAITFOR(!receivedPackets.isEmpty(), timeout); if (receivedPackets.isEmpty()) return DC_STATUS_IO; } @@ -516,6 +517,17 @@ static void checkThreshold() } } +/* + * NOTE! The 'set_timeout()' function only affects the timeout + * for qt_ble_read(), not for the various general BLE operations. + */ +dc_status_t qt_ble_set_timeout(void *io, int timeout) +{ + BLEObject *ble = (BLEObject *) io; + ble->set_timeout(timeout); + return DC_STATUS_SUCCESS; +} + dc_status_t qt_ble_read(void *io, void* data, size_t size, size_t *actual) { checkThreshold(); diff --git a/core/qt-ble.h b/core/qt-ble.h index eb028f9b9..f9600ad19 100644 --- a/core/qt-ble.h +++ b/core/qt-ble.h @@ -20,6 +20,7 @@ class BLEObject : public QObject public: BLEObject(QLowEnergyController *c, dc_user_device_t *); ~BLEObject(); + inline void set_timeout(int value) { timeout = value; } dc_status_t write(const void* data, size_t size, size_t *actual); dc_status_t read(void* data, size_t size, size_t *actual); @@ -45,6 +46,7 @@ private: dc_user_device_t *device; unsigned int hw_credit = 0; unsigned int desc_written = 0; + int timeout; QList<QUuid> hwAllCharacteristics = { "{00000001-0000-1000-8000-008025000000}", // HW_OSTC_BLE_DATA_RX @@ -57,6 +59,7 @@ private: extern "C" { dc_status_t qt_ble_open(void **io, dc_context_t *context, const char *devaddr, dc_user_device_t *user_device); +dc_status_t qt_ble_set_timeout(void *io, int timeout); dc_status_t qt_ble_read(void *io, void* data, size_t size, size_t *actual); dc_status_t qt_ble_write(void *io, const void* data, size_t size, size_t *actual); dc_status_t qt_ble_close(void *io); diff --git a/core/qtserialbluetooth.cpp b/core/qtserialbluetooth.cpp index 14ddacf2b..be1cda686 100644 --- a/core/qtserialbluetooth.cpp +++ b/core/qtserialbluetooth.cpp @@ -410,7 +410,7 @@ ble_packet_open(dc_iostream_t **iostream, dc_context_t *context, const char* dev void *io = NULL; static const dc_custom_cbs_t callbacks = { - NULL, /* set_timeout */ + qt_ble_set_timeout, /* set_timeout */ NULL, /* set_latency */ NULL, /* set_break */ NULL, /* set_dtr */ |