Merge pull request 'GUI: Refactor `send_command`' (#4) from gui_dev-refactor-send_command into gui_dev

Reviewed-on: linuswck/thermostat#4
This commit is contained in:
linuswck 2024-10-07 13:03:38 +08:00
commit 19c3c7a8f2
2 changed files with 86 additions and 119 deletions

View File

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

View File

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