Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
Add requestConnectionPriority
Browse files Browse the repository at this point in the history
  • Loading branch information
twyatt committed Dec 4, 2020
1 parent cf48141 commit 4f1a055
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/src/main/java/gatt/CoroutinesGatt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class CoroutinesGatt internal constructor(
override val services: List<BluetoothGattService> get() = bluetoothGatt.services
override fun getService(uuid: UUID): BluetoothGattService? = bluetoothGatt.getService(uuid)

override fun requestConnectionPriority(
priority: ConnectionPriority
): Boolean = bluetoothGatt.requestConnectionPriority(priority.intValue)

override suspend fun disconnect() {
try {
Able.info { "Disconnecting $this" }
Expand Down Expand Up @@ -157,3 +161,10 @@ class CoroutinesGatt internal constructor(

override fun toString(): String = "CoroutinesGatt(device=${bluetoothGatt.device})"
}

private val ConnectionPriority.intValue: Int
get() = when (this) {
ConnectionPriority.Low -> BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER
ConnectionPriority.Balanced -> BluetoothGatt.CONNECTION_PRIORITY_BALANCED
ConnectionPriority.High -> BluetoothGatt.CONNECTION_PRIORITY_HIGH
}
4 changes: 4 additions & 0 deletions core/src/main/java/gatt/GattConnection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ typealias GattConnectionStatus = Int
*/
typealias GattConnectionState = Int

enum class ConnectionPriority { Low, Balanced, High }

interface GattConnection {

@FlowPreview
val onConnectionStateChange: Flow<OnConnectionStateChange>

fun requestConnectionPriority(priority: ConnectionPriority): Boolean

suspend fun disconnect(): Unit
}

Expand Down

0 comments on commit 4f1a055

Please sign in to comment.