/** * Sends the read request to the given characteristic. * If the characteristic is null, the {@link Request#fail(FailCallback) fail(FailCallback)} * callback will be called. * <p> * The returned request must be either enqueued using {@link Request#enqueue()} for * asynchronous use, or awaited using await() in synchronous execution. * * @param characteristic the characteristic to read. * @return The request. */ @NonNull protected final ReadRequest readCharacteristic(@Nullable final BluetoothGattCharacteristic characteristic) { return Request.newReadRequest(characteristic).setManager(this); }
/** * Sends the read request to the given descriptor. * If the descriptor is null, the {@link Request#fail(FailCallback) fail(FailCallback)} * callback will be called. * <p> * The returned request must be either enqueued using {@link Request#enqueue()} for * asynchronous use, or awaited using await() in synchronous execution. * * @param descriptor the descriptor to read. * @return The request. */ @NonNull protected final ReadRequest readDescriptor(@Nullable final BluetoothGattDescriptor descriptor) { return Request.newReadRequest(descriptor).setManager(this); }
/** * Reads the battery level from the device. * * @deprecated Use {@link #readCharacteristic(BluetoothGattCharacteristic)} instead. */ @SuppressWarnings("ConstantConditions") @Deprecated protected void readBatteryLevel() { Request.newReadBatteryLevelRequest().setManager(this) .with((device, data) -> { if (data.size() == 1) { final int batteryLevel = data.getIntValue(Data.FORMAT_UINT8, 0); log(Log.INFO, "Battery Level received: " + batteryLevel + "%"); mBatteryValue = batteryLevel; final BleManagerGattCallback callback = mGattCallback; if (callback != null) { callback.onBatteryValueReceived(mBluetoothGatt, batteryLevel); } mCallbacks.onBatteryValueReceived(device, batteryLevel); } }) .enqueue(); }