diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-01-28 23:45:38 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-01-28 23:45:38 +0100 |
commit | 3e619a735e63a1222e71060d9e65b354a156b158 (patch) | |
tree | 2f31cdc65d0d773874800c114530eb620bcca536 /bt/src/main/java/io/trygvis/android/bt/BtBluetoothGattCallback.java | |
parent | c4685214d8db34166213ffa373a16af1a99401a5 (diff) | |
download | io.trygvis.soilmoisture-android-3e619a735e63a1222e71060d9e65b354a156b158.tar.gz io.trygvis.soilmoisture-android-3e619a735e63a1222e71060d9e65b354a156b158.tar.bz2 io.trygvis.soilmoisture-android-3e619a735e63a1222e71060d9e65b354a156b158.tar.xz io.trygvis.soilmoisture-android-3e619a735e63a1222e71060d9e65b354a156b158.zip |
o Major refactoring on the BtPromise, mainly internal. Renaming BtPromise to BtSequence and BtSequencer.
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.java | 73 |
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 |