diff --git a/app/src/main/java/com/example/co2sense_app/BLEDevice.java b/app/src/main/java/com/example/co2sense_app/BLEDevice.java index 969a4e1..0c0cf36 100644 --- a/app/src/main/java/com/example/co2sense_app/BLEDevice.java +++ b/app/src/main/java/com/example/co2sense_app/BLEDevice.java @@ -26,13 +26,9 @@ import androidx.annotation.RequiresApi; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; -import java.nio.ByteBuffer; import java.util.NoSuchElementException; public abstract class BLEDevice { - private enum ConnectionState {NONE, STARTING_BT, CONNECTING, CONNECTED}; - private ConnectionState state = ConnectionState.NONE; - private static final int REQUEST_BT_PERMISSION = 16535; private static final int REQUEST_ENABLE_BT = 16536; private static final int SELECT_DEVICE_REQUEST_CODE = 16537; @@ -114,7 +110,7 @@ public abstract class BLEDevice { @Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { super.onCharacteristicChanged(gatt, characteristic); - Log.d("bt", "onCharacteristicChanged: "+ ByteBuffer.wrap(characteristic.getValue()).getShort()); + mainClass.onCharacteristicChanged(gatt, characteristic); } }); } @@ -165,6 +161,10 @@ public abstract class BLEDevice { } + protected void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { + + } + @RequiresApi(api = Build.VERSION_CODES.S) public void startScan(ScanCallback callback){ scanCallback = callback; diff --git a/app/src/main/java/com/example/co2sense_app/CO2Sensor.java b/app/src/main/java/com/example/co2sense_app/CO2Sensor.java index 6925477..509d6fe 100644 --- a/app/src/main/java/com/example/co2sense_app/CO2Sensor.java +++ b/app/src/main/java/com/example/co2sense_app/CO2Sensor.java @@ -36,9 +36,17 @@ public class CO2Sensor extends BLEDevice { @Override protected void onServicesDiscovered() { super.onServicesDiscovered(); + Log.d("CO2Sense", "onServicesDiscovered: "); enableNotifications(bluetoothGatt); } + @Override + protected void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { + super.onCharacteristicChanged(gatt, characteristic); + byte[] rawValue = characteristic.getValue(); + Log.d("CO2Sense", "onCharacteristicChanged: "+characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 0)); + } + @SuppressLint("MissingPermission") private void enableNotifications(BluetoothGatt bluetoothGatt) { BluetoothGattService ES = bluetoothGatt.getService(ENVIRONMENTAL_SENSING_UUID);