Compare commits

...

14 Commits

Author SHA1 Message Date
f513875745 ctrl_panel: Fix highlighting on focus with °C 2024-07-30 18:19:29 +08:00
700792cd72 ctrl_panel: More appropriate steps and fixes 2024-07-30 18:19:29 +08:00
463e515920 ctrl_panel: Put plotted values into readings group
For more intuitiveness to first-time users
2024-07-30 18:19:29 +08:00
a1a5bb5c35 ctrl_panel: Fix max_v to only have unit "V" 2024-07-30 18:19:29 +08:00
45b84b4e6e ctrl_panel: Keep i_set visible when PID engaged
Since i_set is also plotted, we would want to see its precise value too.
2024-07-30 18:19:29 +08:00
f5d075a2f0 ctrl_panel: Remove MutexParameter
Use the standard ListParamenter instead, and hook up UI changes and
sent commands elsewhere.
2024-07-30 18:19:28 +08:00
1cea5eb31c ctrl_panel: Limits fixes
* PID Autotune test current should be positive

* Maximum absolute voltage should be 4 V not 5 V
2024-07-30 18:19:28 +08:00
eb8844ce36 ctrl_panel: Code cleanup
* Remove unnecessary duplication of `THERMOSTAT_PARAMETERS`

* i -> ch

* Separate ParameterTree and Parameter initiation

* Remove extra "channel" option to root parameters, as the "value"
option is already the channel number
2024-07-30 18:19:28 +08:00
14a187ac63 ctrl_panel: PID Auto Tune -> PID Autotune 2024-07-30 18:19:28 +08:00
4546000917 ctrl_panel: Stop crushing spinboxes
It might not be the case on some themes, but on the default Qt theme the
spinbox are a bit too short for the containing numbers. See
https://github.com/pyqtgraph/pyqtgraph/issues/701.
2024-07-30 18:19:28 +08:00
ab6f688dad ctrl_panel: Pin down units for editable fields
Units should always be fixed in user input boxes. The option
"noUnitEditing" is added to do so by the following measures:

1. Don't validate for changed siPrefix and suffix, which avoids their
removal.

2. Avoid getting the cursor embedded within suffixes
2024-07-30 18:19:28 +08:00
ba47a30d92 ctrl_panel: Add option to use fixed siPrefix
Adds the option "pinSiPrefix" for all `Parameters` of type `int` or
`float`, and use it for current Parameters with unit "mA".

This let's us remove all instances of mA scaling scattered all around
the code and specify it in the parameter tree with a single source of
truth.
2024-07-30 18:13:45 +08:00
432b639557 ctrl_panel: Appropriate units for measured current
Allow the readonly display of current to vary its SI prefix in the unit,
since as a display entry it won't have the unit adjustment problem.
2024-07-30 12:21:10 +08:00
681a7539fe ctrl_panel: Improve postfilter description 2024-07-19 15:49:19 +08:00
4 changed files with 304 additions and 120 deletions

View File

@ -4,42 +4,7 @@ from pyqtgraph.parametertree import (
Parameter, Parameter,
registerParameterType, registerParameterType,
) )
import pytec.gui.view.pin_siPrefix
class MutexParameter(pTypes.ListParameter):
"""
Mutually exclusive parameter where only one of its children is visible at a time, list selectable.
The ordering of the list items determines which children will be visible.
"""
def __init__(self, **opts):
super().__init__(**opts)
self.sigValueChanged.connect(self.show_chosen_child)
self.sigValueChanged.emit(self, self.opts["value"])
def _get_param_from_value(self, value):
if isinstance(self.opts["limits"], dict):
values_list = list(self.opts["limits"].values())
else:
values_list = self.opts["limits"]
return self.children()[values_list.index(value)]
@pyqtSlot(object, object)
def show_chosen_child(self, value):
for param in self.children():
param.hide()
child_to_show = self._get_param_from_value(value.value())
child_to_show.show()
if child_to_show.opts.get("triggerOnShow", None):
child_to_show.sigValueChanged.emit(child_to_show, child_to_show.value())
registerParameterType("mutex", MutexParameter)
def set_tree_label_tips(tree): def set_tree_label_tips(tree):
@ -65,31 +30,40 @@ class CtrlPanel(QObject):
self.trees_ui = trees_ui self.trees_ui = trees_ui
self.NUM_CHANNELS = len(trees_ui) self.NUM_CHANNELS = len(trees_ui)
self.THERMOSTAT_PARAMETERS = [param_tree for i in range(self.NUM_CHANNELS)]
self.params = [ self.params = [
Parameter.create( Parameter.create(
name=f"Thermostat Channel {ch} Parameters", name=f"Thermostat Channel {ch} Parameters",
type="group", type="group",
value=ch, value=ch,
children=self.THERMOSTAT_PARAMETERS[ch], children=param_tree,
) )
for ch in range(self.NUM_CHANNELS) for ch in range(self.NUM_CHANNELS)
] ]
for i, param in enumerate(self.params): for ch, tree in enumerate(self.trees_ui):
param.channel = i
for i, tree in enumerate(self.trees_ui):
tree.setHeaderHidden(True) tree.setHeaderHidden(True)
tree.setParameters(self.params[i], showTop=False) tree.setParameters(self.params[ch], showTop=False)
self.params[i].setValue = self._setValue
self.params[i].sigTreeStateChanged.connect(sigTreeStateChanged_handle)
set_tree_label_tips(tree) set_tree_label_tips(tree)
for handle in sigActivated_handles[i]: for ch, param in enumerate(self.params):
self.params[i].child(*handle[0]).sigActivated.connect(handle[1]) self.params[ch].setValue = self._setValue
param.sigTreeStateChanged.connect(sigTreeStateChanged_handle)
for handle in sigActivated_handles[ch]:
param.child(*handle[0]).sigActivated.connect(handle[1])
param.child("output", "control_method").sigValueChanged.connect(
lambda param, value: param.child("i_set").setWritable(
value == "constant_current"
)
)
param.child("output", "control_method").sigValueChanged.connect(
lambda param, value: param.child("target").show(
value == "temperature_pid"
)
)
def _setValue(self, value, blockSignal=None): def _setValue(self, value, blockSignal=None):
""" """
@ -136,10 +110,10 @@ class CtrlPanel(QObject):
) )
self.params[channel].child( self.params[channel].child(
"pid", "pid_output_clamping", "output_min" "pid", "pid_output_clamping", "output_min"
).setValue(settings["parameters"]["output_min"] * 1000) ).setValue(settings["parameters"]["output_min"])
self.params[channel].child( self.params[channel].child(
"pid", "pid_output_clamping", "output_max" "pid", "pid_output_clamping", "output_max"
).setValue(settings["parameters"]["output_max"] * 1000) ).setValue(settings["parameters"]["output_max"])
self.params[channel].child( self.params[channel].child(
"output", "control_method", "target" "output", "control_method", "target"
).setValue(settings["target"]) ).setValue(settings["target"])
@ -154,14 +128,14 @@ class CtrlPanel(QObject):
) )
self.params[channel].child( self.params[channel].child(
"output", "control_method", "i_set" "output", "control_method", "i_set"
).setValue(settings["i_set"] * 1000) ).setValue(settings["i_set"])
if settings["temperature"] is not None: if settings["temperature"] is not None:
self.params[channel].child("temperature").setValue( self.params[channel].child("readings", "temperature").setValue(
settings["temperature"] settings["temperature"]
) )
if settings["tec_i"] is not None: if settings["tec_i"] is not None:
self.params[channel].child("tec_i").setValue( self.params[channel].child("readings", "tec_i").setValue(
settings["tec_i"] * 1000 settings["tec_i"]
) )
@pyqtSlot("QVariantList") @pyqtSlot("QVariantList")
@ -190,10 +164,10 @@ class CtrlPanel(QObject):
pwm_params["max_v"]["value"] pwm_params["max_v"]["value"]
) )
self.params[channel].child("output", "limits", "max_i_pos").setValue( self.params[channel].child("output", "limits", "max_i_pos").setValue(
pwm_params["max_i_pos"]["value"] * 1000 pwm_params["max_i_pos"]["value"]
) )
self.params[channel].child("output", "limits", "max_i_neg").setValue( self.params[channel].child("output", "limits", "max_i_neg").setValue(
pwm_params["max_i_neg"]["value"] * 1000 pwm_params["max_i_neg"]["value"]
) )
for limit in "max_i_pos", "max_i_neg", "max_v": for limit in "max_i_pos", "max_i_neg", "max_v":

View File

@ -1,21 +1,31 @@
{ {
"ctrl_panel": [ "ctrl_panel": [
{ {
"name": "temperature", "name": "readings",
"title": "Temperature", "title": "Readings",
"type": "float", "type": "group",
"format": "{value:.4f} °C", "tip": "Thermostat readings",
"readonly": true, "children": [
"tip": "The measured temperature at the thermistor" {
}, "name": "temperature",
{ "title": "Temperature",
"name": "tec_i", "type": "float",
"title": "Current through TEC", "format": "{value:.4f} {suffix}",
"type": "float", "suffix": "°C",
"suffix": "mA", "readonly": true,
"decimals": 6, "tip": "The measured temperature at the thermistor"
"readonly": true, },
"tip": "The measured current through the TEC" {
"name": "tec_i",
"title": "Current through TEC",
"type": "float",
"siPrefix": true,
"suffix": "A",
"decimals": 6,
"readonly": true,
"tip": "The measured current through the TEC"
}
]
}, },
{ {
"name": "output", "name": "output",
@ -27,7 +37,7 @@
{ {
"name": "control_method", "name": "control_method",
"title": "Control Method", "title": "Control Method",
"type": "mutex", "type": "list",
"limits": { "limits": {
"Constant Current": "constant_current", "Constant Current": "constant_current",
"Temperature PID": "temperature_pid" "Temperature PID": "temperature_pid"
@ -47,14 +57,17 @@
"title": "Set Current", "title": "Set Current",
"type": "float", "type": "float",
"value": 0, "value": 0,
"step": 100, "step": 0.1,
"limits": [ "limits": [
-2000, -2,
2000 2
], ],
"triggerOnShow": true,
"decimals": 6, "decimals": 6,
"suffix": "mA", "pinSiPrefix": "m",
"suffix": "A",
"siPrefix": true,
"noUnitEditing": true,
"compactHeight": false,
"param": [ "param": [
"pwm", "pwm",
"ch", "ch",
@ -67,13 +80,18 @@
"name": "target", "name": "target",
"title": "Setpoint", "title": "Setpoint",
"type": "float", "type": "float",
"visible": false,
"value": 25, "value": 25,
"step": 0.1, "step": 0.1,
"limits": [ "limits": [
-273, -273,
300 300
], ],
"format": "{value:.4f} °C", "format": "{value:.4f} {suffix}",
"suffix": "°C",
"regex": "(?P<number>[+-]?((((\\d+(\\.\\d*)?)|(\\d*\\.\\d+))([eE][+-]?\\d+)?)|((?i:nan)|(inf))))\\s*((?P<siPrefix>[uyzafpnµm kMGTPEZY]?)(?P<suffix>.*))?$",
"noUnitEditing": true,
"compactHeight": false,
"param": [ "param": [
"pid", "pid",
"ch", "ch",
@ -96,13 +114,17 @@
"title": "Max Cooling Current", "title": "Max Cooling Current",
"type": "float", "type": "float",
"value": 0, "value": 0,
"step": 100, "step": 0.1,
"decimals": 6, "decimals": 6,
"limits": [ "limits": [
0, 0,
2000 2
], ],
"suffix": "mA", "siPrefix": true,
"pinSiPrefix": "m",
"suffix": "A",
"noUnitEditing": true,
"compactHeight": false,
"param": [ "param": [
"pwm", "pwm",
"ch", "ch",
@ -116,13 +138,17 @@
"title": "Max Heating Current", "title": "Max Heating Current",
"type": "float", "type": "float",
"value": 0, "value": 0,
"step": 100, "step": 0.1,
"decimals": 6, "decimals": 6,
"siPrefix": true,
"pinSiPrefix": "m",
"suffix": "A",
"noUnitEditing": true,
"limits": [ "limits": [
0, 0,
2000 2
], ],
"suffix": "mA", "compactHeight": false,
"param": [ "param": [
"pwm", "pwm",
"ch", "ch",
@ -137,12 +163,14 @@
"type": "float", "type": "float",
"value": 0, "value": 0,
"step": 0.1, "step": 0.1,
"decimals": 3,
"limits": [ "limits": [
0, 0,
5 4
], ],
"siPrefix": true,
"suffix": "V", "suffix": "V",
"noUnitEditing": true,
"compactHeight": false,
"param": [ "param": [
"pwm", "pwm",
"ch", "ch",
@ -172,7 +200,11 @@
-100, -100,
100 100
], ],
"format": "{value:.4f} °C", "format": "{value:.4f} {suffix}",
"suffix": "°C",
"regex": "(?P<number>[+-]?((((\\d+(\\.\\d*)?)|(\\d*\\.\\d+))([eE][+-]?\\d+)?)|((?i:nan)|(inf))))\\s*((?P<siPrefix>[uyzafpnµm kMGTPEZY]?)(?P<suffix>.*))?$",
"noUnitEditing": true,
"compactHeight": false,
"param": [ "param": [
"s-h", "s-h",
"ch", "ch",
@ -186,9 +218,11 @@
"title": "R₀", "title": "R₀",
"type": "float", "type": "float",
"value": 10000, "value": 10000,
"step": 1, "step": 100,
"siPrefix": true, "siPrefix": true,
"suffix": "Ω", "suffix": "Ω",
"noUnitEditing": true,
"compactHeight": false,
"param": [ "param": [
"s-h", "s-h",
"ch", "ch",
@ -202,9 +236,11 @@
"title": "B", "title": "B",
"type": "float", "type": "float",
"value": 3950, "value": 3950,
"step": 1, "step": 10,
"suffix": "K", "suffix": "K",
"noUnitEditing": true,
"decimals": 4, "decimals": 4,
"compactHeight": false,
"param": [ "param": [
"s-h", "s-h",
"ch", "ch",
@ -215,7 +251,7 @@
}, },
{ {
"name": "rate", "name": "rate",
"title": "Postfilter Rate", "title": "50/60 Hz filter rejection",
"type": "list", "type": "list",
"value": 16.67, "value": 16.67,
"param": [ "param": [
@ -225,10 +261,10 @@
], ],
"limits": { "limits": {
"Off": null, "Off": null,
"16.67 Hz": 16.67, "47 dB @ 10.41 Hz": 27.0,
"20 Hz": 20.0, "62 dB @ 9.1 Hz": 21.25,
"21.25 Hz": 21.25, "86 dB @ 10 Hz": 20.0,
"27 Hz": 27.0 "92 dB @ 8.4 Hz": 16.67
}, },
"tip": "Trade off effective sampling rate and rejection of (50±1) Hz and (60±1) Hz", "tip": "Trade off effective sampling rate and rejection of (50±1) Hz and (60±1) Hz",
"lock": false "lock": false
@ -247,7 +283,7 @@
"title": "Kp", "title": "Kp",
"type": "float", "type": "float",
"step": 0.1, "step": 0.1,
"suffix": "", "compactHeight": false,
"param": [ "param": [
"pid", "pid",
"ch", "ch",
@ -262,6 +298,8 @@
"type": "float", "type": "float",
"step": 0.1, "step": 0.1,
"suffix": "Hz", "suffix": "Hz",
"noUnitEditing": true,
"compactHeight": false,
"param": [ "param": [
"pid", "pid",
"ch", "ch",
@ -276,6 +314,8 @@
"type": "float", "type": "float",
"step": 0.1, "step": 0.1,
"suffix": "s", "suffix": "s",
"noUnitEditing": true,
"compactHeight": false,
"param": [ "param": [
"pid", "pid",
"ch", "ch",
@ -295,13 +335,17 @@
"name": "output_min", "name": "output_min",
"title": "Minimum", "title": "Minimum",
"type": "float", "type": "float",
"step": 100, "step": 0.1,
"limits": [ "limits": [
-2000, -2,
2000 2
], ],
"decimals": 6, "decimals": 6,
"suffix": "mA", "siPrefix": true,
"pinSiPrefix": "m",
"suffix": "A",
"noUnitEditing": true,
"compactHeight": false,
"param": [ "param": [
"pid", "pid",
"ch", "ch",
@ -314,13 +358,17 @@
"name": "output_max", "name": "output_max",
"title": "Maximum", "title": "Maximum",
"type": "float", "type": "float",
"step": 100, "step": 0.1,
"limits": [ "limits": [
-2000, -2,
2000 2
], ],
"decimals": 6, "decimals": 6,
"suffix": "mA", "siPrefix": true,
"pinSiPrefix": "m",
"suffix": "A",
"noUnitEditing": true,
"compactHeight": false,
"param": [ "param": [
"pid", "pid",
"ch", "ch",
@ -333,7 +381,7 @@
}, },
{ {
"name": "pid_autotune", "name": "pid_autotune",
"title": "PID Auto Tune", "title": "PID Autotune",
"expanded": false, "expanded": false,
"type": "group", "type": "group",
"tip": "Automatically tune PID parameters", "tip": "Automatically tune PID parameters",
@ -344,7 +392,11 @@
"type": "float", "type": "float",
"value": 20, "value": 20,
"step": 0.1, "step": 0.1,
"format": "{value:.4f} °C", "format": "{value:.4f} {suffix}",
"suffix": "°C",
"regex": "(?P<number>[+-]?((((\\d+(\\.\\d*)?)|(\\d*\\.\\d+))([eE][+-]?\\d+)?)|((?i:nan)|(inf))))\\s*((?P<siPrefix>[uyzafpnµm kMGTPEZY]?)(?P<suffix>.*))?$",
"noUnitEditing": true,
"compactHeight": false,
"pid_autotune": [ "pid_autotune": [
"target_temp", "target_temp",
"ch" "ch"
@ -357,12 +409,16 @@
"type": "float", "type": "float",
"value": 0, "value": 0,
"decimals": 6, "decimals": 6,
"step": 100, "step": 0.1,
"limits": [ "limits": [
-2000, 0,
2000 2
], ],
"suffix": "mA", "siPrefix": true,
"pinSiPrefix": "m",
"suffix": "A",
"noUnitEditing": true,
"compactHeight": false,
"pid_autotune": [ "pid_autotune": [
"test_current", "test_current",
"ch" "ch"
@ -375,8 +431,11 @@
"type": "float", "type": "float",
"value": 1.5, "value": 1.5,
"step": 0.1, "step": 0.1,
"prefix": "±", "format": "{value:.4f} {suffix}",
"format": "{value:.4f} °C", "suffix": "°C",
"regex": "(?P<number>[+-]?((((\\d+(\\.\\d*)?)|(\\d*\\.\\d+))([eE][+-]?\\d+)?)|((?i:nan)|(inf))))\\s*((?P<siPrefix>[uyzafpnµm kMGTPEZY]?)(?P<suffix>.*))?$",
"noUnitEditing": true,
"compactHeight": false,
"pid_autotune": [ "pid_autotune": [
"temp_swing", "temp_swing",
"ch" "ch"
@ -389,7 +448,10 @@
"type": "float", "type": "float",
"value": 3.0, "value": 3.0,
"step": 0.1, "step": 0.1,
"format": "{value:.4f} s", "format": "{value:.4f} {suffix}",
"noUnitEditing": true,
"suffix": "s",
"compactHeight": false,
"pid_autotune": [ "pid_autotune": [
"lookback", "lookback",
"ch" "ch"

View File

@ -0,0 +1,147 @@
from PyQt6.QtCore import QSignalBlocker
from PyQt6.QtGui import QValidator
from pyqtgraph import SpinBox
from pyqtgraph.parametertree import registerParameterItemType
import pyqtgraph.parametertree.parameterTypes as pTypes
import pyqtgraph.functions as fn
class PinSIPrefixSpinBox(SpinBox):
"""
Extension of PyQtGraph's SpinBox widget.
Adds:
* "pinSiPrefix" option, where the siPrefix could be fixed to a particular scale
* "noUnitEditing" option, where the unit portion of the SpinBox text, including
the siPrefix, is fixed and uneditable.
"""
def __init__(self, parent=None, value=0.0, **kwargs):
super().__init__(parent, value, **kwargs)
self._current_si_prefix = ""
self.lineEdit().cursorPositionChanged.connect(self.editor_cursor_position_changed)
def validate(self, strn, pos):
ret, strn, pos = super().validate(strn, pos)
if "noUnitEditing" in self.opts and self.opts["noUnitEditing"] is True:
suffix = self.opts.get("suffix", "")
# When the unit is edited / removed
if not (
strn.endswith(suffix)
and strn.removesuffix(suffix).endswith(self._current_si_prefix)
):
# Then the input is invalid instead of incomplete, reject this change
ret = QValidator.State.Invalid
return ret, strn, pos
def editor_cursor_position_changed(self, oldpos, newpos):
"""
Modified from the original Qt C++ source,
QAbstractSpinBox::editorCursorPositionChanged
Their suffix is different than our suffix; there's no obvious
way to set that one here.
"""
if "noUnitEditing" in self.opts and self.opts["noUnitEditing"] is True:
edit = self.lineEdit()
if edit.hasSelectedText():
return # Allow for selecting units, for copy-and-paste
unit_len = len(self._current_si_prefix) + len(self.opts.get("suffix", ""))
text_len = len(edit.text())
pos = -1
# Cursor in unit
if text_len - unit_len < newpos < text_len:
if oldpos == text_len:
pos = text_len - unit_len
else:
pos = text_len
if pos != -1:
with QSignalBlocker(edit):
edit.setCursorPosition(pos)
def setOpts(self, **opts):
if "pinSiPrefix" in opts:
self.opts["pinSiPrefix"] = opts.pop("pinSiPrefix")
if "noUnitEditing" in opts:
self.opts["noUnitEditing"] = opts.pop("noUnitEditing")
super().setOpts(**opts)
def formatText(self, prev=None):
"""
Implement 'pinSiPrefix' mechanism for pyqtgraph.SpinBox, where SI prefixes could
be pinned down.
Code modified from the PyQtGraph source
"""
# get the number of decimal places to print
decimals = self.opts['decimals']
suffix = self.opts['suffix']
prefix = self.opts['prefix']
pin_si_prefix = self.opts.get("pinSiPrefix")
# format the string
val = self.value()
if self.opts['siPrefix'] is True:
# SI prefix was requested, so scale the value accordingly
if pin_si_prefix is not None and pin_si_prefix in fn.SI_PREFIX_EXPONENTS:
# fixed scale
s = 10**-fn.SI_PREFIX_EXPONENTS[pin_si_prefix]
p = pin_si_prefix
elif self.val == 0 and prev is not None:
# special case: if it's zero use the previous prefix
(s, p) = fn.siScale(prev)
else:
(s, p) = fn.siScale(val)
parts = {'value': val, 'suffix': suffix, 'decimals': decimals, 'siPrefix': p, 'scaledValue': s*val, 'prefix':prefix}
self._current_si_prefix = p
else:
# no SI prefix /suffix requested; scale is 1
parts = {'value': val, 'suffix': suffix, 'decimals': decimals, 'siPrefix': '', 'scaledValue': val, 'prefix':prefix}
parts['prefixGap'] = '' if parts['prefix'] == '' else ' '
parts['suffixGap'] = '' if (parts['suffix'] == '' and parts['siPrefix'] == '') else ' '
return self.opts['format'].format(**parts)
class PinSIPrefixNumericParameterItem(pTypes.NumericParameterItem):
def makeWidget(self):
opts = self.param.opts
t = opts['type']
defs = {
'value': 0, 'min': None, 'max': None,
'step': 1.0, 'dec': False,
'siPrefix': False, 'suffix': '', 'decimals': 3,
'pinSiPrefix': None, 'noUnitEditing': False
}
if t == 'int':
defs['int'] = True
defs['minStep'] = 1.0
for k in defs:
if k in opts:
defs[k] = opts[k]
if 'limits' in opts:
defs['min'], defs['max'] = opts['limits']
w = PinSIPrefixSpinBox()
w.setOpts(**defs)
w.sigChanged = w.sigValueChanged
w.sigChanging = w.sigValueChanging
return w
registerParameterItemType(
"float", PinSIPrefixNumericParameterItem, pTypes.SimpleParameter, override=True
)
registerParameterItemType(
"int", PinSIPrefixNumericParameterItem, pTypes.SimpleParameter, override=True
)

View File

@ -82,7 +82,7 @@ class MainWindow(QtWidgets.QMainWindow):
[["load"], partial(self.thermostat.load_cfg, ch)], [["load"], partial(self.thermostat.load_cfg, ch)],
[ [
["pid", "pid_autotune", "run_pid"], ["pid", "pid_autotune", "run_pid"],
partial(self.pid_auto_tune_request, ch), partial(self.pid_autotune_request, ch),
], ],
] ]
for ch in range(self.NUM_CHANNELS) for ch in range(self.NUM_CHANNELS)
@ -262,14 +262,11 @@ class MainWindow(QtWidgets.QMainWindow):
@asyncSlot(object, object) @asyncSlot(object, object)
async def send_command(self, param, changes): async def send_command(self, param, changes):
"""Translates parameter tree changes into thermostat set_param calls""" """Translates parameter tree changes into thermostat set_param calls"""
ch = param.channel ch = param.value()
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":
data /= 1000 # Given in mA
thermostat_param = inner_param.opts["param"] thermostat_param = inner_param.opts["param"]
if thermostat_param[1] == "ch": if thermostat_param[1] == "ch":
thermostat_param[1] = ch thermostat_param[1] = ch
@ -283,10 +280,10 @@ class MainWindow(QtWidgets.QMainWindow):
param.child(*param.childPath(inner_param)).setOpts(lock=False) param.child(*param.childPath(inner_param)).setOpts(lock=False)
if inner_param.opts.get("pid_autotune", None) is not None: if inner_param.opts.get("pid_autotune", None) is not None:
auto_tuner_param = inner_param.opts["pid_autotune"][0] autotuner_param = inner_param.opts["pid_autotune"][0]
if inner_param.opts["pid_autotune"][1] != "ch": if inner_param.opts["pid_autotune"][1] != "ch":
ch = inner_param.opts["pid_autotune"][1] ch = inner_param.opts["pid_autotune"][1]
self.autotuners.set_params(auto_tuner_param, ch, data) self.autotuners.set_params(autotuner_param, ch, data)
if inner_param.opts.get("activaters", None) is not None: if inner_param.opts.get("activaters", None) is not None:
activater = inner_param.opts["activaters"][ activater = inner_param.opts["activaters"][
@ -296,9 +293,13 @@ class MainWindow(QtWidgets.QMainWindow):
if activater[1] == "ch": if activater[1] == "ch":
activater[1] = ch activater[1] = ch
await self.client.set_param(*activater) await self.client.set_param(*activater)
else:
await self.client.set_param(
"pwm", ch, "i_set", inner_param.child("i_set").value()
)
@asyncSlot() @asyncSlot()
async def pid_auto_tune_request(self, ch=0): async def pid_autotune_request(self, ch=0):
match self.autotuners.get_state(ch): match self.autotuners.get_state(ch):
case PIDAutotuneState.STATE_OFF | PIDAutotuneState.STATE_FAILED: case PIDAutotuneState.STATE_OFF | PIDAutotuneState.STATE_FAILED:
self.autotuners.load_params_and_set_ready(ch) self.autotuners.load_params_and_set_ready(ch)