From 487bf24ffef5e4562b369e5064480c4bace2043d Mon Sep 17 00:00:00 2001 From: atse Date: Wed, 17 Jul 2024 16:43:42 +0800 Subject: [PATCH] More straightforward mapping to thermostat command New tag "thermostat:set_param" used in JSON. --- pytec/pytec/gui/view/param_tree.json | 156 ++++++++++++--------------- pytec/tec_qt.py | 20 ++-- 2 files changed, 77 insertions(+), 99 deletions(-) diff --git a/pytec/pytec/gui/view/param_tree.json b/pytec/pytec/gui/view/param_tree.json index 2104da2..123d12d 100644 --- a/pytec/pytec/gui/view/param_tree.json +++ b/pytec/pytec/gui/view/param_tree.json @@ -56,11 +56,10 @@ "triggerOnShow": true, "decimals": 6, "compactHeight": false, - "param": [ - "pwm", - "ch", - "i_set" - ], + "thermostat:set_param": { + "topic": "pwm", + "field": "i_set" + }, "tip": "The set current through TEC", "lock": false }, @@ -76,11 +75,10 @@ ], "format": "{value:.4f}", "compactHeight": false, - "param": [ - "pid", - "ch", - "target" - ], + "thermostat:set_param": { + "topic": "pid", + "field": "target" + }, "tip": "The target temperature of the TEC", "lock": false } @@ -105,11 +103,10 @@ 0, 2000 ], - "param": [ - "pwm", - "ch", - "max_i_pos" - ], + "thermostat:set_param": { + "topic": "pwm", + "field": "max_i_pos" + }, "tip": "The maximum cooling (+ve) current through the output pins", "lock": false }, @@ -125,11 +122,10 @@ 0, 2000 ], - "param": [ - "pwm", - "ch", - "max_i_neg" - ], + "thermostat:set_param": { + "topic": "pwm", + "field": "max_i_neg" + }, "tip": "The maximum heating (-ve) current through the output pins", "lock": false }, @@ -145,11 +141,10 @@ ], "siPrefix": true, "compactHeight": false, - "param": [ - "pwm", - "ch", - "max_v" - ], + "thermostat:set_param": { + "topic": "pwm", + "field": "max_v" + }, "tip": "The maximum voltage across the output pins", "lock": false } @@ -176,11 +171,10 @@ ], "format": "{value:.4f}", "compactHeight": false, - "param": [ - "s-h", - "ch", - "t0" - ], + "thermostat:set_param": { + "topic": "s-h", + "field": "t0" + }, "tip": "The origin temperature", "lock": false }, @@ -192,11 +186,10 @@ "step": 1, "siPrefix": true, "compactHeight": false, - "param": [ - "s-h", - "ch", - "r0" - ], + "thermostat:set_param": { + "topic": "s-h", + "field": "r0" + }, "tip": "The resistance of the thermistor at origin temperature T₀", "lock": false }, @@ -208,11 +201,10 @@ "step": 1, "decimals": 4, "compactHeight": false, - "param": [ - "s-h", - "ch", - "b" - ], + "thermostat:set_param": { + "topic": "s-h", + "field": "b" + }, "tip": "The B (or Beta) Parameter", "lock": false }, @@ -221,13 +213,12 @@ "title": "Postfilter Rejection", "type": "list", "value": 16.67, - "param": [ - "postfilter", - "ch", - "rate" - ], + "thermostat:set_param": { + "topic": "postfilter", + "field": "rate" + }, "limits": { - "Off": null, + "Off": "", "47 dB @ 10.41 Hz": 27.0, "62 dB @ 9.1 Hz": 21.25, "86 dB @ 10 Hz": 20.0, @@ -252,11 +243,10 @@ "step": 0.1, "suffix": "", "compactHeight": false, - "param": [ - "pid", - "ch", - "kp" - ], + "thermostat:set_param": { + "topic": "pid", + "field": "kp" + }, "tip": "Proportional gain", "lock": false }, @@ -267,11 +257,10 @@ "step": 0.1, "suffix": "Hz", "compactHeight": false, - "param": [ - "pid", - "ch", - "ki" - ], + "thermostat:set_param": { + "topic": "pid", + "field": "ki" + }, "tip": "Integral gain", "lock": false }, @@ -282,11 +271,10 @@ "step": 0.1, "suffix": "s", "compactHeight": false, - "param": [ - "pid", - "ch", - "kd" - ], + "thermostat:set_param": { + "topic": "pid", + "field": "kd" + }, "tip": "Differential gain", "lock": false }, @@ -308,11 +296,10 @@ ], "decimals": 6, "compactHeight": false, - "param": [ - "pid", - "ch", - "output_min" - ], + "thermostat:set_param": { + "topic": "pid", + "field": "output_min" + }, "tip": "Minimum PID output", "lock": false }, @@ -327,11 +314,10 @@ ], "decimals": 6, "compactHeight": false, - "param": [ - "pid", - "ch", - "output_max" - ], + "thermostat:set_param": { + "topic": "pid", + "field": "output_max" + }, "tip": "Maximum PID output", "lock": false } @@ -352,10 +338,9 @@ "step": 0.1, "format": "{value:.4f}", "compactHeight": false, - "pid_autotune": [ - "target_temp", - "ch" - ], + "pid_autotune": { + "params_name": "target_temp" + }, "tip": "The target temperature to autotune for" }, { @@ -370,10 +355,9 @@ -2000, 2000 ], - "pid_autotune": [ - "test_current", - "ch" - ], + "pid_autotune": { + "params_name": "test_current" + }, "tip": "The testing current when autotuning" }, { @@ -385,10 +369,9 @@ "prefix": "±", "format": "{value:.4f}", "compactHeight": false, - "pid_autotune": [ - "temp_swing", - "ch" - ], + "pid_autotune": { + "params_name": "temp_swing" + }, "tip": "The temperature swing around the target" }, { @@ -399,10 +382,9 @@ "step": 0.1, "format": "{value:.4f}", "compactHeight": false, - "pid_autotune": [ - "lookback", - "ch" - ], + "pid_autotune": { + "params_name": "lookback" + }, "tip": "Amount of time to lookback" }, { diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index b022e45..89c0dc3 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -273,23 +273,19 @@ class MainWindow(QtWidgets.QMainWindow): if inner_param.opts.get("title", None).endswith(" (mA)"): new_value /= 1000 # Given in mA - thermostat_param = inner_param.opts["param"] - if thermostat_param[1] == "ch": - thermostat_param[1] = ch + if inner_param.name() == "rate" and new_value == "": + thermostat_param = thermostat_param.copy() + thermostat_param["field"] = "off" - if inner_param.name() == "rate" and new_value is None: - set_param_args = (*thermostat_param[:2], "off") - else: - set_param_args = (*thermostat_param, new_value) inner_param.setOpts(lock=True) - await self.client.set_param(*set_param_args) + await self.client.set_param( + channel=ch, value=new_value, **thermostat_param + ) inner_param.setOpts(lock=False) if "pid_autotune" in inner_param.opts: - autotuner_param = inner_param.opts["pid_autotune"][0] - if inner_param.opts["pid_autotune"][1] != "ch": - ch = inner_param.opts["pid_autotune"][1] - self.autotuners.set_params(autotuner_param, ch, data) + autotuner_param = inner_param.opts["pid_autotune"] + self.autotuners.set_params(ch=ch, val=new_value, **autotuner_param) if "activaters" in inner_param.opts: activater = inner_param.opts["activaters"][