Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions kable-core/src/androidMain/kotlin/AndroidPeripheral.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ public interface AndroidPeripheral : Peripheral {
* @throws GattRequestRejectedException if Android was unable to fulfill the MTU change request.
* @throws GattStatusException if MTU change request failed.
*/
@Deprecated(

)
public suspend fun requestMtu(mtu: Int): Int

/**
Expand Down
17 changes: 17 additions & 0 deletions kable-core/src/commonMain/kotlin/PeripheralBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import kotlinx.coroutines.flow.StateFlow
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

private val MTU_RANGE = 23..517

public expect class ServicesDiscoveredPeripheral {

public suspend fun read(
Expand All @@ -31,12 +33,27 @@ public class ObservationExceptionPeripheral internal constructor(peripheral: Per
public val state: StateFlow<State> = peripheral.state
}

public class AndroidConfiguration {
/** The MTU to request upon connecting to remote peripheral. */
public var mtu: Int? = null
set(value) {
if (value != null) {
require(value in MTU_RANGE) { "MTU must be within $MTU_RANGE, $value was requested" }
}
field = value
}
}

internal typealias OnAndroidBuilder = AndroidConfiguration.() -> Unit
internal typealias ServicesDiscoveredAction = suspend ServicesDiscoveredPeripheral.() -> Unit
internal typealias ObservationExceptionHandler = suspend ObservationExceptionPeripheral.(cause: Exception) -> Unit

internal val defaultDisconnectTimeout = 5.seconds

public expect class PeripheralBuilder internal constructor() {

public fun onAndroid(action: OnAndroidBuilder)

public fun logging(init: LoggingBuilder)

/**
Expand Down