forked from M-Labs/thermostat
Only show either one or another, pid or not
This commit is contained in:
parent
7f7f749e84
commit
68124cd92b
|
@ -1,6 +1,7 @@
|
||||||
from PyQt6 import QtWidgets, QtGui, QtCore
|
from PyQt6 import QtWidgets, QtGui, QtCore
|
||||||
from PyQt6.QtCore import pyqtSignal, QObject, QSignalBlocker, pyqtSlot
|
from PyQt6.QtCore import pyqtSignal, QObject, QSignalBlocker, pyqtSlot
|
||||||
from pyqtgraph.parametertree import Parameter, ParameterTree, ParameterItem
|
import pyqtgraph.parametertree.parameterTypes as pTypes
|
||||||
|
from pyqtgraph.parametertree import Parameter, ParameterTree, ParameterItem, registerParameterType
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from pglive.sources.data_connector import DataConnector
|
from pglive.sources.data_connector import DataConnector
|
||||||
from pglive.kwargs import Axis
|
from pglive.kwargs import Axis
|
||||||
|
@ -32,6 +33,37 @@ def get_argparser():
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
self._get_param_from_value(value.value()).show()
|
||||||
|
|
||||||
|
|
||||||
|
registerParameterType('mutex', MutexParameter)
|
||||||
|
|
||||||
|
|
||||||
class WrappedClient(QObject, Client):
|
class WrappedClient(QObject, Client):
|
||||||
connection_error = pyqtSignal()
|
connection_error = pyqtSignal()
|
||||||
|
|
||||||
|
@ -128,7 +160,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
{'name': 'Temperature', 'type': 'float', 'siPrefix': True, 'suffix': '°C', 'readonly': True},
|
{'name': 'Temperature', 'type': 'float', 'siPrefix': True, 'suffix': '°C', 'readonly': True},
|
||||||
{'name': 'Current through TEC', 'type': 'float', 'siPrefix': True, 'suffix': 'A', 'readonly': True},
|
{'name': 'Current through TEC', 'type': 'float', 'siPrefix': True, 'suffix': 'A', 'readonly': True},
|
||||||
{'name': 'Output Config', 'expanded': True, 'type': 'group', 'children': [
|
{'name': 'Output Config', 'expanded': True, 'type': 'group', 'children': [
|
||||||
{'name': 'Control Method', 'type': 'list', 'limits': {'Current Setpoint': False, 'Temperature PID': True},
|
{'name': 'Control Method', 'type': 'mutex', 'limits': {'Current Setpoint': False, 'Temperature PID': True},
|
||||||
'commands': [f'pwm {ch} pid'], 'children': [
|
'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')]},
|
||||||
|
@ -586,22 +618,23 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
@asyncSlot(object, object)
|
@asyncSlot(object, object)
|
||||||
async def send_command(self, param, changes):
|
async def send_command(self, param, changes):
|
||||||
for inner_param, change, data in changes:
|
for inner_param, change, data in changes:
|
||||||
if inner_param.opts.get("commands", None) is not None:
|
if change == 'value':
|
||||||
ch = param.value()
|
if inner_param.opts.get("commands", None) is not None:
|
||||||
match inner_param.name():
|
ch = param.value()
|
||||||
case 'Control Method':
|
match inner_param.name():
|
||||||
pid_enabled = data
|
case 'Control Method':
|
||||||
getattr(self, f'ch{ch}_t_line').setVisible(pid_enabled)
|
pid_enabled = data
|
||||||
if pid_enabled:
|
getattr(self, f'ch{ch}_t_line').setVisible(pid_enabled)
|
||||||
getattr(self, f'ch{ch}_t_line').setValue(inner_param.child('Set Temperature').value())
|
if pid_enabled:
|
||||||
else:
|
getattr(self, f'ch{ch}_t_line').setValue(inner_param.child('Set Temperature').value())
|
||||||
await self.client.set_param('pwm', ch, 'i_set', inner_param.child('Constant Current').value())
|
else:
|
||||||
return
|
await self.client.set_param('pwm', ch, 'i_set', inner_param.child('Constant Current').value())
|
||||||
case 'Set Temperature':
|
return
|
||||||
getattr(self, f'ch{ch}_t_line').setValue(data)
|
case 'Set Temperature':
|
||||||
await asyncio.gather(*[self.client._command(x.format(value=data)) for x in inner_param.opts["commands"]])
|
getattr(self, f'ch{ch}_t_line').setValue(data)
|
||||||
elif inner_param.opts.get("param", None) is not None:
|
await asyncio.gather(*[self.client._command(x.format(value=data)) for x in inner_param.opts["commands"]])
|
||||||
await asyncio.gather(*[self.client.set_param(*x, data) for x in inner_param.opts["param"]])
|
elif inner_param.opts.get("param", None) is not None:
|
||||||
|
await asyncio.gather(*[self.client.set_param(*x, data) for x in inner_param.opts["param"]])
|
||||||
|
|
||||||
|
|
||||||
def _set_param_tree(self):
|
def _set_param_tree(self):
|
||||||
|
|
Loading…
Reference in New Issue