/** * Disables notifications on 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 be disabled. * @return The request. */ @NonNull protected final WriteRequest disableNotifications(@Nullable final BluetoothGattCharacteristic characteristic) { return Request.newDisableNotificationsRequest(characteristic).setManager(this); }
/** * Disables indications on 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 be disabled. * @return The request. */ @NonNull protected final WriteRequest disableIndications(@Nullable final BluetoothGattCharacteristic characteristic) { return Request.newDisableIndicationsRequest(characteristic).setManager(this); }
/** * Enables indications on 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 be enabled. * @return The request. */ @NonNull protected final WriteRequest enableIndications(@Nullable final BluetoothGattCharacteristic characteristic) { return Request.newEnableIndicationsRequest(characteristic).setManager(this); }
/** * Enables notifications on 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 be enabled. * @return The request. */ @NonNull protected final WriteRequest enableNotifications( @Nullable final BluetoothGattCharacteristic characteristic) { return Request.newEnableNotificationsRequest(characteristic).setManager(this); }
/** * Writes the given data to the descriptor. * <p> * Use {@link WriteRequest#split() split()} or * {@link WriteRequest#split(DataSplitter) split(ValueSplitter)} on the returned * {@link WriteRequest} if data should be automatically split into multiple packets. * 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 write to. * @param data data to be written to the descriptor. * @return The request. */ @NonNull protected final WriteRequest writeDescriptor(@Nullable final BluetoothGattDescriptor descriptor, @Nullable final byte[] data) { return Request.newWriteRequest(descriptor, data).setManager(this); }
/** * Writes at most length bytes from offset at given data to the characteristic. * The write type is taken from the characteristic. * <p> * Use {@link WriteRequest#split() split()} or * {@link WriteRequest#split(DataSplitter) split(ValueSplitter)} on the returned * {@link WriteRequest} if data should be automatically split into multiple packets. * 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 write to. * @param data data to be written to the characteristic. * @param offset index of the first byte to be sent. * @param length number of bytes to be sent. * @return The request. */ @NonNull protected final WriteRequest writeCharacteristic(@Nullable final BluetoothGattCharacteristic characteristic, @Nullable final byte[] data, final int offset, final int length) { return Request.newWriteRequest(characteristic, data, offset, length).setManager(this); }
/** * Writes at most length bytes from offset at given data to the descriptor. * <p> * Use {@link WriteRequest#split() split()} or * {@link WriteRequest#split(DataSplitter) split(ValueSplitter)} on the returned * {@link WriteRequest} if data should be automatically split into multiple packets. * 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 write to. * @param data data to be written to the descriptor. * @param offset index of the first byte to be sent. * @param length number of bytes to be sent. * @return The request. */ @NonNull protected final WriteRequest writeDescriptor(@Nullable final BluetoothGattDescriptor descriptor, @Nullable final byte[] data, final int offset, final int length) { return Request.newWriteRequest(descriptor, data, offset, length).setManager(this); }
/** * Writes the given data to the characteristic. The write type is taken from the characteristic. * <p> * Use {@link WriteRequest#split() split()} or * {@link WriteRequest#split(DataSplitter) split(ValueSplitter)} on the returned * {@link WriteRequest} if data should be automatically split into multiple packets. * 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 write to. * @param data data to be written to the characteristic. * @return The request. */ @NonNull protected final WriteRequest writeCharacteristic(@Nullable final BluetoothGattCharacteristic characteristic, @Nullable final byte[] data) { return Request.newWriteRequest(characteristic, data).setManager(this); }
/** * Writes the given data to the characteristic. The write type is taken from the characteristic. * <p> * Use {@link WriteRequest#split() split()} or * {@link WriteRequest#split(DataSplitter) split(DataSplitter)} on the returned * {@link WriteRequest} if data should be automatically split into multiple packets. * 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 write to. * @param data data to be written to the characteristic. * @return The request. */ @NonNull protected final WriteRequest writeCharacteristic(@Nullable final BluetoothGattCharacteristic characteristic, @Nullable final Data data) { return Request.newWriteRequest(characteristic, data != null ? data.getValue() : null) .setManager(this); }
/** * Writes the given data to the descriptor. * <p> * Use {@link WriteRequest#split() split()} or * {@link WriteRequest#split(DataSplitter) split(ValueSplitter)} on the returned * {@link WriteRequest} if data should be automatically split into multiple packets. * 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 write to. * @param data data to be written to the descriptor. * @return The request. */ @NonNull protected final WriteRequest writeDescriptor(@Nullable final BluetoothGattDescriptor descriptor, @Nullable final Data data) { return Request.newWriteRequest(descriptor, data != null ? data.getValue() : null) .setManager(this); }
/** * This method disables notifications on the Battery Level characteristic. * * @deprecated Use {@link #disableNotifications(BluetoothGattCharacteristic)} instead. */ @Deprecated protected void disableBatteryLevelNotifications() { Request.newDisableBatteryLevelNotificationsRequest().setManager(this) .done(device -> log(Log.INFO, "Battery Level notifications disabled")) .enqueue(); }
/** * This method enables notifications on the Battery Level characteristic. * * @deprecated Use {@link #setNotificationCallback(BluetoothGattCharacteristic)} and * {@link #enableNotifications(BluetoothGattCharacteristic)} instead. */ @SuppressWarnings("ConstantConditions") @Deprecated protected void enableBatteryLevelNotifications() { if (mBatteryLevelNotificationCallback == null) { mBatteryLevelNotificationCallback = new ValueChangedCallback() .with((device, data) -> { if (data.size() == 1) { final int batteryLevel = data.getIntValue(Data.FORMAT_UINT8, 0); mBatteryValue = batteryLevel; final BleManagerGattCallback callback = mGattCallback; if (callback != null) { callback.onBatteryValueReceived(mBluetoothGatt, batteryLevel); } mCallbacks.onBatteryValueReceived(device, batteryLevel); } }); } Request.newEnableBatteryLevelNotificationsRequest().setManager(this) .done(device -> log(Log.INFO, "Battery Level notifications enabled")) .enqueue(); }