From 00756a74192becb02e6bbe982d50c00f7ddc1005 Mon Sep 17 00:00:00 2001 From: Travis Wyatt Date: Sat, 18 Jan 2025 18:13:12 -0800 Subject: [PATCH] Simplify "client characteristic config" UUID definition --- .../androidMain/kotlin/BluetoothDeviceAndroidPeripheral.kt | 3 ++- .../kotlin/bluetooth/ClientCharacteristicConfigUuid.kt | 6 +++--- kable-core/src/androidMain/kotlin/external/Constants.kt | 3 --- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/kable-core/src/androidMain/kotlin/BluetoothDeviceAndroidPeripheral.kt b/kable-core/src/androidMain/kotlin/BluetoothDeviceAndroidPeripheral.kt index 6f4255721..8f3e740ee 100644 --- a/kable-core/src/androidMain/kotlin/BluetoothDeviceAndroidPeripheral.kt +++ b/kable-core/src/androidMain/kotlin/BluetoothDeviceAndroidPeripheral.kt @@ -42,6 +42,7 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlin.coroutines.cancellation.CancellationException import kotlin.time.Duration +import kotlin.uuid.toJavaUuid import kotlin.uuid.toKotlinUuid // Number of service discovery attempts to make if no services are discovered. @@ -370,7 +371,7 @@ private val Priority.intValue: Int } private val PlatformCharacteristic.configDescriptor: PlatformDescriptor? - get() = descriptors.firstOrNull { clientCharacteristicConfigUuid == it.uuid.toKotlinUuid() } + get() = descriptors.firstOrNull { clientCharacteristicConfigUuid == it.uuid } private val PlatformCharacteristic.supportsNotify: Boolean get() = properties and PROPERTY_NOTIFY != 0 diff --git a/kable-core/src/androidMain/kotlin/bluetooth/ClientCharacteristicConfigUuid.kt b/kable-core/src/androidMain/kotlin/bluetooth/ClientCharacteristicConfigUuid.kt index ba3e47117..d32190256 100644 --- a/kable-core/src/androidMain/kotlin/bluetooth/ClientCharacteristicConfigUuid.kt +++ b/kable-core/src/androidMain/kotlin/bluetooth/ClientCharacteristicConfigUuid.kt @@ -1,6 +1,6 @@ package com.juul.kable.bluetooth -import com.juul.kable.external.CLIENT_CHARACTERISTIC_CONFIG_UUID -import kotlin.uuid.Uuid +import com.juul.kable.Bluetooth +import kotlin.uuid.toJavaUuid -internal val clientCharacteristicConfigUuid = Uuid.parse(CLIENT_CHARACTERISTIC_CONFIG_UUID) +internal val clientCharacteristicConfigUuid = (Bluetooth.BaseUuid + 0x2902).toJavaUuid() diff --git a/kable-core/src/androidMain/kotlin/external/Constants.kt b/kable-core/src/androidMain/kotlin/external/Constants.kt index c0d2107c0..68fab4231 100644 --- a/kable-core/src/androidMain/kotlin/external/Constants.kt +++ b/kable-core/src/androidMain/kotlin/external/Constants.kt @@ -49,6 +49,3 @@ internal const val GATT_NOT_ENCRYPTED = 0x8e internal const val GATT_CCC_CFG_ERR = 0xFD internal const val GATT_PRC_IN_PROGRESS = 0xFE internal const val GATT_OUT_OF_RANGE = 0xFF - -// https://android.googlesource.com/platform/development/+/7167a054a8027f75025c865322fa84791a9b3bd1/samples/BluetoothLeGatt/src/com/example/bluetooth/le/SampleGattAttributes.java#27 -internal const val CLIENT_CHARACTERISTIC_CONFIG_UUID = "00002902-0000-1000-8000-00805f9b34fb"