forked from M-Labs/thermostat
send_command: Better maps to thermostat commands
* Use a `dict` to map values to thermostat parameters. New tag "thermostat:set_param" used in JSON. * Remove "activater" option and interpret commands anomalies directly in send_command
This commit is contained in:
parent
d70ba8aaa0
commit
2548746fc6
@ -33,14 +33,10 @@
|
||||
"Constant Current": "constant_current",
|
||||
"Temperature PID": "temperature_pid"
|
||||
},
|
||||
"activaters": [
|
||||
null,
|
||||
[
|
||||
"pwm",
|
||||
"ch",
|
||||
"pid"
|
||||
]
|
||||
],
|
||||
"thermostat:set_param": {
|
||||
"topic": "pwm",
|
||||
"field": "pid"
|
||||
},
|
||||
"tip": "Select control method of output",
|
||||
"children": [
|
||||
{
|
||||
@ -56,11 +52,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
|
||||
},
|
||||
@ -77,11 +72,10 @@
|
||||
],
|
||||
"format": "{value:.4f}",
|
||||
"compactHeight": false,
|
||||
"param": [
|
||||
"pid",
|
||||
"ch",
|
||||
"target"
|
||||
],
|
||||
"thermostat:set_param": {
|
||||
"topic": "pid",
|
||||
"field": "target"
|
||||
},
|
||||
"tip": "The temperature setpoint of the TEC",
|
||||
"lock": false
|
||||
}
|
||||
@ -106,11 +100,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
|
||||
},
|
||||
@ -126,11 +119,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
|
||||
},
|
||||
@ -146,11 +138,10 @@
|
||||
],
|
||||
"siPrefix": true,
|
||||
"compactHeight": false,
|
||||
"param": [
|
||||
"pwm",
|
||||
"ch",
|
||||
"max_v"
|
||||
],
|
||||
"thermostat:set_param": {
|
||||
"topic": "pwm",
|
||||
"field": "max_v"
|
||||
},
|
||||
"tip": "The maximum voltage (in both directions) across the output pins",
|
||||
"lock": false
|
||||
}
|
||||
@ -177,11 +168,10 @@
|
||||
],
|
||||
"format": "{value:.4f}",
|
||||
"compactHeight": false,
|
||||
"param": [
|
||||
"s-h",
|
||||
"ch",
|
||||
"t0"
|
||||
],
|
||||
"thermostat:set_param": {
|
||||
"topic": "s-h",
|
||||
"field": "t0"
|
||||
},
|
||||
"tip": "The base temperature",
|
||||
"lock": false
|
||||
},
|
||||
@ -193,11 +183,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 base temperature T₀",
|
||||
"lock": false
|
||||
},
|
||||
@ -209,11 +198,10 @@
|
||||
"step": 1,
|
||||
"decimals": 4,
|
||||
"compactHeight": false,
|
||||
"param": [
|
||||
"s-h",
|
||||
"ch",
|
||||
"b"
|
||||
],
|
||||
"thermostat:set_param": {
|
||||
"topic": "s-h",
|
||||
"field": "b"
|
||||
},
|
||||
"tip": "The Beta Parameter",
|
||||
"lock": false
|
||||
},
|
||||
@ -222,13 +210,12 @@
|
||||
"title": "50/60 Hz filter 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,
|
||||
@ -253,11 +240,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 +253,10 @@
|
||||
"type": "float",
|
||||
"step": 0.1,
|
||||
"compactHeight": false,
|
||||
"param": [
|
||||
"pid",
|
||||
"ch",
|
||||
"ki"
|
||||
],
|
||||
"thermostat:set_param": {
|
||||
"topic": "pid",
|
||||
"field": "ki"
|
||||
},
|
||||
"tip": "Integral gain",
|
||||
"lock": false
|
||||
},
|
||||
@ -281,11 +266,10 @@
|
||||
"type": "float",
|
||||
"step": 0.1,
|
||||
"compactHeight": false,
|
||||
"param": [
|
||||
"pid",
|
||||
"ch",
|
||||
"kd"
|
||||
],
|
||||
"thermostat:set_param": {
|
||||
"topic": "pid",
|
||||
"field": "kd"
|
||||
},
|
||||
"tip": "Differential gain",
|
||||
"lock": false
|
||||
},
|
||||
@ -307,11 +291,10 @@
|
||||
],
|
||||
"decimals": 6,
|
||||
"compactHeight": false,
|
||||
"param": [
|
||||
"pid",
|
||||
"ch",
|
||||
"output_min"
|
||||
],
|
||||
"thermostat:set_param": {
|
||||
"topic": "pid",
|
||||
"field": "output_min"
|
||||
},
|
||||
"tip": "Minimum PID output",
|
||||
"lock": false
|
||||
},
|
||||
@ -326,11 +309,10 @@
|
||||
],
|
||||
"decimals": 6,
|
||||
"compactHeight": false,
|
||||
"param": [
|
||||
"pid",
|
||||
"ch",
|
||||
"output_max"
|
||||
],
|
||||
"thermostat:set_param": {
|
||||
"topic": "pid",
|
||||
"field": "output_max"
|
||||
},
|
||||
"tip": "Maximum PID output",
|
||||
"lock": false
|
||||
}
|
||||
@ -351,10 +333,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"
|
||||
},
|
||||
{
|
||||
@ -369,10 +350,9 @@
|
||||
0,
|
||||
2000
|
||||
],
|
||||
"pid_autotune": [
|
||||
"test_current",
|
||||
"ch"
|
||||
],
|
||||
"pid_autotune": {
|
||||
"params_name": "test_current"
|
||||
},
|
||||
"tip": "The testing current when autotuning"
|
||||
},
|
||||
{
|
||||
@ -384,10 +364,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"
|
||||
},
|
||||
{
|
||||
@ -398,10 +377,9 @@
|
||||
"step": 0.1,
|
||||
"format": "{value:.4f}",
|
||||
"compactHeight": false,
|
||||
"pid_autotune": [
|
||||
"lookback",
|
||||
"ch"
|
||||
],
|
||||
"pid_autotune": {
|
||||
"params_name": "lookback"
|
||||
},
|
||||
"tip": "Amount of time referenced for tuning"
|
||||
},
|
||||
{
|
||||
|
@ -270,35 +270,29 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
if "thermostat:set_param" in inner_param.opts:
|
||||
thermostat_param = inner_param.opts["thermostat:set_param"]
|
||||
|
||||
# Handle thermostat command irregularities
|
||||
match inner_param.name(), new_value:
|
||||
case "rate", "":
|
||||
thermostat_param = thermostat_param.copy()
|
||||
thermostat_param["field"] = "off"
|
||||
case "control_method", "constant_current":
|
||||
inner_param = inner_param.child("i_set")
|
||||
thermostat_param = inner_param.opts["thermostat:set_param"]
|
||||
new_value = inner_param.value()
|
||||
case "control_method", "temperature_pid":
|
||||
new_value = ""
|
||||
|
||||
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 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)
|
||||
|
||||
if "activaters" in inner_param.opts:
|
||||
activater = inner_param.opts["activaters"][
|
||||
inner_param.reverse[0].index(data) # ListParameter.reverse = list of codename values
|
||||
]
|
||||
if activater is not None:
|
||||
if activater[1] == "ch":
|
||||
activater[1] = ch
|
||||
await self.client.set_param(*activater)
|
||||
autotuner_param = inner_param.opts["pid_autotune"]
|
||||
self.autotuners.set_params(ch=ch, val=new_value, **autotuner_param)
|
||||
|
||||
@asyncSlot()
|
||||
async def pid_autotune_request(self, ch=0):
|
||||
|
Loading…
Reference in New Issue
Block a user