diff --git a/core/src/androidMain/kotlin/BluetoothDevice.kt b/core/src/androidMain/kotlin/BluetoothDevice.kt index 4f8fb4234..1077be714 100644 --- a/core/src/androidMain/kotlin/BluetoothDevice.kt +++ b/core/src/androidMain/kotlin/BluetoothDevice.kt @@ -124,4 +124,4 @@ private val Phy.intValue: Int } private val BluetoothDevice.threadName: String - get() = "Gatt@$this" + get() = "Gatt@$this" \ No newline at end of file diff --git a/core/src/androidMain/kotlin/Peripheral.kt b/core/src/androidMain/kotlin/Peripheral.kt index ebdffa884..eb1f7b5a7 100644 --- a/core/src/androidMain/kotlin/Peripheral.kt +++ b/core/src/androidMain/kotlin/Peripheral.kt @@ -7,10 +7,7 @@ import android.bluetooth.BluetoothAdapter.STATE_TURNING_OFF import android.bluetooth.BluetoothAdapter.STATE_TURNING_ON import android.bluetooth.BluetoothDevice import android.bluetooth.BluetoothGatt -import android.bluetooth.BluetoothGattCharacteristic.PROPERTY_INDICATE -import android.bluetooth.BluetoothGattCharacteristic.PROPERTY_NOTIFY -import android.bluetooth.BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT -import android.bluetooth.BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE +import android.bluetooth.BluetoothGattCharacteristic.* import android.bluetooth.BluetoothGattDescriptor import android.bluetooth.BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE import android.bluetooth.BluetoothGattDescriptor.ENABLE_INDICATION_VALUE @@ -264,7 +261,9 @@ public class AndroidPeripheral internal constructor( data: ByteArray, writeType: WriteType, ) { - val bluetoothGattCharacteristic = bluetoothGattCharacteristicFrom(characteristic) + val bluetoothGattCharacteristic = bluetoothGattCharacteristicFrom( + characteristic, + PROPERTY_WRITE or PROPERTY_WRITE_NO_RESPONSE) connection.execute { bluetoothGattCharacteristic.value = data bluetoothGattCharacteristic.writeType = writeType.intValue @@ -313,7 +312,9 @@ public class AndroidPeripheral internal constructor( ): Flow = observers.acquire(characteristic, onSubscription) internal suspend fun startObservation(characteristic: Characteristic) { - val platformCharacteristic = platformServices.findCharacteristic(characteristic) + val platformCharacteristic = platformServices.findCharacteristic( + characteristic, + PROPERTY_NOTIFY or PROPERTY_INDICATE) connection .bluetoothGatt .setCharacteristicNotification(platformCharacteristic, true) @@ -356,8 +357,8 @@ public class AndroidPeripheral internal constructor( } private fun bluetoothGattCharacteristicFrom( - characteristic: Characteristic - ) = platformServices.findCharacteristic(characteristic).bluetoothGattCharacteristic + characteristic: Characteristic, propertyMask: Int = -1 + ) = platformServices.findCharacteristic(characteristic, propertyMask).bluetoothGattCharacteristic private fun bluetoothGattDescriptorFrom( descriptor: Descriptor diff --git a/core/src/androidMain/kotlin/PlatformService.kt b/core/src/androidMain/kotlin/PlatformService.kt index 0c8c23f9f..205dee4c5 100644 --- a/core/src/androidMain/kotlin/PlatformService.kt +++ b/core/src/androidMain/kotlin/PlatformService.kt @@ -29,21 +29,25 @@ internal fun BluetoothGattService.toPlatformService(): PlatformService { /** @throws NoSuchElementException if service or characteristic is not found. */ internal fun List.findCharacteristic( - characteristic: Characteristic + characteristic: Characteristic, propertyMask: Int = -1 ): PlatformCharacteristic = findCharacteristic( serviceUuid = characteristic.serviceUuid, - characteristicUuid = characteristic.characteristicUuid + characteristicUuid = characteristic.characteristicUuid, + propertyMask = propertyMask ) -/** @throws NoSuchElementException if service or characteristic is not found. */ private fun List.findCharacteristic( serviceUuid: Uuid, - characteristicUuid: Uuid + characteristicUuid: Uuid, + propertyMask: Int = -1 ): PlatformCharacteristic = first(serviceUuid) .characteristics - .first(characteristicUuid) + .first { platformCharacteristic -> + platformCharacteristic.characteristicUuid == characteristicUuid + && platformCharacteristic.bluetoothGattCharacteristic.properties and propertyMask != 0 + } /** @throws NoSuchElementException if service, characteristic or descriptor is not found. */ internal fun List.findDescriptor( @@ -63,5 +67,5 @@ private fun List.findDescriptor( ): PlatformDescriptor = findCharacteristic( serviceUuid = serviceUuid, - characteristicUuid = characteristicUuid + characteristicUuid = characteristicUuid, ).descriptors.first(descriptorUuid) diff --git a/gradle.properties b/gradle.properties index 43d4c70a6..0efc625be 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,18 +14,15 @@ POM_NAME=Kable POM_DESCRIPTION=Kotlin Asynchronous Bluetooth Low Energy POM_INCEPTION_YEAR=2020 -POM_URL=https://github.com/JuulLabs/kable -POM_SCM_URL=https://github.com/JuulLabs/kable -POM_SCM_CONNECTION=scm:git:git://github.com/JuulLabs/kable.git -POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/JuulLabs/kable.git +POM_URL=https://github.com/solvek/kable +POM_SCM_URL=https://github.com/solvek/kable +POM_SCM_CONNECTION=scm:git:git://github.com/solvek/kable.git +POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/solvek/kable.git POM_LICENCE_NAME=The Apache Software License, Version 2.0 POM_LICENCE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt POM_LICENCE_DIST=repo -POM_DEVELOPER_ID=twyatt -POM_DEVELOPER_NAME=Travis Wyatt -POM_DEVELOPER_URL=https://github.com/twyatt - -kotlin.js.webpack.major.version=5 -kotlin.js.compiler=both +POM_DEVELOPER_ID=solvek +POM_DEVELOPER_NAME=Sergi Adamchuk +POM_DEVELOPER_URL=https://github.com/solvek