Skip to content

Commit

Permalink
Added mtu status on callback (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reedyuk authored Jan 29, 2025
1 parent 5119887 commit a505e6a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class BleDelegate: BlueFalconDelegate {
override fun didRssiUpdate(bluetoothPeripheral: BluetoothPeripheral) {
}

override fun didUpdateMTU(bluetoothPeripheral: BluetoothPeripheral) {
override fun didUpdateMTU(bluetoothPeripheral: BluetoothPeripheral, status: Int) {

}

Expand Down
2 changes: 1 addition & 1 deletion examples/KotlinMP-Example/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion library/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions library/src/androidMain/kotlin/dev/bluefalcon/BlueFalcon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions library/src/nativeMain/kotlin/dev/bluefalcon/BlueFalcon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit a505e6a

Please sign in to comment.