writable

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

Parameters

properties

the CharacteristicProperty.Writable of the characteristic. Must not be empty

encrypted

true if reading from the characteristic should be encrypted. This will result in Permission.WRITE_ENCRYPTION_REQUIRED. Otherwise will add Permission.WRITABLE

onFailedToWrite

the function to call when writing to the characteristic fails. This contains the com.splendo.kaluga.bluetooth.ConnectedDevice and the exception that caused deserialization to fail and should return a GattResponse.WriteResponse

onWrite

the function to call when reading from the characteristic. This contains the com.splendo.kaluga.bluetooth.ConnectedDevice, and the T to write and should return a GattResponse.WriteResponse. If the data being written is split over multiple offsets, this will only be called when the data can be fully deserialized

Type Parameters

T

the type of the data being written


inline fun <T : Any> LocalDescriptor.DSL.writable(encrypted: Boolean = false, bluetoothFormat: BluetoothFormat = BluetoothFormat, noinline onFailedToWrite: suspend LocalDescriptor.(ConnectedDevice, Exception) -> GattResponse.WriteResponse = { _, _ -> GattResponse.ApplicationError(0x80) }, noinline onWrite: suspend LocalDescriptor.(ConnectedDevice, T) -> GattResponse.WriteResponse)

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

Parameters

encrypted

true if reading from the descriptor should be encrypted. This will result in LocalCharacteristic.Permission.WRITE_ENCRYPTION_REQUIRED. Otherwise will add LocalCharacteristic.Permission.WRITABLE

onFailedToWrite

the function to call when writing to the descriptor fails. This contains the com.splendo.kaluga.bluetooth.ConnectedDevice and the exception that caused deserialization to fail and should return a GattResponse.WriteResponse

onWrite

the function to call when reading from the descriptor. This contains the com.splendo.kaluga.bluetooth.ConnectedDevice, and the T to write and should return a GattResponse.WriteResponse. If the data being written is split over multiple offsets, this will only be called when the data can be fully deserialized

Type Parameters

T

the type of the data being written