ctrl_panel: Pin down units for editable fields

Avoids awkward value editing
This commit is contained in:
atse 2024-06-27 17:28:12 +08:00
parent b668c699fb
commit 8a4d861672
2 changed files with 22 additions and 33 deletions

View File

@ -44,7 +44,7 @@
"children": [ "children": [
{ {
"name": "i_set", "name": "i_set",
"title": "Set Current", "title": "Set Current (mA)",
"type": "float", "type": "float",
"value": 0, "value": 0,
"step": 100, "step": 100,
@ -54,7 +54,6 @@
], ],
"triggerOnShow": true, "triggerOnShow": true,
"decimals": 6, "decimals": 6,
"suffix": "mA",
"param": [ "param": [
"pwm", "pwm",
"ch", "ch",
@ -65,7 +64,7 @@
}, },
{ {
"name": "target", "name": "target",
"title": "Setpoint", "title": "Setpoint (°C)",
"type": "float", "type": "float",
"value": 25, "value": 25,
"step": 0.1, "step": 0.1,
@ -73,7 +72,7 @@
-273, -273,
300 300
], ],
"format": "{value:.4f} °C", "format": "{value:.4f}",
"param": [ "param": [
"pid", "pid",
"ch", "ch",
@ -93,7 +92,7 @@
"children": [ "children": [
{ {
"name": "max_i_pos", "name": "max_i_pos",
"title": "Max Cooling Current", "title": "Max Cooling Current (mA)",
"type": "float", "type": "float",
"value": 0, "value": 0,
"step": 100, "step": 100,
@ -102,7 +101,6 @@
0, 0,
2000 2000
], ],
"suffix": "mA",
"param": [ "param": [
"pwm", "pwm",
"ch", "ch",
@ -113,7 +111,7 @@
}, },
{ {
"name": "max_i_neg", "name": "max_i_neg",
"title": "Max Heating Current", "title": "Max Heating Current (mA)",
"type": "float", "type": "float",
"value": 0, "value": 0,
"step": 100, "step": 100,
@ -122,7 +120,6 @@
0, 0,
2000 2000
], ],
"suffix": "mA",
"param": [ "param": [
"pwm", "pwm",
"ch", "ch",
@ -133,7 +130,7 @@
}, },
{ {
"name": "max_v", "name": "max_v",
"title": "Max Absolute Voltage", "title": "Max Absolute Voltage (V)",
"type": "float", "type": "float",
"value": 0, "value": 0,
"step": 0.1, "step": 0.1,
@ -142,7 +139,6 @@
5 5
], ],
"siPrefix": true, "siPrefix": true,
"suffix": "V",
"param": [ "param": [
"pwm", "pwm",
"ch", "ch",
@ -164,7 +160,7 @@
"children": [ "children": [
{ {
"name": "t0", "name": "t0",
"title": "T₀", "title": "T₀ (°C)",
"type": "float", "type": "float",
"value": 25, "value": 25,
"step": 0.1, "step": 0.1,
@ -172,7 +168,7 @@
-100, -100,
100 100
], ],
"format": "{value:.4f} °C", "format": "{value:.4f}",
"param": [ "param": [
"s-h", "s-h",
"ch", "ch",
@ -183,12 +179,11 @@
}, },
{ {
"name": "r0", "name": "r0",
"title": "R₀", "title": "R₀ (Ω)",
"type": "float", "type": "float",
"value": 10000, "value": 10000,
"step": 1, "step": 1,
"siPrefix": true, "siPrefix": true,
"suffix": "Ω",
"param": [ "param": [
"s-h", "s-h",
"ch", "ch",
@ -199,11 +194,10 @@
}, },
{ {
"name": "b", "name": "b",
"title": "B", "title": "B (K)",
"type": "float", "type": "float",
"value": 3950, "value": 3950,
"step": 1, "step": 1,
"suffix": "K",
"decimals": 4, "decimals": 4,
"param": [ "param": [
"s-h", "s-h",
@ -258,10 +252,9 @@
}, },
{ {
"name": "ki", "name": "ki",
"title": "Ki", "title": "Ki (Hz)",
"type": "float", "type": "float",
"step": 0.1, "step": 0.1,
"suffix": "Hz",
"param": [ "param": [
"pid", "pid",
"ch", "ch",
@ -272,10 +265,9 @@
}, },
{ {
"name": "kd", "name": "kd",
"title": "Kd", "title": "Kd (s)",
"type": "float", "type": "float",
"step": 0.1, "step": 0.1,
"suffix": "s",
"param": [ "param": [
"pid", "pid",
"ch", "ch",
@ -293,7 +285,7 @@
"children": [ "children": [
{ {
"name": "output_min", "name": "output_min",
"title": "Minimum", "title": "Minimum (mA)",
"type": "float", "type": "float",
"step": 100, "step": 100,
"limits": [ "limits": [
@ -301,7 +293,6 @@
2000 2000
], ],
"decimals": 6, "decimals": 6,
"suffix": "mA",
"param": [ "param": [
"pid", "pid",
"ch", "ch",
@ -312,7 +303,7 @@
}, },
{ {
"name": "output_max", "name": "output_max",
"title": "Maximum", "title": "Maximum (mA)",
"type": "float", "type": "float",
"step": 100, "step": 100,
"limits": [ "limits": [
@ -320,7 +311,6 @@
2000 2000
], ],
"decimals": 6, "decimals": 6,
"suffix": "mA",
"param": [ "param": [
"pid", "pid",
"ch", "ch",
@ -340,11 +330,11 @@
"children": [ "children": [
{ {
"name": "target_temp", "name": "target_temp",
"title": "Target Temperature", "title": "Target Temperature (°C)",
"type": "float", "type": "float",
"value": 20, "value": 20,
"step": 0.1, "step": 0.1,
"format": "{value:.4f} °C", "format": "{value:.4f}",
"pid_autotune": [ "pid_autotune": [
"target_temp", "target_temp",
"ch" "ch"
@ -353,7 +343,7 @@
}, },
{ {
"name": "test_current", "name": "test_current",
"title": "Test Current", "title": "Test Current (mA)",
"type": "float", "type": "float",
"value": 0, "value": 0,
"decimals": 6, "decimals": 6,
@ -362,7 +352,6 @@
-2000, -2000,
2000 2000
], ],
"suffix": "mA",
"pid_autotune": [ "pid_autotune": [
"test_current", "test_current",
"ch" "ch"
@ -371,12 +360,12 @@
}, },
{ {
"name": "temp_swing", "name": "temp_swing",
"title": "Temperature Swing", "title": "Temperature Swing (°C)",
"type": "float", "type": "float",
"value": 1.5, "value": 1.5,
"step": 0.1, "step": 0.1,
"prefix": "±", "prefix": "±",
"format": "{value:.4f} °C", "format": "{value:.4f}",
"pid_autotune": [ "pid_autotune": [
"temp_swing", "temp_swing",
"ch" "ch"
@ -385,11 +374,11 @@
}, },
{ {
"name": "lookback", "name": "lookback",
"title": "Lookback", "title": "Lookback (s)",
"type": "float", "type": "float",
"value": 3.0, "value": 3.0,
"step": 0.1, "step": 0.1,
"format": "{value:.4f} s", "format": "{value:.4f}",
"pid_autotune": [ "pid_autotune": [
"lookback", "lookback",
"ch" "ch"

View File

@ -267,7 +267,7 @@ 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: if inner_param.opts.get("param", None) is not None:
if inner_param.opts.get("suffix", None) == "mA": if inner_param.opts.get("title", None).endswith(" (mA)"):
data /= 1000 # Given in mA data /= 1000 # Given in mA
thermostat_param = inner_param.opts["param"] thermostat_param = inner_param.opts["param"]