From b539c2046a8237acab772d65080485a2a26c8077 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 18 Nov 2023 14:49:23 +0300 Subject: [PATCH] `DeviceSpec` properties no explicitly pass property name to getters and setters --- CHANGELOG.md | 1 + .../controls/constructor/Regulator.kt | 5 +- .../kscience/controls/api/descriptors.kt | 2 +- .../kscience/controls/spec/DeviceSpec.kt | 141 +++++++----------- .../controls/spec/deviceExtensions.kt | 2 +- .../controls/spec/propertySpecDelegates.kt | 32 ++-- .../controls/spec/propertyReflection.kt | 8 + .../controls/opcua/client/OpcUaClientTest.kt | 4 +- .../commonMain/kotlin/ControlVisionPlugin.kt | 19 +++ .../src/commonMain/kotlin/IndicatorVision.kt | 20 +++ .../jsMain/kotlin/ControlsVisionPlugin.js.kt | 33 ++++ .../kotlin/ControlsVisionPlugin.jvm.kt | 21 +++ .../kscience/controls/demo/DemoDevice.kt | 6 +- .../kscience/controls/demo/car/IVirtualCar.kt | 2 + .../sciprog/devices/mks/MksPdr900Device.kt | 2 +- .../pimotionmaster/PiMotionMasterDevice.kt | 12 +- 16 files changed, 185 insertions(+), 125 deletions(-) create mode 100644 controls-core/src/jvmMain/kotlin/space/kscience/controls/spec/propertyReflection.kt create mode 100644 controls-vision/src/commonMain/kotlin/ControlVisionPlugin.kt create mode 100644 controls-vision/src/commonMain/kotlin/IndicatorVision.kt create mode 100644 controls-vision/src/jsMain/kotlin/ControlsVisionPlugin.js.kt create mode 100644 controls-vision/src/jvmMain/kotlin/ControlsVisionPlugin.jvm.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 4083a94..abf5789 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Changed - Property caching moved from core `Device` to the `CachingDevice` +- `DeviceSpec` properties no explicitly pass property name to getters and setters. ### Deprecated diff --git a/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/Regulator.kt b/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/Regulator.kt index 71cb3b0..7495d33 100644 --- a/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/Regulator.kt +++ b/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/Regulator.kt @@ -1,10 +1,7 @@ package space.kscience.controls.constructor import space.kscience.controls.api.Device -import space.kscience.controls.spec.DevicePropertySpec -import space.kscience.controls.spec.DeviceSpec -import space.kscience.controls.spec.MutableDevicePropertySpec -import space.kscience.controls.spec.doubleProperty +import space.kscience.controls.spec.* import space.kscience.dataforge.meta.transformations.MetaConverter diff --git a/controls-core/src/commonMain/kotlin/space/kscience/controls/api/descriptors.kt b/controls-core/src/commonMain/kotlin/space/kscience/controls/api/descriptors.kt index 6f7d27c..2adb89a 100644 --- a/controls-core/src/commonMain/kotlin/space/kscience/controls/api/descriptors.kt +++ b/controls-core/src/commonMain/kotlin/space/kscience/controls/api/descriptors.kt @@ -27,6 +27,6 @@ public fun PropertyDescriptor.metaDescriptor(block: MetaDescriptorBuilder.()->Un */ @Serializable public class ActionDescriptor(public val name: String) { - public var info: String? = null + public var description: String? = null } diff --git a/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/DeviceSpec.kt b/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/DeviceSpec.kt index 55122d9..b5813b7 100644 --- a/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/DeviceSpec.kt +++ b/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/DeviceSpec.kt @@ -44,64 +44,11 @@ public abstract class DeviceSpec { return deviceProperty } - public fun property( + public inline fun property( converter: MetaConverter, - readOnlyProperty: KProperty1, - descriptorBuilder: PropertyDescriptor.() -> Unit = {}, - ): PropertyDelegateProvider, ReadOnlyProperty>> = - PropertyDelegateProvider { _, property -> - val deviceProperty = object : DevicePropertySpec { - override val descriptor: PropertyDescriptor = PropertyDescriptor(property.name).apply { - //TODO add type from converter - mutable = true - }.apply(descriptorBuilder) - - override val converter: MetaConverter = converter - - override suspend fun read(device: D): T = withContext(device.coroutineContext) { - readOnlyProperty.get(device) - } - } - registerProperty(deviceProperty) - ReadOnlyProperty { _, _ -> - deviceProperty - } - } - - public fun mutableProperty( - converter: MetaConverter, - readWriteProperty: KMutableProperty1, - descriptorBuilder: PropertyDescriptor.() -> Unit = {}, - ): PropertyDelegateProvider, ReadOnlyProperty>> = - PropertyDelegateProvider { _, property -> - val deviceProperty = object : MutableDevicePropertySpec { - - override val descriptor: PropertyDescriptor = PropertyDescriptor(property.name).apply { - //TODO add the type from converter - mutable = true - }.apply(descriptorBuilder) - - override val converter: MetaConverter = converter - - override suspend fun read(device: D): T = withContext(device.coroutineContext) { - readWriteProperty.get(device) - } - - override suspend fun write(device: D, value: T): Unit = withContext(device.coroutineContext) { - readWriteProperty.set(device, value) - } - } - registerProperty(deviceProperty) - ReadOnlyProperty { _, _ -> - deviceProperty - } - } - - public fun property( - converter: MetaConverter, - descriptorBuilder: PropertyDescriptor.() -> Unit = {}, + crossinline descriptorBuilder: PropertyDescriptor.() -> Unit = {}, name: String? = null, - read: suspend D.() -> T?, + crossinline read: suspend D.(propertyName: String) -> T?, ): PropertyDelegateProvider, ReadOnlyProperty, DevicePropertySpec>> = PropertyDelegateProvider { _: DeviceSpec, property -> val propertyName = name ?: property.name @@ -109,7 +56,7 @@ public abstract class DeviceSpec { override val descriptor: PropertyDescriptor = PropertyDescriptor(propertyName).apply(descriptorBuilder) override val converter: MetaConverter = converter - override suspend fun read(device: D): T? = withContext(device.coroutineContext) { device.read() } + override suspend fun read(device: D): T? = withContext(device.coroutineContext) { device.read(propertyName) } } registerProperty(deviceProperty) ReadOnlyProperty, DevicePropertySpec> { _, _ -> @@ -117,27 +64,30 @@ public abstract class DeviceSpec { } } - public fun mutableProperty( + public inline fun mutableProperty( converter: MetaConverter, - descriptorBuilder: PropertyDescriptor.() -> Unit = {}, + crossinline descriptorBuilder: PropertyDescriptor.() -> Unit = {}, name: String? = null, - read: suspend D.() -> T?, - write: suspend D.(T) -> Unit, + crossinline read: suspend D.(propertyName: String) -> T?, + crossinline write: suspend D.(propertyName: String, value: T) -> Unit, ): PropertyDelegateProvider, ReadOnlyProperty, MutableDevicePropertySpec>> = PropertyDelegateProvider { _: DeviceSpec, property: KProperty<*> -> val propertyName = name ?: property.name val deviceProperty = object : MutableDevicePropertySpec { - override val descriptor: PropertyDescriptor = PropertyDescriptor(propertyName, mutable = true) - .apply(descriptorBuilder) + override val descriptor: PropertyDescriptor = PropertyDescriptor( + propertyName, + mutable = true + ).apply(descriptorBuilder) override val converter: MetaConverter = converter - override suspend fun read(device: D): T? = withContext(device.coroutineContext) { device.read() } + override suspend fun read(device: D): T? = + withContext(device.coroutineContext) { device.read(propertyName) } override suspend fun write(device: D, value: T): Unit = withContext(device.coroutineContext) { - device.write(value) + device.write(propertyName, value) } } - _properties[propertyName] = deviceProperty + registerProperty(deviceProperty) ReadOnlyProperty, MutableDevicePropertySpec> { _, _ -> deviceProperty } @@ -209,33 +159,42 @@ public abstract class DeviceSpec { } } +public inline fun DeviceSpec.property( + converter: MetaConverter, + readOnlyProperty: KProperty1, + crossinline descriptorBuilder: PropertyDescriptor.() -> Unit = {}, +): PropertyDelegateProvider, ReadOnlyProperty, DevicePropertySpec>> = property( + converter, + descriptorBuilder, + name = readOnlyProperty.name, + read = { readOnlyProperty.get(this) } +) + +public inline fun DeviceSpec.mutableProperty( + converter: MetaConverter, + readWriteProperty: KMutableProperty1, + crossinline descriptorBuilder: PropertyDescriptor.() -> Unit = {}, +): PropertyDelegateProvider, ReadOnlyProperty, MutableDevicePropertySpec>> = + mutableProperty( + converter, + descriptorBuilder, + readWriteProperty.name, + read = { _ -> readWriteProperty.get(this) }, + write = { _, value: T -> readWriteProperty.set(this, value) } + ) /** - * Register a mutable logical property for a device + * Register a mutable logical property (without a corresponding physical state) for a device */ -@OptIn(InternalDeviceAPI::class) -public fun > DeviceSpec.logicalProperty( +public inline fun > DeviceSpec.logicalProperty( converter: MetaConverter, - descriptorBuilder: PropertyDescriptor.() -> Unit = {}, + crossinline descriptorBuilder: PropertyDescriptor.() -> Unit = {}, name: String? = null, -): PropertyDelegateProvider, ReadOnlyProperty>> = - PropertyDelegateProvider { _, property -> - val deviceProperty = object : MutableDevicePropertySpec { - val propertyName = name ?: property.name - override val descriptor: PropertyDescriptor = PropertyDescriptor(propertyName).apply { - //TODO add type from converter - mutable = true - }.apply(descriptorBuilder) - - override val converter: MetaConverter = converter - - override suspend fun read(device: D): T? = device.getProperty(propertyName)?.let(converter::metaToObject) - - override suspend fun write(device: D, value: T): Unit = - device.writeProperty(propertyName, converter.objectToMeta(value)) - } - registerProperty(deviceProperty) - ReadOnlyProperty { _, _ -> - deviceProperty - } - } \ No newline at end of file +): PropertyDelegateProvider, ReadOnlyProperty, MutableDevicePropertySpec>> = + mutableProperty( + converter, + descriptorBuilder, + name, + read = { propertyName -> getProperty(propertyName)?.let(converter::metaToObject) }, + write = { propertyName, value -> writeProperty(propertyName, converter.objectToMeta(value)) } + ) \ No newline at end of file diff --git a/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/deviceExtensions.kt b/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/deviceExtensions.kt index af42f60..fefb65e 100644 --- a/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/deviceExtensions.kt +++ b/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/deviceExtensions.kt @@ -12,7 +12,7 @@ import kotlin.time.Duration /** * Perform a recurring asynchronous read action and return a flow of results. * The flow is lazy, so action is not performed unless flow is consumed. - * The flow uses called context. In order to call it on device context, use `flowOn(coroutineContext)`. + * The flow uses caller context. To call it on device context, use `flowOn(coroutineContext)`. * * The flow is canceled when the device scope is canceled */ diff --git a/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/propertySpecDelegates.kt b/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/propertySpecDelegates.kt index 70ef94a..8314838 100644 --- a/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/propertySpecDelegates.kt +++ b/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/propertySpecDelegates.kt @@ -14,7 +14,7 @@ import kotlin.properties.ReadOnlyProperty public fun DeviceSpec.booleanProperty( descriptorBuilder: PropertyDescriptor.() -> Unit = {}, name: String? = null, - read: suspend D.() -> Boolean? + read: suspend D.(propertyName: String) -> Boolean? ): PropertyDelegateProvider, ReadOnlyProperty, DevicePropertySpec>> = property( MetaConverter.boolean, { @@ -37,9 +37,9 @@ private inline fun numberDescriptor( } public fun DeviceSpec.numberProperty( - name: String? = null, descriptorBuilder: PropertyDescriptor.() -> Unit = {}, - read: suspend D.() -> Number? + name: String? = null, + read: suspend D.(propertyName: String) -> Number? ): PropertyDelegateProvider, ReadOnlyProperty, DevicePropertySpec>> = property( MetaConverter.number, numberDescriptor(descriptorBuilder), @@ -50,7 +50,7 @@ public fun DeviceSpec.numberProperty( public fun DeviceSpec.doubleProperty( descriptorBuilder: PropertyDescriptor.() -> Unit = {}, name: String? = null, - read: suspend D.() -> Double? + read: suspend D.(propertyName: String) -> Double? ): PropertyDelegateProvider, ReadOnlyProperty, DevicePropertySpec>> = property( MetaConverter.double, numberDescriptor(descriptorBuilder), @@ -61,7 +61,7 @@ public fun DeviceSpec.doubleProperty( public fun DeviceSpec.stringProperty( descriptorBuilder: PropertyDescriptor.() -> Unit = {}, name: String? = null, - read: suspend D.() -> String? + read: suspend D.(propertyName: String) -> String? ): PropertyDelegateProvider, ReadOnlyProperty, DevicePropertySpec>> = property( MetaConverter.string, { @@ -77,7 +77,7 @@ public fun DeviceSpec.stringProperty( public fun DeviceSpec.metaProperty( descriptorBuilder: PropertyDescriptor.() -> Unit = {}, name: String? = null, - read: suspend D.() -> Meta? + read: suspend D.(propertyName: String) -> Meta? ): PropertyDelegateProvider, ReadOnlyProperty, DevicePropertySpec>> = property( MetaConverter.meta, { @@ -95,8 +95,8 @@ public fun DeviceSpec.metaProperty( public fun DeviceSpec.booleanProperty( descriptorBuilder: PropertyDescriptor.() -> Unit = {}, name: String? = null, - read: suspend D.() -> Boolean?, - write: suspend D.(Boolean) -> Unit + read: suspend D.(propertyName: String) -> Boolean?, + write: suspend D.(propertyName: String, value: Boolean) -> Unit ): PropertyDelegateProvider, ReadOnlyProperty, MutableDevicePropertySpec>> = mutableProperty( MetaConverter.boolean, @@ -115,31 +115,31 @@ public fun DeviceSpec.booleanProperty( public fun DeviceSpec.numberProperty( descriptorBuilder: PropertyDescriptor.() -> Unit = {}, name: String? = null, - read: suspend D.() -> Number, - write: suspend D.(Number) -> Unit + read: suspend D.(propertyName: String) -> Number, + write: suspend D.(propertyName: String, value: Number) -> Unit ): PropertyDelegateProvider, ReadOnlyProperty, MutableDevicePropertySpec>> = mutableProperty(MetaConverter.number, numberDescriptor(descriptorBuilder), name, read, write) public fun DeviceSpec.doubleProperty( descriptorBuilder: PropertyDescriptor.() -> Unit = {}, name: String? = null, - read: suspend D.() -> Double, - write: suspend D.(Double) -> Unit + read: suspend D.(propertyName: String) -> Double, + write: suspend D.(propertyName: String, value: Double) -> Unit ): PropertyDelegateProvider, ReadOnlyProperty, MutableDevicePropertySpec>> = mutableProperty(MetaConverter.double, numberDescriptor(descriptorBuilder), name, read, write) public fun DeviceSpec.stringProperty( descriptorBuilder: PropertyDescriptor.() -> Unit = {}, name: String? = null, - read: suspend D.() -> String, - write: suspend D.(String) -> Unit + read: suspend D.(propertyName: String) -> String, + write: suspend D.(propertyName: String, value: String) -> Unit ): PropertyDelegateProvider, ReadOnlyProperty, MutableDevicePropertySpec>> = mutableProperty(MetaConverter.string, descriptorBuilder, name, read, write) public fun DeviceSpec.metaProperty( descriptorBuilder: PropertyDescriptor.() -> Unit = {}, name: String? = null, - read: suspend D.() -> Meta, - write: suspend D.(Meta) -> Unit + read: suspend D.(propertyName: String) -> Meta, + write: suspend D.(propertyName: String, value: Meta) -> Unit ): PropertyDelegateProvider, ReadOnlyProperty, MutableDevicePropertySpec>> = mutableProperty(MetaConverter.meta, descriptorBuilder, name, read, write) \ No newline at end of file diff --git a/controls-core/src/jvmMain/kotlin/space/kscience/controls/spec/propertyReflection.kt b/controls-core/src/jvmMain/kotlin/space/kscience/controls/spec/propertyReflection.kt new file mode 100644 index 0000000..1d4cb56 --- /dev/null +++ b/controls-core/src/jvmMain/kotlin/space/kscience/controls/spec/propertyReflection.kt @@ -0,0 +1,8 @@ +package space.kscience.controls.spec + +import space.kscience.controls.api.PropertyDescriptor +import kotlin.reflect.KProperty + +internal fun PropertyDescriptor.fromSpec(property: KProperty<*>){ + property.annotations +} \ No newline at end of file diff --git a/controls-opcua/src/test/kotlin/space/kscience/controls/opcua/client/OpcUaClientTest.kt b/controls-opcua/src/test/kotlin/space/kscience/controls/opcua/client/OpcUaClientTest.kt index 8537449..33aa8fb 100644 --- a/controls-opcua/src/test/kotlin/space/kscience/controls/opcua/client/OpcUaClientTest.kt +++ b/controls-opcua/src/test/kotlin/space/kscience/controls/opcua/client/OpcUaClientTest.kt @@ -29,7 +29,7 @@ class OpcUaClientTest { return DemoOpcUaDevice(config) } - val randomDouble by doubleProperty(read = DemoOpcUaDevice::readRandomDouble) + val randomDouble by doubleProperty { readRandomDouble() } } @@ -42,7 +42,7 @@ class OpcUaClientTest { fun testReadDouble() = runTest { val device = DemoOpcUaDevice.build() device.start() - println(device.read(DemoOpcUaDevice.randomDouble)) + println(device.read(DemoOpcUaDevice.randomDouble)) device.stop() } diff --git a/controls-vision/src/commonMain/kotlin/ControlVisionPlugin.kt b/controls-vision/src/commonMain/kotlin/ControlVisionPlugin.kt new file mode 100644 index 0000000..d587250 --- /dev/null +++ b/controls-vision/src/commonMain/kotlin/ControlVisionPlugin.kt @@ -0,0 +1,19 @@ +package space.kscience.controls.vision + +import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.modules.polymorphic +import kotlinx.serialization.modules.subclass +import space.kscience.dataforge.context.PluginFactory +import space.kscience.visionforge.Vision +import space.kscience.visionforge.VisionPlugin +import space.kscience.visionforge.plotly.VisionOfPlotly + +public expect class ControlVisionPlugin: VisionPlugin{ + public companion object: PluginFactory +} + +internal val controlsVisionSerializersModule = SerializersModule { + polymorphic(Vision::class) { + subclass(VisionOfPlotly.serializer()) + } +} \ No newline at end of file diff --git a/controls-vision/src/commonMain/kotlin/IndicatorVision.kt b/controls-vision/src/commonMain/kotlin/IndicatorVision.kt new file mode 100644 index 0000000..9ec2319 --- /dev/null +++ b/controls-vision/src/commonMain/kotlin/IndicatorVision.kt @@ -0,0 +1,20 @@ +package space.kscience.controls.vision + +import space.kscience.dataforge.meta.Meta +import space.kscience.dataforge.meta.node +import space.kscience.visionforge.AbstractVision +import space.kscience.visionforge.Vision + +/** + * A [Vision] that shows an indicator + */ +public class IndicatorVision: AbstractVision() { + public val value: Meta? by properties.node() +} + +///** +// * A [Vision] that allows both showing the value and changing it +// */ +//public interface RegulatorVision: IndicatorVision{ +// +//} \ No newline at end of file diff --git a/controls-vision/src/jsMain/kotlin/ControlsVisionPlugin.js.kt b/controls-vision/src/jsMain/kotlin/ControlsVisionPlugin.js.kt new file mode 100644 index 0000000..0d928ac --- /dev/null +++ b/controls-vision/src/jsMain/kotlin/ControlsVisionPlugin.js.kt @@ -0,0 +1,33 @@ +package space.kscience.controls.vision + +import kotlinx.serialization.modules.SerializersModule +import org.w3c.dom.Element +import space.kscience.dataforge.context.Context +import space.kscience.dataforge.context.PluginFactory +import space.kscience.dataforge.context.PluginTag +import space.kscience.dataforge.meta.Meta +import space.kscience.dataforge.names.Name +import space.kscience.visionforge.ElementVisionRenderer +import space.kscience.visionforge.Vision +import space.kscience.visionforge.VisionPlugin + +public actual class ControlVisionPlugin : VisionPlugin(), ElementVisionRenderer { + override val tag: PluginTag get() = Companion.tag + + override val visionSerializersModule: SerializersModule get() = controlsVisionSerializersModule + + override fun rateVision(vision: Vision): Int { + TODO("Not yet implemented") + } + + override fun render(element: Element, name: Name, vision: Vision, meta: Meta) { + TODO("Not yet implemented") + } + + public actual companion object : PluginFactory { + override val tag: PluginTag = PluginTag("controls.vision") + + override fun build(context: Context, meta: Meta): ControlVisionPlugin = ControlVisionPlugin() + + } +} \ No newline at end of file diff --git a/controls-vision/src/jvmMain/kotlin/ControlsVisionPlugin.jvm.kt b/controls-vision/src/jvmMain/kotlin/ControlsVisionPlugin.jvm.kt new file mode 100644 index 0000000..55074ae --- /dev/null +++ b/controls-vision/src/jvmMain/kotlin/ControlsVisionPlugin.jvm.kt @@ -0,0 +1,21 @@ +package space.kscience.controls.vision + +import kotlinx.serialization.modules.SerializersModule +import space.kscience.dataforge.context.Context +import space.kscience.dataforge.context.PluginFactory +import space.kscience.dataforge.context.PluginTag +import space.kscience.dataforge.meta.Meta +import space.kscience.visionforge.VisionPlugin + +public actual class ControlVisionPlugin : VisionPlugin() { + override val tag: PluginTag get() = Companion.tag + + override val visionSerializersModule: SerializersModule get() = controlsVisionSerializersModule + + public actual companion object : PluginFactory { + override val tag: PluginTag = PluginTag("controls.vision") + + override fun build(context: Context, meta: Meta): ControlVisionPlugin = ControlVisionPlugin() + + } +} \ No newline at end of file diff --git a/demo/all-things/src/main/kotlin/space/kscience/controls/demo/DemoDevice.kt b/demo/all-things/src/main/kotlin/space/kscience/controls/demo/DemoDevice.kt index 4f902c0..eaa1bff 100644 --- a/demo/all-things/src/main/kotlin/space/kscience/controls/demo/DemoDevice.kt +++ b/demo/all-things/src/main/kotlin/space/kscience/controls/demo/DemoDevice.kt @@ -16,7 +16,7 @@ import kotlin.math.sin import kotlin.time.Duration.Companion.milliseconds -interface IDemoDevice: Device { +interface IDemoDevice : Device { var timeScaleState: Double var sinScaleState: Double var cosScaleState: Double @@ -50,8 +50,8 @@ class DemoDevice(context: Context, meta: Meta) : DeviceBySpec(Compa val sinScale by mutableProperty(MetaConverter.double, IDemoDevice::sinScaleState) val cosScale by mutableProperty(MetaConverter.double, IDemoDevice::cosScaleState) - val sin by doubleProperty(read = IDemoDevice::sinValue) - val cos by doubleProperty(read = IDemoDevice::cosValue) + val sin by doubleProperty { sinValue() } + val cos by doubleProperty { cosValue() } val coordinates by metaProperty( descriptorBuilder = { diff --git a/demo/car/src/main/kotlin/space/kscience/controls/demo/car/IVirtualCar.kt b/demo/car/src/main/kotlin/space/kscience/controls/demo/car/IVirtualCar.kt index 3bb8c79..c61041b 100644 --- a/demo/car/src/main/kotlin/space/kscience/controls/demo/car/IVirtualCar.kt +++ b/demo/car/src/main/kotlin/space/kscience/controls/demo/car/IVirtualCar.kt @@ -2,6 +2,8 @@ package space.kscience.controls.demo.car import space.kscience.controls.api.Device import space.kscience.controls.spec.DeviceSpec +import space.kscience.controls.spec.mutableProperty +import space.kscience.controls.spec.property interface IVirtualCar : Device { var speedState: Vector2D diff --git a/demo/mks-pdr900/src/main/kotlin/center/sciprog/devices/mks/MksPdr900Device.kt b/demo/mks-pdr900/src/main/kotlin/center/sciprog/devices/mks/MksPdr900Device.kt index df54bfa..cb8030c 100644 --- a/demo/mks-pdr900/src/main/kotlin/center/sciprog/devices/mks/MksPdr900Device.kt +++ b/demo/mks-pdr900/src/main/kotlin/center/sciprog/devices/mks/MksPdr900Device.kt @@ -89,7 +89,7 @@ class MksPdr900Device(context: Context, meta: Meta) : DeviceBySpec writePowerOn(value) }) val channel by logicalProperty(MetaConverter.int) diff --git a/demo/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterDevice.kt b/demo/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterDevice.kt index 18e5838..dde2750 100644 --- a/demo/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterDevice.kt +++ b/demo/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterDevice.kt @@ -157,13 +157,13 @@ class PiMotionMasterDevice( } val stop by unitAction({ - info = "Stop all axis" + description = "Stop all axis" }) { send("STP") } val connect by action(MetaConverter.meta, MetaConverter.unit, descriptorBuilder = { - info = "Connect to specific port and initialize axis" + description = "Connect to specific port and initialize axis" }) { portSpec -> //Clear current actions if present if (port != null) { @@ -189,7 +189,7 @@ class PiMotionMasterDevice( } val disconnect by unitAction({ - info = "Disconnect the program from the device if it is connected" + description = "Disconnect the program from the device if it is connected" }) { port?.let { execute(stop) @@ -245,8 +245,8 @@ class PiMotionMasterDevice( read = { readAxisBoolean("$command?") }, - write = { - writeAxisBoolean(command, it) + write = { _, value -> + writeAxisBoolean(command, value) }, descriptorBuilder = descriptorBuilder ) @@ -259,7 +259,7 @@ class PiMotionMasterDevice( mm.requestAndParse("$command?", axisId)[axisId]?.toDoubleOrNull() ?: error("Malformed $command response. Should include float value for $axisId") }, - write = { newValue -> + write = { _, newValue -> mm.send(command, axisId, newValue.toString()) mm.failIfError() },