diff --git a/examples/ComposeMultiplatform-Example/shared/build.gradle.kts b/examples/ComposeMultiplatform-Example/shared/build.gradle.kts index 31daa74..1303f30 100644 --- a/examples/ComposeMultiplatform-Example/shared/build.gradle.kts +++ b/examples/ComposeMultiplatform-Example/shared/build.gradle.kts @@ -46,7 +46,7 @@ kotlin { implementation("dev.icerock.moko:mvvm-flow-compose:0.16.1") // BlueFalcon dependency here - implementation("dev.bluefalcon:blue-falcon:2.2.0") + implementation("dev.bluefalcon:blue-falcon:2.2.4") } } val commonTest by getting { diff --git a/examples/ComposeMultiplatform-Example/shared/src/commonMain/kotlin/com/example/bluefalconcomposemultiplatform/ble/data/BleDelegate.kt b/examples/ComposeMultiplatform-Example/shared/src/commonMain/kotlin/com/example/bluefalconcomposemultiplatform/ble/data/BleDelegate.kt index 7d8c39e..ed11ce4 100644 --- a/examples/ComposeMultiplatform-Example/shared/src/commonMain/kotlin/com/example/bluefalconcomposemultiplatform/ble/data/BleDelegate.kt +++ b/examples/ComposeMultiplatform-Example/shared/src/commonMain/kotlin/com/example/bluefalconcomposemultiplatform/ble/data/BleDelegate.kt @@ -54,7 +54,7 @@ class BleDelegate: BlueFalconDelegate { override fun didRssiUpdate(bluetoothPeripheral: BluetoothPeripheral) { } - override fun didUpdateMTU(bluetoothPeripheral: BluetoothPeripheral) { + override fun didUpdateMTU(bluetoothPeripheral: BluetoothPeripheral, status: Int) { } diff --git a/examples/KotlinMP-Example/gradle/libs.versions.toml b/examples/KotlinMP-Example/gradle/libs.versions.toml index baf9058..9382933 100644 --- a/examples/KotlinMP-Example/gradle/libs.versions.toml +++ b/examples/KotlinMP-Example/gradle/libs.versions.toml @@ -15,7 +15,7 @@ compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" } compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" } compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "compose-material3" } -blue-falcon = { module = "dev.bluefalcon:blue-falcon", version = "2.2.0" } +blue-falcon = { module = "dev.bluefalcon:blue-falcon", version = "2.2.4" } kmm-viewmodel = { module = "com.rickclephas.kmp:kmp-observableviewmodel-core", version = "1.0.0-BETA-3" } androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } compose-permissions = { group = "com.github.dawidraszka.compose-permission-handler", name = "core", version = "1.5.0" } diff --git a/library/gradle.properties b/library/gradle.properties index 603b531..d28b281 100644 --- a/library/gradle.properties +++ b/library/gradle.properties @@ -10,7 +10,7 @@ org.gradle.configureondemand = false android.useAndroidX=true android.enableJetifier=true -version=2.2.3 +version=2.2.4 group=dev.bluefalcon libraryName=blue-falcon kotlinx_coroutines_version=1.9.0 diff --git a/library/src/androidMain/kotlin/dev/bluefalcon/BlueFalcon.kt b/library/src/androidMain/kotlin/dev/bluefalcon/BlueFalcon.kt index b79f243..0617a24 100644 --- a/library/src/androidMain/kotlin/dev/bluefalcon/BlueFalcon.kt +++ b/library/src/androidMain/kotlin/dev/bluefalcon/BlueFalcon.kt @@ -285,7 +285,10 @@ actual class BlueFalcon actual constructor( } actual fun changeMTU(bluetoothPeripheral: BluetoothPeripheral, mtuSize: Int) { - mGattClientCallback.gattsForDevice(bluetoothPeripheral.device).forEach { it.requestMtu(mtuSize) } + log?.debug("changeMTU -> ${bluetoothPeripheral.uuid} mtuSize: $mtuSize") + mGattClientCallback.gattsForDevice(bluetoothPeripheral.device).forEach { gatt -> + gatt.requestMtu(mtuSize) + } } inner class BluetoothScanCallBack : ScanCallback() { @@ -398,16 +401,14 @@ actual class BlueFalcon actual constructor( } override fun onMtuChanged(gatt: BluetoothGatt?, mtu: Int, status: Int) { - super.onMtuChanged(gatt, mtu, status) log?.info("onMtuChanged$mtu status:$status") - if (status != BluetoothGatt.GATT_SUCCESS) { - return - } gatt?.device?.let { bluetoothDevice -> val bluetoothPeripheral = BluetoothPeripheral(bluetoothDevice) - bluetoothPeripheral.mtuSize = mtu + if (status == BluetoothGatt.GATT_SUCCESS) { + bluetoothPeripheral.mtuSize = mtu + } delegates.forEach { - it.didUpdateMTU(bluetoothPeripheral) + it.didUpdateMTU(bluetoothPeripheral, status) } } } diff --git a/library/src/commonMain/kotlin/dev/bluefalcon/BlueFalconDelegate.kt b/library/src/commonMain/kotlin/dev/bluefalcon/BlueFalconDelegate.kt index c6fb15f..c8a00cf 100644 --- a/library/src/commonMain/kotlin/dev/bluefalcon/BlueFalconDelegate.kt +++ b/library/src/commonMain/kotlin/dev/bluefalcon/BlueFalconDelegate.kt @@ -23,7 +23,7 @@ interface BlueFalconDelegate { @JsName("didRssiUpdate") fun didRssiUpdate(bluetoothPeripheral: BluetoothPeripheral) {} @JsName("didUpdateMTU") - fun didUpdateMTU(bluetoothPeripheral: BluetoothPeripheral) {} + fun didUpdateMTU(bluetoothPeripheral: BluetoothPeripheral, status: Int) {} @JsName("didReadDescriptor") fun didReadDescriptor( bluetoothPeripheral: BluetoothPeripheral, diff --git a/library/src/nativeMain/kotlin/dev/bluefalcon/BlueFalcon.kt b/library/src/nativeMain/kotlin/dev/bluefalcon/BlueFalcon.kt index c4c82b8..b15d2bc 100644 --- a/library/src/nativeMain/kotlin/dev/bluefalcon/BlueFalcon.kt +++ b/library/src/nativeMain/kotlin/dev/bluefalcon/BlueFalcon.kt @@ -221,12 +221,11 @@ actual class BlueFalcon actual constructor( } actual fun changeMTU(bluetoothPeripheral: BluetoothPeripheral, mtuSize: Int) { - var mtu = bluetoothPeripheral.bluetoothDevice.maximumWriteValueLengthForType(CBCharacteristicWriteWithResponse) - log?.debug("Change MTU size called but not needed: ${mtuSize}") - val btPeripheral = bluetoothPeripheral - btPeripheral.mtuSize = mtu.toInt() + val mtu = bluetoothPeripheral.bluetoothDevice.maximumWriteValueLengthForType(CBCharacteristicWriteWithResponse) + log?.debug("Change MTU size called but not needed for darwin platforms: $mtuSize:$mtu") + bluetoothPeripheral.mtuSize = mtu.toInt() delegates.forEach { - it.didUpdateMTU(btPeripheral) + it.didUpdateMTU(bluetoothPeripheral, 1) } } } \ No newline at end of file