Safe Bluetooth
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.
Properties
Functions
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun asyncReadCharacteristic(c: BluetoothGattCharacteristic, cb: (Result<BluetoothGattCharacteristic>) -> Unit)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun asyncWriteCharacteristic(c: BluetoothGattCharacteristic, v: ByteArray, cb: (Result<BluetoothGattCharacteristic>) -> Unit)
Link copied to clipboard
fun asyncWriteDescriptor(c: BluetoothGattDescriptor, value: ByteArray, cb: (Result<BluetoothGattDescriptor>) -> Unit)
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 setNotify(c: BluetoothGattCharacteristic, enable: Boolean, onChanged: (BluetoothGattCharacteristic) -> Unit)