BLE support: simplify write function

It seems clearer to bail when list is empty...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2017-09-20 19:19:25 -04:00
parent 16d9b0c790
commit bb1df1218d

View file

@ -151,24 +151,24 @@ dc_status_t BLEObject::write(const void *data, size_t size, size_t *actual)
}
QList<QLowEnergyCharacteristic> list = preferredService()->characteristics();
if (list.isEmpty())
return DC_STATUS_IO;
QByteArray bytes((const char *)data, (int) size);
if (!list.isEmpty()) {
const QLowEnergyCharacteristic &c = list.constFirst();
QLowEnergyService::WriteMode mode;
const QLowEnergyCharacteristic &c = list.constFirst();
QLowEnergyService::WriteMode mode;
mode = (c.properties() & QLowEnergyCharacteristic::WriteNoResponse) ?
mode = (c.properties() & QLowEnergyCharacteristic::WriteNoResponse) ?
QLowEnergyService::WriteWithoutResponse :
QLowEnergyService::WriteWithResponse;
if (IS_SHEARWATER(device))
bytes.prepend("\1\0", 2);
if (IS_SHEARWATER(device))
bytes.prepend("\1\0", 2);
preferredService()->writeCharacteristic(c, bytes, mode);
return DC_STATUS_SUCCESS;
}
return DC_STATUS_IO;
preferredService()->writeCharacteristic(c, bytes, mode);
return DC_STATUS_SUCCESS;
}
dc_status_t BLEObject::read(void *data, size_t size, size_t *actual)