DSL

interface DSL

DSL for setting up a LocalCharacteristic

Types

Link copied to clipboard

Sets up notification to notify all com.splendo.kaluga.bluetooth.ConnectedDevice of changes to this LocalCharacteristic whenever a Trigger fires

Functions

Link copied to clipboard
open fun <T> SharedFlow<T>.collectTo(scope: CoroutineScope, notification: LocalCharacteristic.DSL.NotificationDSL<T>.() -> Unit)

Collects a SharedFlow of T and notifies any subscribed com.splendo.kaluga.bluetooth.ConnectedDevice of any changes. Results in a call to notifiable that may only be called once

open fun <T> StateFlow<T>.collectTo(scope: CoroutineScope, notification: LocalCharacteristic.DSL.NotificationDSL<T>.() -> Unit)

Collects a StateFlow of T and notifies any subscribed com.splendo.kaluga.bluetooth.ConnectedDevice of any changes. Results in a call to notifiable that may only be called once

open fun <T> Flow<T>.collectTo(scope: CoroutineScope, started: SharingStarted, replay: Int = 0, notification: LocalCharacteristic.DSL.NotificationDSL<T>.() -> Unit)

Collects a Flow of T and notifies any subscribed com.splendo.kaluga.bluetooth.ConnectedDevice of any changes. Results in a call to notifiable that may only be called once

Link copied to clipboard
open fun <T> ReceiveChannel<T>.consumeTo(scope: CoroutineScope, notification: LocalCharacteristic.DSL.NotificationDSL<T>.() -> Unit)

Consumes a ReceiveChannel of T and notifies any subscribed com.splendo.kaluga.bluetooth.ConnectedDevice of any changes. Results in a call to notifiable that may only be called once

Link copied to clipboard
abstract fun descriptor(uuid: UUID, descriptor: LocalDescriptor.DSL.() -> Unit)
open fun descriptor(uuidString: String, descriptor: LocalDescriptor.DSL.() -> Unit)

Adds a LocalDescriptor to the characteristic being built This is not supported on iOS and will be ignored there.

Link copied to clipboard
abstract fun notifiable(properties: Set<CharacteristicProperty.Notifiable> = setOf(CharacteristicProperty.Notify), encrypted: Boolean = false, onSubscribe: LocalCharacteristic.Notifiable.(ConnectedDevice) -> Unit, onUnsubscribe: LocalCharacteristic.Notifiable.(ConnectedDevice) -> Unit)

Makes this LocalCharacteristic a LocalCharacteristic.Notifiable This method can only be called once.

Link copied to clipboard
abstract fun readable(encrypted: Boolean = false, onRead: suspend LocalCharacteristic.(ConnectedDevice, Int) -> GattResponse.ReadResponse)

Makes this LocalCharacteristic readable by a com.splendo.kaluga.bluetooth.ConnectedDevice Cannot be called if readable, or readableAlwaysSuccess has been called before

Link copied to clipboard
open fun readableAlwaysSuccess(encrypted: Boolean = false, onRead: suspend LocalCharacteristic.(ConnectedDevice, Int) -> ByteArray)
open fun <T> readableAlwaysSuccess(encrypted: Boolean = false, serializationStrategy: SerializationStrategy<T>, bluetoothFormat: BluetoothFormat = BluetoothFormat, onRead: suspend LocalCharacteristic.(ConnectedDevice) -> T)

Makes this LocalCharacteristic readable by a com.splendo.kaluga.bluetooth.ConnectedDevice to always return GattResponse.ReadSuccess Cannot be called if readable, or readableAlwaysSuccess has been called before

Link copied to clipboard
inline fun <T : Any> LocalCharacteristic.DSL.readableAlwaysSuccess(encrypted: Boolean = false, bluetoothFormat: BluetoothFormat = BluetoothFormat, noinline onRead: suspend LocalCharacteristic.(ConnectedDevice) -> T)

Makes this LocalCharacteristic readable by a com.splendo.kaluga.bluetooth.ConnectedDevice to always return GattResponse.ReadSuccess Cannot be called if LocalCharacteristic.DSL.readable, or LocalCharacteristic.DSL.readableAlwaysSuccess has been called before

Link copied to clipboard
abstract fun writable(properties: Set<CharacteristicProperty.Writable> = setOf(CharacteristicProperty.Write), encrypted: Boolean = false, onWrite: suspend LocalCharacteristic.(ConnectedDevice, ByteArray, Int) -> GattResponse.WriteResponse)
open fun <T> writable(properties: Set<CharacteristicProperty.Writable> = setOf(CharacteristicProperty.Write), encrypted: Boolean = false, deserializationStrategy: DeserializationStrategy<T>, bluetoothFormat: BluetoothFormat = BluetoothFormat, onFailedToWrite: suspend LocalCharacteristic.(ConnectedDevice, Exception) -> GattResponse.WriteResponse = { _, _ -> GattResponse.ApplicationError(0x80) }, onWrite: suspend LocalCharacteristic.(ConnectedDevice, T) -> GattResponse.WriteResponse)

Makes this LocalCharacteristic writable by a com.splendo.kaluga.bluetooth.ConnectedDevice Cannot be called if writable or writableAlwaysSuccess has been called before

Link copied to clipboard
inline fun <T : Any> LocalCharacteristic.DSL.writable(properties: Set<CharacteristicProperty.Writable> = setOf(CharacteristicProperty.Write), encrypted: Boolean = false, bluetoothFormat: BluetoothFormat = BluetoothFormat, noinline onFailedToWrite: suspend LocalCharacteristic.(ConnectedDevice, Exception) -> GattResponse.WriteResponse = { _, _ -> GattResponse.ApplicationError(0x80) }, noinline onWrite: suspend LocalCharacteristic.(ConnectedDevice, T) -> GattResponse.WriteResponse)

Makes this LocalCharacteristic writable by a com.splendo.kaluga.bluetooth.ConnectedDevice Cannot be called if writable has been called before

Link copied to clipboard
open fun writableAlwaysSuccess(properties: Set<CharacteristicProperty.Writable> = setOf(CharacteristicProperty.Write), encrypted: Boolean = false, onWrite: suspend LocalCharacteristic.(ConnectedDevice, ByteArray, Int) -> Unit)
open fun <T> writableAlwaysSuccess(properties: Set<CharacteristicProperty.Writable> = setOf(CharacteristicProperty.Write), encrypted: Boolean = false, deserializationStrategy: DeserializationStrategy<T>, bluetoothFormat: BluetoothFormat = BluetoothFormat, onWrite: suspend LocalCharacteristic.(ConnectedDevice, T) -> Unit)

Makes this LocalCharacteristic writable by a com.splendo.kaluga.bluetooth.ConnectedDevice and always responds with GattResponse.WriteSuccess Cannot be called if writable or writableAlwaysSuccess has been called before

Link copied to clipboard
inline fun <T : Any> LocalCharacteristic.DSL.writableAlwaysSuccess(properties: Set<CharacteristicProperty.Writable> = setOf(CharacteristicProperty.Write), encrypted: Boolean = false, bluetoothFormat: BluetoothFormat = BluetoothFormat, noinline onWrite: suspend LocalCharacteristic.(ConnectedDevice, T) -> Unit)

Makes this LocalCharacteristic writable by a com.splendo.kaluga.bluetooth.ConnectedDevice and always responds with GattResponse.WriteSuccess Cannot be called if writable has been called before