Interface change

This commit is contained in:
atse 2023-08-22 13:22:07 +08:00
parent 4c839f079b
commit 7f7f749e84
1 changed files with 29 additions and 22 deletions

View File

@ -125,19 +125,23 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
"""Thermostat parameters that are particular to a channel""" """Thermostat parameters that are particular to a channel"""
THERMOSTAT_PARAMETERS = [[ THERMOSTAT_PARAMETERS = [[
{'name': 'Temperature', 'type': 'float', 'siPrefix': True, 'suffix': '°C', 'readonly': True},
{'name': 'Current through TEC', 'type': 'float', 'siPrefix': True, 'suffix': 'A', 'readonly': True},
{'name': 'Output Config', 'expanded': True, 'type': 'group', 'children': [
{'name': 'Control Method', 'type': 'list', 'limits': {'Current Setpoint': False, 'Temperature PID': True},
'commands': [f'pwm {ch} pid'], 'children': [
{'name': 'Constant Current', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (-3, 3), 'siPrefix': True, {'name': 'Constant Current', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (-3, 3), 'siPrefix': True,
'suffix': 'A', 'param': [('pwm', ch, 'i_set')]}, 'suffix': 'A', 'param': [('pwm', ch, 'i_set')]},
{'name': 'Temperature PID', 'type': 'bool', 'value': False, 'commands': [f'pwm {ch} pid'],
'children': [
{'name': 'Set Temperature', 'type': 'float', 'value': 25, 'step': 0.1, 'limits': (-273, 300), 'siPrefix': True, {'name': 'Set Temperature', 'type': 'float', 'value': 25, 'step': 0.1, 'limits': (-273, 300), 'siPrefix': True,
'suffix': '°C', 'param': [('pid', ch, 'target')]}, 'suffix': '°C', 'param': [('pid', ch, 'target')]},
]}, ]},
{'name': 'Output Config', 'expanded': False, 'type': 'group', 'children': [ {'name': 'Limits', 'expanded': False, 'type': 'group', 'children': [
{'name': 'Max Absolute Current', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (0, 3), 'siPrefix': True, {'name': 'Max Absolute Current', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (0, 3), 'siPrefix': True,
'suffix': 'A', 'commands': [f'pwm {ch} max_i_pos {{value}}', f'pwm {ch} max_i_neg {{value}}', 'suffix': 'A', 'commands': [f'pwm {ch} max_i_pos {{value}}', f'pwm {ch} max_i_neg {{value}}',
f'pid {ch} output_min -{{value}}', f'pid {ch} output_max {{value}}']}, f'pid {ch} output_min -{{value}}', f'pid {ch} output_max {{value}}']},
{'name': 'Max Absolute Voltage', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (0, 5), 'siPrefix': True, {'name': 'Max Absolute Voltage', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (0, 5), 'siPrefix': True,
'suffix': 'V', 'param': [('pwm', ch, 'max_v')]}, 'suffix': 'V', 'param': [('pwm', ch, 'max_v')]},
]}
]}, ]},
{'name': 'Thermistor Config', 'expanded': False, 'type': 'group', 'children': [ {'name': 'Thermistor Config', 'expanded': False, 'type': 'group', 'children': [
{'name': 'T₀', 'type': 'float', 'value': 25, 'step': 0.1, 'limits': (-100, 100), 'siPrefix': True, {'name': 'T₀', 'type': 'float', 'value': 25, 'step': 0.1, 'limits': (-100, 100), 'siPrefix': True,
@ -585,13 +589,13 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
if inner_param.opts.get("commands", None) is not None: if inner_param.opts.get("commands", None) is not None:
ch = param.value() ch = param.value()
match inner_param.name(): match inner_param.name():
case 'Temperature PID': case 'Control Method':
pid_enabled = data pid_enabled = data
getattr(self, f'ch{ch}_t_line').setVisible(pid_enabled) getattr(self, f'ch{ch}_t_line').setVisible(pid_enabled)
if pid_enabled: if pid_enabled:
getattr(self, f'ch{ch}_t_line').setValue(inner_param.child('Set Temperature').value()) getattr(self, f'ch{ch}_t_line').setValue(inner_param.child('Set Temperature').value())
else: else:
await self.client.set_param('pwm', ch, 'i_set', param.child('Constant Current').value()) await self.client.set_param('pwm', ch, 'i_set', inner_param.child('Constant Current').value())
return return
case 'Set Temperature': case 'Set Temperature':
getattr(self, f'ch{ch}_t_line').setValue(data) getattr(self, f'ch{ch}_t_line').setValue(data)
@ -614,8 +618,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.params[channel].child("PID Config", "Kp").setValue(settings["parameters"]["kp"]) self.params[channel].child("PID Config", "Kp").setValue(settings["parameters"]["kp"])
self.params[channel].child("PID Config", "Ki").setValue(settings["parameters"]["ki"]) self.params[channel].child("PID Config", "Ki").setValue(settings["parameters"]["ki"])
self.params[channel].child("PID Config", "Kd").setValue(settings["parameters"]["kd"]) self.params[channel].child("PID Config", "Kd").setValue(settings["parameters"]["kd"])
if self.params[channel].child("Temperature PID").value(): if self.params[channel].child("Output Config", "Control Method").value():
self.params[channel].child("Temperature PID", "Set Temperature").setValue(settings["target"]) self.params[channel].child("Output Config", "Control Method", "Set Temperature").setValue(settings["target"])
getattr(self, f'ch{channel}_t_line').setValue(settings["target"]) getattr(self, f'ch{channel}_t_line').setValue(settings["target"])
@pyqtSlot(list) @pyqtSlot(list)
@ -623,10 +627,13 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
for settings in report_data: for settings in report_data:
channel = settings["channel"] channel = settings["channel"]
with QSignalBlocker(self.params[channel]): with QSignalBlocker(self.params[channel]):
self.params[channel].child("Temperature PID").setValue(settings["pid_engaged"]) self.params[channel].child("Output Config", "Control Method").setValue(settings["pid_engaged"])
getattr(self, f'ch{channel}_t_line').setVisible(settings["pid_engaged"]) getattr(self, f'ch{channel}_t_line').setVisible(settings["pid_engaged"])
if not settings["pid_engaged"]: self.params[channel].child("Output Config", "Control Method", "Constant Current").setValue(settings["i_set"])
self.params[channel].child("Constant Current").setValue(settings["i_set"]) if settings['temperature'] is not None:
self.params[channel].child("Temperature").setValue(settings['temperature'])
if settings['tec_i'] is not None:
self.params[channel].child("Current through TEC").setValue(settings['tec_i'])
@pyqtSlot(list) @pyqtSlot(list)
def update_thermistor(self, sh_data): def update_thermistor(self, sh_data):
@ -642,8 +649,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
for pwm_params in pwm_data: for pwm_params in pwm_data:
channel = pwm_params["channel"] channel = pwm_params["channel"]
with QSignalBlocker(self.params[channel]): with QSignalBlocker(self.params[channel]):
self.params[channel].child("Output Config", "Max Absolute Voltage").setValue(pwm_params["max_v"]["value"]) self.params[channel].child("Output Config", "Limits", "Max Absolute Voltage").setValue(pwm_params["max_v"]["value"])
self.params[channel].child("Output Config", "Max Absolute Current").setValue(pwm_params["max_i_pos"]["value"]) self.params[channel].child("Output Config", "Limits", "Max Absolute Current").setValue(pwm_params["max_i_pos"]["value"])
@pyqtSlot(list) @pyqtSlot(list)
def update_postfilter(self, postfilter_data): def update_postfilter(self, postfilter_data):