Dovydas
04/20/2025, 3:28 PMDovydas
04/20/2025, 3:29 PMinterface MetaWearDevice {
companion object {
private val _connectionState = MutableStateFlow(false)
}
val connectionState: Flow<Boolean> get() = _connectionState
val isConnected: Boolean get() = _connectionState.value
// This notation effectively makes the function protected
/** Needs to be called inside connect and disconnect functions */
fun MetaWearDevice.changeConnectionState(state: Boolean) {
_connectionState.value = state
}
/** This function should also register a callback that sets the connection state to false when the device disconnects */
suspend fun connect()
Have to override or it doesn't conform to the protocol
class MetaWearDeviceImpl : MetaWearDevice {
var connectionState: any Kotlinx_coroutines_coreFlow
var isConnected: Bool
func changeConnectionState(_ receiver: any MetaWearDevice, state: Bool) {
<#code#>
}
Dovydas
04/20/2025, 4:03 PMval MetaWearDevice.isConnected: Boolean get() = this.connectionState.value
/** Needs to be called inside connect and disconnect functions */
fun MetaWearDevice.changeConnectionState(state: Boolean) {
this.connectionState.value = state
}
Dovydas
04/20/2025, 4:53 PMFrançois
04/21/2025, 7:07 AM