forked from M-Labs/thermostat
ctrl_panel: Use new locking mechanism from Kirdy
This commit is contained in:
parent
ca4f6d05ff
commit
7aec46f882
@ -30,6 +30,11 @@ 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)
|
||||||
|
|
||||||
|
def _set_value_with_lock(self, value):
|
||||||
|
if not self.opts.get("lock"):
|
||||||
|
self.setValue(value)
|
||||||
|
Parameter.set_value_with_lock = _set_value_with_lock
|
||||||
|
|
||||||
self.params = [
|
self.params = [
|
||||||
Parameter.create(
|
Parameter.create(
|
||||||
name=f"Thermostat Channel {ch} Parameters",
|
name=f"Thermostat Channel {ch} Parameters",
|
||||||
@ -47,7 +52,6 @@ class CtrlPanel(QObject):
|
|||||||
set_tree_label_tips(tree)
|
set_tree_label_tips(tree)
|
||||||
|
|
||||||
for ch, param in enumerate(self.params):
|
for ch, param in enumerate(self.params):
|
||||||
self.params[ch].setValue = self._setValue
|
|
||||||
param.sigTreeStateChanged.connect(sigTreeStateChanged_handle)
|
param.sigTreeStateChanged.connect(sigTreeStateChanged_handle)
|
||||||
|
|
||||||
for handle in sigActivated_handles[ch]:
|
for handle in sigActivated_handles[ch]:
|
||||||
@ -77,32 +81,6 @@ class CtrlPanel(QObject):
|
|||||||
font.setBold(True)
|
font.setBold(True)
|
||||||
item.setFont(0, font)
|
item.setFont(0, font)
|
||||||
|
|
||||||
def _setValue(self, value, blockSignal=None):
|
|
||||||
"""
|
|
||||||
Implement 'lock' mechanism for Parameter Type
|
|
||||||
|
|
||||||
Modified from the source
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
if blockSignal is not None:
|
|
||||||
self.sigValueChanged.disconnect(blockSignal)
|
|
||||||
value = self._interpretValue(value)
|
|
||||||
if fn.eq(self.opts["value"], value):
|
|
||||||
return value
|
|
||||||
|
|
||||||
if "lock" in self.opts.keys():
|
|
||||||
if self.opts["lock"]:
|
|
||||||
return value
|
|
||||||
self.opts["value"] = value
|
|
||||||
self.sigValueChanged.emit(
|
|
||||||
self, value
|
|
||||||
) # value might change after signal is received by tree item
|
|
||||||
finally:
|
|
||||||
if blockSignal is not None:
|
|
||||||
self.sigValueChanged.connect(blockSignal)
|
|
||||||
|
|
||||||
return self.opts["value"]
|
|
||||||
|
|
||||||
def change_params_title(self, channel, path, title):
|
def change_params_title(self, channel, path, title):
|
||||||
self.params[channel].child(*path).setOpts(title=title)
|
self.params[channel].child(*path).setOpts(title=title)
|
||||||
|
|
||||||
@ -111,57 +89,59 @@ class CtrlPanel(QObject):
|
|||||||
for settings in pid_settings:
|
for settings in pid_settings:
|
||||||
channel = settings["channel"]
|
channel = settings["channel"]
|
||||||
with QSignalBlocker(self.params[channel]):
|
with QSignalBlocker(self.params[channel]):
|
||||||
self.params[channel].child("pid", "kp").setValue(
|
self.params[channel].child("pid", "kp").set_value_with_lock(
|
||||||
settings["parameters"]["kp"]
|
settings["parameters"]["kp"]
|
||||||
)
|
)
|
||||||
self.params[channel].child("pid", "ki").setValue(
|
self.params[channel].child("pid", "ki").set_value_with_lock(
|
||||||
settings["parameters"]["ki"]
|
settings["parameters"]["ki"]
|
||||||
)
|
)
|
||||||
self.params[channel].child("pid", "kd").setValue(
|
self.params[channel].child("pid", "kd").set_value_with_lock(
|
||||||
settings["parameters"]["kd"]
|
settings["parameters"]["kd"]
|
||||||
)
|
)
|
||||||
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"])
|
).set_value_with_lock(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"])
|
).set_value_with_lock(settings["parameters"]["output_max"])
|
||||||
self.params[channel].child(
|
self.params[channel].child(
|
||||||
"output", "control_method", "target"
|
"output", "control_method", "target"
|
||||||
).setValue(settings["target"])
|
).set_value_with_lock(settings["target"])
|
||||||
|
|
||||||
@pyqtSlot("QVariantList")
|
@pyqtSlot("QVariantList")
|
||||||
def update_report(self, report_data):
|
def update_report(self, report_data):
|
||||||
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("output", "control_method").setValue(
|
self.params[channel].child(
|
||||||
|
"output", "control_method"
|
||||||
|
).set_value_with_lock(
|
||||||
"temperature_pid" if settings["pid_engaged"] else "constant_current"
|
"temperature_pid" if settings["pid_engaged"] else "constant_current"
|
||||||
)
|
)
|
||||||
self.params[channel].child(
|
self.params[channel].child(
|
||||||
"output", "control_method", "i_set"
|
"output", "control_method", "i_set"
|
||||||
).setValue(settings["i_set"])
|
).set_value_with_lock(settings["i_set"])
|
||||||
if settings["temperature"] is not None:
|
if settings["temperature"] is not None:
|
||||||
self.params[channel].child("readings", "temperature").setValue(
|
self.params[channel].child(
|
||||||
settings["temperature"]
|
"readings", "temperature"
|
||||||
)
|
).set_value_with_lock(settings["temperature"])
|
||||||
if settings["tec_i"] is not None:
|
if settings["tec_i"] is not None:
|
||||||
self.params[channel].child("readings", "tec_i").setValue(
|
self.params[channel].child(
|
||||||
settings["tec_i"]
|
"readings", "tec_i"
|
||||||
)
|
).set_value_with_lock(settings["tec_i"])
|
||||||
|
|
||||||
@pyqtSlot("QVariantList")
|
@pyqtSlot("QVariantList")
|
||||||
def update_thermistor(self, sh_data):
|
def update_thermistor(self, sh_data):
|
||||||
for sh_param in sh_data:
|
for sh_param in sh_data:
|
||||||
channel = sh_param["channel"]
|
channel = sh_param["channel"]
|
||||||
with QSignalBlocker(self.params[channel]):
|
with QSignalBlocker(self.params[channel]):
|
||||||
self.params[channel].child("thermistor", "t0").setValue(
|
self.params[channel].child("thermistor", "t0").set_value_with_lock(
|
||||||
sh_param["params"]["t0"] - 273.15
|
sh_param["params"]["t0"] - 273.15
|
||||||
)
|
)
|
||||||
self.params[channel].child("thermistor", "r0").setValue(
|
self.params[channel].child("thermistor", "r0").set_value_with_lock(
|
||||||
sh_param["params"]["r0"]
|
sh_param["params"]["r0"]
|
||||||
)
|
)
|
||||||
self.params[channel].child("thermistor", "b").setValue(
|
self.params[channel].child("thermistor", "b").set_value_with_lock(
|
||||||
sh_param["params"]["b"]
|
sh_param["params"]["b"]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -172,15 +152,15 @@ class CtrlPanel(QObject):
|
|||||||
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", "limits", "max_v").setValue(
|
self.params[channel].child(
|
||||||
pwm_params["max_v"]["value"]
|
"output", "limits", "max_v"
|
||||||
)
|
).set_value_with_lock(pwm_params["max_v"]["value"])
|
||||||
self.params[channel].child("output", "limits", "max_i_pos").setValue(
|
self.params[channel].child(
|
||||||
pwm_params["max_i_pos"]["value"]
|
"output", "limits", "max_i_pos"
|
||||||
)
|
).set_value_with_lock(pwm_params["max_i_pos"]["value"])
|
||||||
self.params[channel].child("output", "limits", "max_i_neg").setValue(
|
self.params[channel].child(
|
||||||
pwm_params["max_i_neg"]["value"]
|
"output", "limits", "max_i_neg"
|
||||||
)
|
).set_value_with_lock(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":
|
||||||
if pwm_params[limit]["value"] == 0.0:
|
if pwm_params[limit]["value"] == 0.0:
|
||||||
@ -192,6 +172,6 @@ class CtrlPanel(QObject):
|
|||||||
for postfilter_params in postfilter_data:
|
for postfilter_params in postfilter_data:
|
||||||
channel = postfilter_params["channel"]
|
channel = postfilter_params["channel"]
|
||||||
with QSignalBlocker(self.params[channel]):
|
with QSignalBlocker(self.params[channel]):
|
||||||
self.params[channel].child("thermistor", "rate").setValue(
|
self.params[channel].child("thermistor", "rate").set_value_with_lock(
|
||||||
postfilter_params["rate"]
|
postfilter_params["rate"]
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user