From 3e619a735e63a1222e71060d9e65b354a156b158 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 28 Jan 2015 23:45:38 +0100 Subject: o Major refactoring on the BtPromise, mainly internal. Renaming BtPromise to BtSequence and BtSequencer. --- .../android/bt/BtBluetoothGattCallback.java | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 bt/src/main/java/io/trygvis/android/bt/BtBluetoothGattCallback.java (limited to 'bt/src/main/java/io/trygvis/android/bt/BtBluetoothGattCallback.java') diff --git a/bt/src/main/java/io/trygvis/android/bt/BtBluetoothGattCallback.java b/bt/src/main/java/io/trygvis/android/bt/BtBluetoothGattCallback.java new file mode 100644 index 0000000..1f4921f --- /dev/null +++ b/bt/src/main/java/io/trygvis/android/bt/BtBluetoothGattCallback.java @@ -0,0 +1,73 @@ +package io.trygvis.android.bt; + +import android.bluetooth.BluetoothGatt; +import android.bluetooth.BluetoothGattCallback; +import android.bluetooth.BluetoothGattCharacteristic; +import android.bluetooth.BluetoothGattDescriptor; + +import static io.trygvis.android.bt.BtSequencer.EventType.onCharacteristicChanged; +import static io.trygvis.android.bt.BtSequencer.EventType.onCharacteristicRead; +import static io.trygvis.android.bt.BtSequencer.EventType.onCharacteristicWrite; +import static io.trygvis.android.bt.BtSequencer.EventType.onConnectionStateChange; +import static io.trygvis.android.bt.BtSequencer.EventType.onDescriptorRead; +import static io.trygvis.android.bt.BtSequencer.EventType.onDescriptorWrite; +import static io.trygvis.android.bt.BtSequencer.EventType.onReliableWriteCompleted; +import static io.trygvis.android.bt.BtSequencer.EventType.onServicesDiscovered; + +public class BtBluetoothGattCallback extends BluetoothGattCallback { + + private final BtSequencer sequencer; + + BtBluetoothGattCallback(BtSequencer sequencer) { + this.sequencer = sequencer; + } + + // ----------------------------------------------------------------------- + // + // ----------------------------------------------------------------------- + + @Override + public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { + sequencer.onEvent(onConnectionStateChange, "status=" + status + ", newState=" + newState, gatt, null, null, status, newState); + } + + @Override + public void onServicesDiscovered(BluetoothGatt gatt, int status) { + sequencer.onEvent(onServicesDiscovered, "status=" + status, gatt, null, null, status, 9); + } + + @Override + public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { + sequencer.onEvent(onCharacteristicRead, "status=" + status + ", characteristic=" + characteristic.getUuid(), gatt, characteristic, null, status, 0); + } + + @Override + public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { + sequencer.onEvent(onCharacteristicWrite, "status=" + status + ", characteristic=" + characteristic.getUuid(), gatt, characteristic, null, status, 0); + } + + @Override + public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { + sequencer.onEvent(onCharacteristicChanged, "characteristic=" + characteristic.getUuid(), gatt, characteristic, null, BluetoothGatt.GATT_SUCCESS, 0); + } + + @Override + public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { + sequencer.onEvent(onDescriptorRead, "status=" + status + ", descriptor=" + descriptor.getUuid(), gatt, null, descriptor, status, 0); + } + + @Override + public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { + sequencer.onEvent(onDescriptorWrite, "status=" + status + ", descriptor=" + descriptor.getUuid(), gatt, null, descriptor, status, 0); + } + + @Override + public void onReliableWriteCompleted(BluetoothGatt gatt, int status) { + sequencer.onEvent(onReliableWriteCompleted, "status=" + status, gatt, null, null, status, 0); + } + +// @Override +// public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { +// sequencer.onEvent(onReadRemoteRssi, "status=" + status, gatt, null, null, status, 0); +// } +} \ No newline at end of file -- cgit v1.2.3