GUI: Refactor send_command #4

Merged
linuswck merged 6 commits from gui_dev-refactor-send_command into gui_dev 2024-10-07 13:03:38 +08:00
2 changed files with 86 additions and 119 deletions

View File

@ -25,14 +25,10 @@
"Constant Current", "Constant Current",
"Temperature PID" "Temperature PID"
], ],
"activaters":[ "thermostat:set_param":{
null, "topic":"pwm",
[ "field":"pid"
"pwm", },
"ch",
"pid"
]
],
"children":[ "children":[
{ {
"name":"Set Current", "name":"Set Current",
@ -46,11 +42,10 @@
"triggerOnShow":true, "triggerOnShow":true,
"decimals":6, "decimals":6,
"suffix":"mA", "suffix":"mA",
"param":[ "thermostat:set_param":{
"pwm", "topic":"pwm",
"ch", "field":"i_set"
"i_set" },
],
"lock":false "lock":false
}, },
{ {
@ -63,11 +58,10 @@
300 300
], ],
"format":"{value:.4f} °C", "format":"{value:.4f} °C",
"param":[ "thermostat:set_param":{
"pid", "topic":"pid",
"ch", "field":"target"
"target" },
],
"lock":false "lock":false
} }
] ]
@ -88,11 +82,10 @@
2000 2000
], ],
"suffix":"mA", "suffix":"mA",
"param":[ "thermostat:set_param":{
"pwm", "topic":"pwm",
"ch", "field":"max_i_pos"
"max_i_pos" },
],
"lock":false "lock":false
}, },
{ {
@ -106,11 +99,10 @@
2000 2000
], ],
"suffix":"mA", "suffix":"mA",
"param":[ "thermostat:set_param":{
"pwm", "topic":"pwm",
"ch", "field":"max_i_neg"
"max_i_neg" },
],
"lock":false "lock":false
}, },
{ {
@ -124,11 +116,10 @@
], ],
"siPrefix":true, "siPrefix":true,
"suffix":"V", "suffix":"V",
"param":[ "thermostat:set_param":{
"pwm", "topic":"pwm",
"ch", "field":"max_v"
"max_v" },
],
"lock":false "lock":false
} }
] ]
@ -150,11 +141,10 @@
100 100
], ],
"format":"{value:.4f} °C", "format":"{value:.4f} °C",
"param":[ "thermostat:set_param":{
"s-h", "topic":"s-h",
"ch", "field":"t0"
"t0" },
],
"lock":false "lock":false
}, },
{ {
@ -164,11 +154,10 @@
"step":1, "step":1,
"siPrefix":true, "siPrefix":true,
"suffix":"Ω", "suffix":"Ω",
"param":[ "thermostat:set_param":{
"s-h", "topic":"s-h",
"ch", "field":"r0"
"r0" },
],
"lock":false "lock":false
}, },
{ {
@ -178,22 +167,20 @@
"step":1, "step":1,
"suffix":"K", "suffix":"K",
"decimals":4, "decimals":4,
"param":[ "thermostat:set_param":{
"s-h", "topic":"s-h",
"ch", "field":"b"
"b" },
],
"lock":false "lock":false
}, },
{ {
"name":"Postfilter Rate", "name":"Postfilter Rate",
"type":"list", "type":"list",
"value":16.67, "value":16.67,
"param":[ "thermostat:set_param":{
"postfilter", "topic":"postfilter",
"ch", "field":"rate"
"rate" },
],
"limits":{ "limits":{
"Off":null, "Off":null,
"16.67 Hz":16.67, "16.67 Hz":16.67,
@ -215,11 +202,10 @@
"type":"float", "type":"float",
"step":0.1, "step":0.1,
"suffix":"", "suffix":"",
"param":[ "thermostat:set_param":{
"pid", "topic":"pid",
"ch", "field":"kp"
"kp" },
],
"lock":false "lock":false
}, },
{ {
@ -227,11 +213,10 @@
"type":"float", "type":"float",
"step":0.1, "step":0.1,
"suffix":"Hz", "suffix":"Hz",
"param":[ "thermostat:set_param":{
"pid", "topic":"pid",
"ch", "field":"ki"
"ki" },
],
"lock":false "lock":false
}, },
{ {
@ -239,11 +224,10 @@
"type":"float", "type":"float",
"step":0.1, "step":0.1,
"suffix":"s", "suffix":"s",
"param":[ "thermostat:set_param":{
"pid", "topic":"pid",
"ch", "field":"kd"
"kd" },
],
"lock":false "lock":false
}, },
{ {
@ -261,11 +245,10 @@
], ],
"decimals":6, "decimals":6,
"suffix":"mA", "suffix":"mA",
"param":[ "thermostat:set_param":{
"pid", "topic":"pid",
"ch", "field":"output_min"
"output_min" },
],
"lock":false "lock":false
}, },
{ {
@ -278,11 +261,10 @@
], ],
"decimals":6, "decimals":6,
"suffix":"mA", "suffix":"mA",
"param":[ "thermostat:set_param":{
"pid", "topic":"pid",
"ch", "field":"output_max"
"output_max" },
],
"lock":false "lock":false
} }
] ]
@ -298,10 +280,7 @@
"value":20, "value":20,
"step":0.1, "step":0.1,
"format":"{value:.4f} °C", "format":"{value:.4f} °C",
"pid_autotune":[ "pid_autotune":"target_temp"
"target_temp",
"ch"
]
}, },
{ {
"name":"Test Current", "name":"Test Current",
@ -314,10 +293,7 @@
2000 2000
], ],
"suffix":"mA", "suffix":"mA",
"pid_autotune":[ "pid_autotune":"test_current"
"test_current",
"ch"
]
}, },
{ {
"name":"Temperature Swing", "name":"Temperature Swing",
@ -326,10 +302,7 @@
"step":0.1, "step":0.1,
"prefix":"±", "prefix":"±",
"format":"{value:.4f} °C", "format":"{value:.4f} °C",
"pid_autotune":[ "pid_autotune":"temp_swing"
"temp_swing",
"ch"
]
}, },
{ {
"name":"Lookback", "name":"Lookback",
@ -337,10 +310,7 @@
"value":3.0, "value":3.0,
"step":0.1, "step":0.1,
"format":"{value:.4f} s", "format":"{value:.4f} s",
"pid_autotune":[ "pid_autotune":"lookback"
"lookback",
"ch"
]
}, },
{ {
"name":"Run", "name":"Run",

View File

@ -266,36 +266,33 @@ class MainWindow(QtWidgets.QMainWindow):
for inner_param, change, data in changes: for inner_param, change, data in changes:
if change == "value": if change == "value":
if inner_param.opts.get("param", None) is not None: new_value = data
if "thermostat:set_param" in inner_param.opts:
if inner_param.opts.get("suffix", None) == "mA": if inner_param.opts.get("suffix", None) == "mA":
data /= 1000 # Given in mA new_value /= 1000 # Given in mA
thermostat_param = inner_param.opts["param"] thermostat_param = inner_param.opts["thermostat:set_param"]
if thermostat_param[1] == "ch":
thermostat_param[1] = ch
if inner_param.name() == "Postfilter Rate" and data is None: # Handle thermostat command irregularities
set_param_args = (*thermostat_param[:2], "off") match inner_param.name(), new_value:
else: case "Postfilter Rate", None:
set_param_args = (*thermostat_param, data) thermostat_param = thermostat_param.copy()
param.child(*param.childPath(inner_param)).setOpts(lock=True) thermostat_param["field"] = "off"
await self.client.set_param(*set_param_args) new_value = ""
param.child(*param.childPath(inner_param)).setOpts(lock=False) case "Control Method", "Constant Current":
return
case "Control Method", "Temperature PID":
new_value = ""
if inner_param.opts.get("pid_autotune", None) is not None: inner_param.setOpts(lock=True)
auto_tuner_param = inner_param.opts["pid_autotune"][0] await self.client.set_param(
if inner_param.opts["pid_autotune"][1] != "ch": channel=ch, value=new_value, **thermostat_param
ch = inner_param.opts["pid_autotune"][1] )
self.autotuners.set_params(auto_tuner_param, ch, data) inner_param.setOpts(lock=False)
if inner_param.opts.get("activaters", None) is not None: if "pid_autotune" in inner_param.opts:
activater = inner_param.opts["activaters"][ auto_tuner_param = inner_param.opts["pid_autotune"]
inner_param.opts["limits"].index(data) self.autotuners.set_params(auto_tuner_param, ch, new_value)
]
if activater is not None:
if activater[1] == "ch":
activater[1] = ch
await self.client.set_param(*activater)
@asyncSlot() @asyncSlot()
async def pid_auto_tune_request(self, ch=0): async def pid_auto_tune_request(self, ch=0):