diff --git a/numass-control/gun/build.gradle b/numass-control/gun/build.gradle index 38371017..adb7e3e8 100644 --- a/numass-control/gun/build.gradle +++ b/numass-control/gun/build.gradle @@ -19,7 +19,7 @@ apply plugin: 'application' version = "0.1.0" if (!hasProperty('mainClass')) { - ext.mainClass = 'inr.numass.control.gun.EGunApplicationkt' + ext.mainClass = 'inr.numass.control.gun.EGunApplication' } mainClassName = mainClass diff --git a/numass-control/gun/src/main/kotlin/inr/numass/control/gun/EGun.kt b/numass-control/gun/src/main/kotlin/inr/numass/control/gun/EGun.kt index da808b9a..8400f197 100644 --- a/numass-control/gun/src/main/kotlin/inr/numass/control/gun/EGun.kt +++ b/numass-control/gun/src/main/kotlin/inr/numass/control/gun/EGun.kt @@ -25,8 +25,10 @@ import hep.dataforge.meta.Meta import hep.dataforge.meta.Metoid import hep.dataforge.names.Name import hep.dataforge.optional +import inr.numass.control.DeviceView import java.util.* +@DeviceView(GunDisplay::class) class EGun(context: Context, meta: Meta) : AbstractDevice(context, meta), DeviceHub, ContextAware, Metoid { val sources: List by lazy { meta.getMetaList("source").map {IT6800Device(context, it) } @@ -37,4 +39,14 @@ class EGun(context: Context, meta: Meta) : AbstractDevice(context, meta), Device override fun optDevice(name: Name): Optional { return sources.find { it.name == name.toString() }.optional } + + override fun init() { + super.init() + sources.forEach { it.init() } + } + + override fun shutdown() { + sources.forEach { it.shutdown() } + super.shutdown() + } } \ No newline at end of file diff --git a/numass-control/gun/src/main/kotlin/inr/numass/control/gun/EGunApplication.kt b/numass-control/gun/src/main/kotlin/inr/numass/control/gun/EGunApplication.kt index a3b9d698..f35d7dcb 100644 --- a/numass-control/gun/src/main/kotlin/inr/numass/control/gun/EGunApplication.kt +++ b/numass-control/gun/src/main/kotlin/inr/numass/control/gun/EGunApplication.kt @@ -38,6 +38,6 @@ class EGunApplication: NumassControlApplication() { } override fun getDeviceMeta(config: Meta): Meta { - return MetaUtils.findNode(config,"device"){it.getString("name") == "numass.gun"}.orElseThrow{RuntimeException("Gun configuration not found")} + return MetaUtils.findNode(config,"device"){it.getString("type") == "numass.gun"}.orElseThrow{RuntimeException("Gun configuration not found")} } } \ No newline at end of file diff --git a/numass-control/gun/src/main/kotlin/inr/numass/control/gun/EGunView.kt b/numass-control/gun/src/main/kotlin/inr/numass/control/gun/EGunView.kt index 172eac6d..c6e743e5 100644 --- a/numass-control/gun/src/main/kotlin/inr/numass/control/gun/EGunView.kt +++ b/numass-control/gun/src/main/kotlin/inr/numass/control/gun/EGunView.kt @@ -16,19 +16,58 @@ package inr.numass.control.gun +import hep.dataforge.fx.asBooleanProperty import hep.dataforge.fx.asDoubleProperty +import inr.numass.control.DeviceDisplayFX +import inr.numass.control.indicator +import javafx.geometry.Orientation import tornadofx.* -class EGunView(gun: EGun) : View() { +class GunDisplay: DeviceDisplayFX(){ + override fun buildView(device: EGun): UIComponent? { + return EGunView(device) + } +} + + +class EGunView(val gun: EGun) : View() { override val root = borderpane { + top{ + buttonbar { + button("refresh"){ + action { + gun.sources.forEach { + it.update() + } + } + } + } + } center { vbox { - gun.sources.forEach { device -> + gun.sources.forEach { source -> hbox { - label(device.name) - slider(range = 0.0..5.0, value = 0){ - valueProperty().bindBidirectional(device.currentState.asDoubleProperty()) + label(source.name) + separator(Orientation.VERTICAL) + + indicator { + bind(source.connected.asBooleanProperty()) } + + val voltageProperty = source.voltageState.asDoubleProperty() + val currentProperty = source.currentState.asDoubleProperty() + + textfield { + + } + separator(Orientation.VERTICAL) + label("V: ") + label(voltageProperty) + + separator(Orientation.VERTICAL) + + label("I: ") + label(currentProperty) } } } diff --git a/numass-control/gun/src/main/kotlin/inr/numass/control/gun/IT6800Device.kt b/numass-control/gun/src/main/kotlin/inr/numass/control/gun/IT6800Device.kt index 4422c4e1..552f092e 100644 --- a/numass-control/gun/src/main/kotlin/inr/numass/control/gun/IT6800Device.kt +++ b/numass-control/gun/src/main/kotlin/inr/numass/control/gun/IT6800Device.kt @@ -38,7 +38,7 @@ class IT6800Device(context: Context, meta: Meta) : AbstractDevice(context, meta) private var monitorJob: Job? = null - val connected get() = portHelper.connected + val connected get() = portHelper.connectedState val address: Byte = meta.getValue("address", 0).number.toByte() diff --git a/numass-control/gun/src/main/resources/config/devices.xml b/numass-control/gun/src/main/resources/config/devices.xml new file mode 100644 index 00000000..b441fea2 --- /dev/null +++ b/numass-control/gun/src/main/resources/config/devices.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/numass-core/src/main/kotlin/inr/numass/data/SpectrumAdapter.kt b/numass-core/src/main/kotlin/inr/numass/data/SpectrumAdapter.kt index b4d2c0b1..6e427397 100644 --- a/numass-core/src/main/kotlin/inr/numass/data/SpectrumAdapter.kt +++ b/numass-core/src/main/kotlin/inr/numass/data/SpectrumAdapter.kt @@ -24,6 +24,7 @@ import hep.dataforge.values.Value import hep.dataforge.values.ValueMap import hep.dataforge.values.Values import hep.dataforge.values.asValue +import java.lang.Math.sqrt import java.util.* import java.util.stream.Stream @@ -83,8 +84,8 @@ class SpectrumAdapter : BasicAdapter { when { y < 0 -> Optional.empty() y == 0.0 -> //avoid infinite weights - Optional.of(Value.of(1.0 / getTime(values))) - else -> Optional.of(Value.of(Math.sqrt(y / getTime(values)))) + Optional.of(Value.of(1.0 / sqrt(getTime(values)))) + else -> Optional.of(Value.of(sqrt(y / getTime(values)))) } } }