Updates on numass msp

This commit is contained in:
Alexander Nozik 2018-04-12 13:33:54 +03:00
parent e99fe84053
commit d032c48ef4
3 changed files with 56 additions and 57 deletions

View File

@ -233,7 +233,7 @@ class LambdaMagnet(private val controller: LambdaPortController, meta: Meta) : A
private fun startUpdateTask(delay: Long = DEFAULT_DELAY.toLong()) { private fun startUpdateTask(delay: Long = DEFAULT_DELAY.toLong()) {
assert(delay > 0) assert(delay > 0)
stopUpdateTask() stopUpdateTask()
updateTask = repeat(Duration.ofMillis(delay)) { updateTask = repeatOnDeviceThread(Duration.ofMillis(delay)) {
try { try {
val measuredI = current.readBlocking().doubleValue() val measuredI = current.readBlocking().doubleValue()
val targetI = target.doubleValue val targetI = target.doubleValue
@ -295,7 +295,7 @@ class LambdaMagnet(private val controller: LambdaPortController, meta: Meta) : A
assert(delay >= 1000) assert(delay >= 1000)
stopMonitorTask() stopMonitorTask()
monitorTask = repeat(Duration.ofMillis(delay)) { monitorTask = repeatOnDeviceThread(Duration.ofMillis(delay)) {
try { try {
runBlocking { runBlocking {
voltage.read() voltage.read()

View File

@ -66,21 +66,20 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
//val selected: Boolean by valueState("selected").booleanDelegate //val selected: Boolean by valueState("selected").booleanDelegate
var controlled = valueState(CONTROLLED_STATE) { _, value -> val controlled = valueState(CONTROLLED_STATE) { value ->
control(value.booleanValue()) runOnDeviceThread {
val res = control(value.booleanValue())
updateState(CONTROLLED_STATE, res)
}
} }
var filament by valueState("filament") { old, value -> val filament = valueState("filament") { value ->
if (old != value) {
selectFilament(value.intValue()) selectFilament(value.intValue())
} }
}.intDelegate
var filamentOn = valueState("filamentOn") { old, value -> val filamentOn = valueState("filamentOn") { value ->
if (old != value) {
setFilamentOn(value.booleanValue()) setFilamentOn(value.booleanValue())
} }
}
var peakJumpZero: Double by valueState("peakJump.zero").doubleDelegate var peakJumpZero: Double by valueState("peakJump.zero").doubleDelegate
@ -130,7 +129,6 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
* @throws hep.dataforge.exceptions.ControlException * @throws hep.dataforge.exceptions.ControlException
*/ */
private fun control(on: Boolean): Boolean { private fun control(on: Boolean): Boolean {
synchronized(this) {
logger.info("Starting initialization sequence") logger.info("Starting initialization sequence")
if (on != this.controlled.booleanValue) { if (on != this.controlled.booleanValue) {
val sensorName: String val sensorName: String
@ -171,7 +169,6 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
return on return on
} }
} }
}
/** /**
* Send request to the msp * Send request to the msp
@ -225,13 +222,15 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
@Throws(PortException::class) @Throws(PortException::class)
private fun selectFilament(filament: Int) { private fun selectFilament(filament: Int) {
runOnDeviceThread {
val response = commandAndWait("FilamentSelect", filament) val response = commandAndWait("FilamentSelect", filament)
if (response.isOK) { if (response.isOK) {
updateState("filament", response[1, 1]) this.filament.update(response[1, 1])
} else { } else {
logger.error("Failed to set filament with error: {}", response.errorDescription) logger.error("Failed to set filament with error: {}", response.errorDescription)
} }
} }
}
/** /**
* Turn filament on or off * Turn filament on or off
@ -299,7 +298,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
override fun stopMeasurement() { override fun stopMeasurement() {
super.stopMeasurement() super.stopMeasurement()
execute { runOnDeviceThread {
stopPeakJump() stopPeakJump()
} }
} }
@ -309,7 +308,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
stopMeasurement() stopMeasurement()
} }
if (newMeta.getString("type", "peakJump") == "peakJump") { if (newMeta.getString("type", "peakJump") == "peakJump") {
execute { runOnDeviceThread {
startPeakJump(newMeta) startPeakJump(newMeta)
} }
} else { } else {

View File

@ -117,7 +117,7 @@ class MspDisplay() : DeviceDisplayFX<MspDevice>(), NamedValueListener {
addListener { _, oldValue, newValue -> addListener { _, oldValue, newValue ->
if (newValue != oldValue) { if (newValue != oldValue) {
runAsync { runAsync {
device.filament = newValue device.filament.set(newValue)
} }
} }
} }