SafeBluetooth

class SafeBluetooth(context: Context, device: BluetoothDevice, analytics: PlatformAnalytics) : Closeable(source)

Uses coroutines to safely access a bluetooth GATT device with a synchronous API

The BTLE API on android is dumb. You can only have one outstanding operation in flight to the device. If you try to do something when something is pending, the operation just returns false. You are expected to chain your operations from the results callbacks.

This class fixes the API by using coroutines to let you safely do a series of BTLE operations.

Constructors

Link copied to clipboard
constructor(context: Context, device: BluetoothDevice, analytics: PlatformAnalytics)

Types

Link copied to clipboard
class BLEStatusException(val status: Int, msg: String) : BLEException

A BLE status code based error

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun asyncConnect(autoConnect: Boolean = false, cb: (Result<Unit>) -> Unit, lostConnectCb: () -> Unit)

start a connection attempt.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun asyncRequestMtu(len: Int, cb: (Result<Unit>) -> Unit)
Link copied to clipboard
Link copied to clipboard
open override fun close()

Close and destroy this SafeBluetooth instance. You'll need to make a new instance before using it again

Link copied to clipboard

Close down any existing connection, any existing calls (including async connects will be cancelled and you'll need to recall connect to use this againt

Link copied to clipboard
fun closeGatt()

Close just the GATT device but keep our pending callbacks active

Link copied to clipboard
fun connect(autoConnect: Boolean = false)
Link copied to clipboard