batt read

This commit is contained in:
leo 2022-12-19 21:07:02 +01:00
parent a9064f3e9e
commit 04da54b868
Signed by: leo
GPG Key ID: 0DD993BFB2B307DB
2 changed files with 12 additions and 8 deletions

View File

@ -134,10 +134,10 @@ public abstract class BLEDevice {
} }
@Override @Override
public void onDescriptorRead(@NonNull BluetoothGatt gatt, @NonNull BluetoothGattDescriptor descriptor, int status, @NonNull byte[] value) { public void onCharacteristicRead(@NonNull BluetoothGatt gatt, @NonNull BluetoothGattCharacteristic characteristic, int status) {
super.onDescriptorRead(gatt, descriptor, status, value); super.onCharacteristicRead(gatt, characteristic, status);
mainClass.onDescriptorRead(gatt, descriptor, status); Log.d("bt", "onCharacteristicRead: ");
Log.d("bt", "onDescriptorRead: "); mainClass.onCharacteristicRead(gatt, characteristic, status);
commandLock=false; commandLock=false;
runNextCommand(); runNextCommand();
} }
@ -201,6 +201,9 @@ public abstract class BLEDevice {
protected void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status){ protected void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status){
eventCallback.onDescriptorRead(gatt, descriptor, status); eventCallback.onDescriptorRead(gatt, descriptor, status);
} }
protected void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status){
eventCallback.onCharacteristicRead(gatt, characteristic, status);
}
@RequiresApi(api = Build.VERSION_CODES.S) @RequiresApi(api = Build.VERSION_CODES.S)
public void startScan(ScanCallback callback){ public void startScan(ScanCallback callback){
@ -252,7 +255,7 @@ public abstract class BLEDevice {
@SuppressLint("MissingPermission") @SuppressLint("MissingPermission")
protected void readCharacteristic(BluetoothGattService service, BluetoothGatt bluetoothGatt, UUID uuid){ protected void readCharacteristic(BluetoothGattService service, BluetoothGatt bluetoothGatt, UUID uuid){
Log.d("bt", "readCharacteristic: "+uuid); Log.d("bt", "readCharacteristic: "+uuid+":"+bluetoothGatt+":"+service);
BluetoothGattCharacteristic charact = service.getCharacteristic(uuid); BluetoothGattCharacteristic charact = service.getCharacteristic(uuid);
commandQueue.add(new Runnable() { commandQueue.add(new Runnable() {
@Override @Override

View File

@ -74,14 +74,15 @@ public class MainActivity extends AppCompatActivity {
} }
} }
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
@Override @Override
public void onCharacteristicRead(@NonNull BluetoothGatt gatt, @NonNull BluetoothGattCharacteristic characteristic, @NonNull byte[] value, int status) { public void onCharacteristicRead(@NonNull BluetoothGatt gatt, @NonNull BluetoothGattCharacteristic characteristic, int status) {
super.onCharacteristicRead(gatt, characteristic, value, status); super.onCharacteristicRead(gatt, characteristic, status);
Log.d("UI_update", "onCharacteristicRead: "); Log.d("UI_update", "onCharacteristicRead: ");
if(characteristic.getUuid().equals(sensor.CHAR_BATT_LEVEL_UUID)){ if(characteristic.getUuid().equals(sensor.CHAR_BATT_LEVEL_UUID)){
Log.d("UI_update", "onCharacteristicChanged: batt"); Log.d("UI_update", "onCharacteristicChanged: batt");
int val = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0); int val = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
CO2_widget.setValue(val); batt_widget.setValue(val);
} }
} }
}); });