aboutsummaryrefslogtreecommitdiff
path: root/bt/src/main/java/io/trygvis/android/bt/BtBluetoothGattCallback.java
diff options
context:
space:
mode:
Diffstat (limited to 'bt/src/main/java/io/trygvis/android/bt/BtBluetoothGattCallback.java')
-rw-r--r--bt/src/main/java/io/trygvis/android/bt/BtBluetoothGattCallback.java73
1 files changed, 73 insertions, 0 deletions
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