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 fe8b777
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public final class com/juul/able/gatt/CoroutinesGatt : com/juul/able/gatt/Gatt {
public fun getServices ()Ljava/util/List;
public fun readCharacteristic (Landroid/bluetooth/BluetoothGattCharacteristic;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun readRemoteRssi (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun requestConnectionPriority (Lcom/juul/able/gatt/Priority;)Z
public fun requestMtu (ILkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun setCharacteristicNotification (Landroid/bluetooth/BluetoothGattCharacteristic;Z)Z
public fun toString ()Ljava/lang/String;
Expand All @@ -107,6 +108,7 @@ public abstract interface class com/juul/able/gatt/Gatt : com/juul/able/gatt/Gat
public abstract interface class com/juul/able/gatt/GattConnection {
public abstract fun disconnect (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun getOnConnectionStateChange ()Lkotlinx/coroutines/flow/Flow;
public abstract fun requestConnectionPriority (Lcom/juul/able/gatt/Priority;)Z
}

public abstract interface class com/juul/able/gatt/GattIo {
Expand Down Expand Up @@ -246,6 +248,14 @@ public final class com/juul/able/gatt/OnReadRemoteRssi : com/juul/able/gatt/HasG
public final class com/juul/able/gatt/OutOfOrderGattCallbackException : java/lang/IllegalStateException {
}

public final class com/juul/able/gatt/Priority : java/lang/Enum {
public static final field Balanced Lcom/juul/able/gatt/Priority;
public static final field High Lcom/juul/able/gatt/Priority;
public static final field Low Lcom/juul/able/gatt/Priority;
public static fun valueOf (Ljava/lang/String;)Lcom/juul/able/gatt/Priority;
public static fun values ()[Lcom/juul/able/gatt/Priority;
}

public final class com/juul/able/logger/AndroidLogger : com/juul/able/logger/Logger {
public fun <init> ()V
public fun isLoggable (I)Z
Expand Down
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: Priority
): 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 Priority.intValue: Int
get() = when (this) {
Priority.Low -> BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER
Priority.Balanced -> BluetoothGatt.CONNECTION_PRIORITY_BALANCED
Priority.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 Priority { Low, Balanced, High }

interface GattConnection {

@FlowPreview
val onConnectionStateChange: Flow<OnConnectionStateChange>

fun requestConnectionPriority(priority: Priority): Boolean

suspend fun disconnect(): Unit
}

Expand Down

0 comments on commit fe8b777

Please sign in to comment.