notif
This commit is contained in:
parent
a4e6d4ba17
commit
c74919496e
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user