diff --git a/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/DeviceConstructor.kt b/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/DeviceConstructor.kt index 820f6ef..63b5303 100644 --- a/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/DeviceConstructor.kt +++ b/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/DeviceConstructor.kt @@ -54,7 +54,7 @@ public abstract class DeviceConstructor( /** * Register a property and provide a direct reader for it */ - public fun > property( + public fun > property( state: S, descriptorBuilder: PropertyDescriptor.() -> Unit = {}, nameOverride: String? = null, @@ -104,7 +104,7 @@ public abstract class DeviceConstructor( /** * Create and register a virtual mutable property with optional [callback] */ - public fun virtualProperty( + public fun virtualProperty( metaConverter: MetaConverter, initialState: T, descriptorBuilder: PropertyDescriptor.() -> Unit = {}, diff --git a/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/DeviceGroup.kt b/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/DeviceGroup.kt index 6cdb784..ca05c27 100644 --- a/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/DeviceGroup.kt +++ b/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/DeviceGroup.kt @@ -28,7 +28,7 @@ public open class DeviceGroup( ) : DeviceHub, CachingDevice { internal class Property( - val state: DeviceState, + val state: DeviceState<*>, val descriptor: PropertyDescriptor, ) @@ -82,7 +82,7 @@ public open class DeviceGroup( /** * Register a new property based on [DeviceState]. Properties could be modified dynamically */ - public fun registerProperty(descriptor: PropertyDescriptor, state: DeviceState) { + public fun registerProperty(descriptor: PropertyDescriptor, state: DeviceState<*>) { val name = descriptor.name.parseAsName() require(properties[name] == null) { "Can't add property with name $name. It already exists." } properties[name] = Property(state, descriptor) diff --git a/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/DeviceState.kt b/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/DeviceState.kt index 1219210..faa7b2f 100644 --- a/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/DeviceState.kt +++ b/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/DeviceState.kt @@ -50,7 +50,7 @@ public operator fun MutableDeviceState.setValue(thisRef: Any?, property: this.value = value } -public var MutableDeviceState.valueAsMeta: Meta +public var MutableDeviceState.valueAsMeta: Meta get() = converter.convert(value) set(arg) { value = converter.read(arg) diff --git a/controls-vision/src/commonMain/kotlin/plotExtensions.kt b/controls-vision/src/commonMain/kotlin/plotExtensions.kt index 4cfa49b..804fe9d 100644 --- a/controls-vision/src/commonMain/kotlin/plotExtensions.kt +++ b/controls-vision/src/commonMain/kotlin/plotExtensions.kt @@ -184,18 +184,16 @@ public fun Plot.plotBooleanState( private fun Flow.chunkedByPeriod(duration: Duration): Flow> { val collector: ArrayDeque = ArrayDeque() return channelFlow { - coroutineScope { - launch { - while (isActive) { - delay(duration) - send(ArrayList(collector)) - collector.clear() - } - } - this@chunkedByPeriod.collect { - collector.add(it) + launch { + while (isActive) { + delay(duration) + send(ArrayList(collector)) + collector.clear() } } + this@chunkedByPeriod.collect { + collector.add(it) + } } } @@ -224,7 +222,7 @@ public fun Plot.plotAveragedDeviceProperty( ): Job = scatter(configuration).run { val data = TimeData() device.propertyMessageFlow(propertyName).chunkedByPeriod(averagingInterval).transform { eventList -> - if(eventList.isEmpty()){ + if (eventList.isEmpty()) { data.append(Clock.System.now(), missingValue.asValue()) } else { val time = eventList.map { it.time }.averageTime()