Status bar limits warning

This commit is contained in:
atse 2023-09-26 17:43:40 +08:00
parent e4d1f0133e
commit 442450667b
3 changed files with 51 additions and 6 deletions

View File

@ -85,14 +85,12 @@ class WrappedClient(QObject, Client):
async def _check_zero_limits(self): async def _check_zero_limits(self):
pwm_report = await self.get_pwm() pwm_report = await self.get_pwm()
for pwm_channel in pwm_report: for pwm_channel in pwm_report:
ch = pwm_channel["channel"]
if (neg := pwm_channel["max_i_neg"]["value"]) != (pos := pwm_channel["max_i_pos"]["value"]): if (neg := pwm_channel["max_i_neg"]["value"]) != (pos := pwm_channel["max_i_pos"]["value"]):
# Set the minimum of the 2 # Set the minimum of the 2
lcd = min(neg, pos) lowest = min(neg, pos)
await self.set_param("pwm", pwm_channel["channel"], 'max_i_neg', lcd) await self.set_param("pwm", ch, 'max_i_neg', lowest)
await self.set_param("pwm", pwm_channel["channel"], 'max_i_pos', lcd) await self.set_param("pwm", ch, 'max_i_pos', lowest)
for limit in ["max_i_pos", "max_v"]:
if pwm_channel[limit]["value"] == 0.0:
QtWidgets.QMessageBox.warning(self.parent(), "Limits", "Max {} is set to zero on channel {}!".format("Current" if limit == "max_i_pos" else "Voltage", pwm_channel["channel"]))
class ClientWatcher(QObject): class ClientWatcher(QObject):
@ -509,6 +507,39 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.plot_settings.setMenu(self.plot_menu) self.plot_settings.setMenu(self.plot_menu)
@pyqtSlot(list)
def set_limits_warning(self, limits_zeroed: list):
for channel in limits_zeroed:
if len(channel) != 0:
break
else:
self.limits_warning.setPixmap(QtGui.QPixmap())
self.limits_warning.setToolTip("")
return
report_str = "The following output limits are set to zero:\n"
for ch in range(2):
had_zeros = False
first = True
for limit in "max_i_pos", "max_v":
if limit in limits_zeroed[ch]:
if not first:
report_str += ", "
if not had_zeros:
report_str += f"Channel {ch}: "
had_zeros = True
report_str += '"Max Absolute Current"' if limit == "max_i_pos" else '"Max Absolute Voltage"'
first = False
if had_zeros:
report_str += '\n'
report_str += "\nThere will be no overall output on channels with zeroed limits."
pixmapi = getattr(QtWidgets.QStyle.StandardPixmap, "SP_MessageBoxWarning")
icon = self.style().standardIcon(pixmapi)
self.limits_warning.setPixmap(icon.pixmap(16, 16))
self.limits_warning.setToolTip(report_str)
@pyqtSlot(int) @pyqtSlot(int)
def set_max_samples(self, samples: int): def set_max_samples(self, samples: int):
for channel_graph in self.channel_graphs: for channel_graph in self.channel_graphs:
@ -767,12 +798,20 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
@pyqtSlot(list) @pyqtSlot(list)
def update_pwm(self, pwm_data): def update_pwm(self, pwm_data):
channel_zeroed_limits = [[] for i in range(2)]
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", "Limits", "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", "Limits", "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"])
for limit in "max_i_pos", "max_v":
if pwm_params[limit]["value"] == 0.0:
channel_zeroed_limits[channel].append(limit)
self.set_limits_warning(channel_zeroed_limits)
@pyqtSlot(list) @pyqtSlot(list)
def update_postfilter(self, postfilter_data): def update_postfilter(self, postfilter_data):
for postfilter_params in postfilter_data: for postfilter_params in postfilter_data:

View File

@ -252,6 +252,9 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLabel" name="limits_warning"/>
</item>
<item> <item>
<widget class="QLabel" name="background_task_lbl"> <widget class="QLabel" name="background_task_lbl">
<property name="text"> <property name="text">

View File

@ -127,6 +127,9 @@ class Ui_MainWindow(object):
self.plot_settings.setPopupMode(QtWidgets.QToolButton.ToolButtonPopupMode.InstantPopup) self.plot_settings.setPopupMode(QtWidgets.QToolButton.ToolButtonPopupMode.InstantPopup)
self.plot_settings.setObjectName("plot_settings") self.plot_settings.setObjectName("plot_settings")
self.settings_layout.addWidget(self.plot_settings) self.settings_layout.addWidget(self.plot_settings)
self.limits_warning = QtWidgets.QLabel(parent=self.bottom_settings_group)
self.limits_warning.setObjectName("limits_warning")
self.settings_layout.addWidget(self.limits_warning)
self.background_task_lbl = QtWidgets.QLabel(parent=self.bottom_settings_group) self.background_task_lbl = QtWidgets.QLabel(parent=self.bottom_settings_group)
self.background_task_lbl.setObjectName("background_task_lbl") self.background_task_lbl.setObjectName("background_task_lbl")
self.settings_layout.addWidget(self.background_task_lbl) self.settings_layout.addWidget(self.background_task_lbl)