Destroy changed IOs after piCtory changes

This commit is contained in:
2020-11-12 19:48:56 +01:00
parent 146dd74c95
commit 1fd1d37fa7
4 changed files with 28 additions and 37 deletions

2
.idea/misc.xml generated
View File

@@ -3,7 +3,7 @@
<component name="JavaScriptSettings"> <component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" /> <option name="languageLevel" value="ES6" />
</component> </component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
<component name="PythonCompatibilityInspectionAdvertiser"> <component name="PythonCompatibilityInspectionAdvertiser">
<option name="version" value="3" /> <option name="version" value="3" />
</component> </component>

View File

@@ -6,7 +6,7 @@
<sourceFolder url="file://$MODULE_DIR$/revpicommander" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/revpicommander" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/lib/revpimodio2" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/lib/revpimodio2" isTestSource="false" />
</content> </content>
<orderEntry type="jdk" jdkName="Python 3.6" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Python 3.8" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

View File

@@ -194,10 +194,6 @@ class DebugControl(QtWidgets.QWidget, Ui_wid_debugcontrol):
int.from_bytes(value_procimg, byteorder=io[5], signed=io[6]) & 1 << io[4] int.from_bytes(value_procimg, byteorder=io[5], signed=io[6]) & 1 << io[4]
) )
if self.driver_reset_detected:
# Change last value to save the actual states of outputs
win.set_last_value(io[0], value_procimg)
if (refresh or write_out) and io_type == "out": if (refresh or write_out) and io_type == "out":
widget_value, last_value = win.get_value(io[0]) widget_value, last_value = win.get_value(io[0])
if widget_value != last_value: if widget_value != last_value:
@@ -290,7 +286,7 @@ class DebugControl(QtWidgets.QWidget, Ui_wid_debugcontrol):
# ps_devices format: [[0, 'picore01'], [32, 'di01'], ... # ps_devices format: [[0, 'picore01'], [32, 'di01'], ...
dict_devices = {v[0]: v[1] for v in helper.cm.call_remote_function("ps_devices", default_value=[])} dict_devices = {v[0]: v[1] for v in helper.cm.call_remote_function("ps_devices", default_value=[])}
if len(dict_devices) == 0: if len(dict_devices) == 0:
# There is not piCtory configuration on the Revolution Pi # There is no piCtory configuration on the Revolution Pi
return False return False
# Remove not existing or renamed devices # Remove not existing or renamed devices

View File

@@ -20,6 +20,7 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
"""This window was closed.""" """This window was closed."""
do_read = QtCore.pyqtSignal() do_read = QtCore.pyqtSignal()
do_write = QtCore.pyqtSignal() do_write = QtCore.pyqtSignal()
search_class = (QtWidgets.QLineEdit, QtWidgets.QDoubleSpinBox, QtWidgets.QCheckBox)
def __init__(self, position: int, name: str, inputs: list, outputs: list, parent=None): def __init__(self, position: int, name: str, inputs: list, outputs: list, parent=None):
super(DebugIos, self).__init__(parent) super(DebugIos, self).__init__(parent)
@@ -36,7 +37,6 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
self.name = name self.name = name
self.inputs = inputs.copy() self.inputs = inputs.copy()
self.outputs = outputs.copy() self.outputs = outputs.copy()
self.search_class = (QtWidgets.QLineEdit, QtWidgets.QDoubleSpinBox, QtWidgets.QCheckBox)
self.write_values = False self.write_values = False
min_input = min(inputs, key=lambda k: k[2]) min_input = min(inputs, key=lambda k: k[2])
@@ -61,7 +61,8 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
helper.cm.debug_geos[self.position] = self.saveGeometry() helper.cm.debug_geos[self.position] = self.saveGeometry()
self.device_closed.emit(self.position) self.device_closed.emit(self.position)
def _calc_min_max(self, byte_length: int, signed: bool): @staticmethod
def _calc_min_max(byte_length: int, signed: bool):
"""Calculate min an max value which fits to bytes.""" """Calculate min an max value which fits to bytes."""
max_int_value = 256 ** byte_length max_int_value = 256 ** byte_length
return max_int_value / 2 * -1 if signed else 0.0, \ return max_int_value / 2 * -1 if signed else 0.0, \
@@ -88,9 +89,18 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
byteorder = io[5] byteorder = io[5]
signed = io[6] signed = io[6]
if container.findChild(self.search_class, name) is not None: val = container.findChild(self.search_class, name)
# Check properties of this IO if val is not None:
continue # Destroy IO if the properties was changed
if byte_length != val.property("byte_length") or \
bit_address != val.property("bit_address") or \
byteorder != ("big" if val.property("big_endian") else "little") or \
signed != val.property("signed"):
del self.__qwa[name]
layout.removeRow(layout.getWidgetPosition(val)[0])
pi.logger.debug("Destroy property changed IO '{0}'".format(name))
else:
continue
lbl = QtWidgets.QLabel(name, container) lbl = QtWidgets.QLabel(name, container)
lbl.setObjectName("lbl_".format(name)) lbl.setObjectName("lbl_".format(name))
@@ -118,9 +128,6 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
# Bytes or string # Bytes or string
val = QtWidgets.QLineEdit() val = QtWidgets.QLineEdit()
val.setReadOnly(read_only) val.setReadOnly(read_only)
val.setProperty("big_endian", byteorder == "big")
val.setProperty("byte_length", byte_length)
val.setProperty("signed", signed)
val.setProperty("struct_type", "text") val.setProperty("struct_type", "text")
val.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) val.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
@@ -137,12 +144,9 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
val = QtWidgets.QDoubleSpinBox() val = QtWidgets.QDoubleSpinBox()
val.setReadOnly(read_only) val.setReadOnly(read_only)
val.setProperty("big_endian", byteorder == "big")
val.setProperty("byte_length", byte_length)
val.setProperty("signed", signed)
val.setProperty("struct_type", struct_type) val.setProperty("struct_type", struct_type)
val.setProperty("frm", "{0}{1}".format( val.setProperty("frm", "{0}{1}".format(
">" if val.property("big_endian") else "<", ">" if byteorder == "big" else "<",
struct_type.lower() if signed else struct_type struct_type.lower() if signed else struct_type
)) ))
@@ -157,6 +161,11 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
val.valueChanged.connect(self._change_sbx_dvalue) val.valueChanged.connect(self._change_sbx_dvalue)
val.setObjectName(name) val.setObjectName(name)
val.setProperty("big_endian", byteorder == "big")
val.setProperty("bit_address", bit_address)
val.setProperty("byte_length", byte_length)
val.setProperty("signed", signed)
self.__qwa[name] = val self.__qwa[name] = val
return val return val
@@ -322,28 +331,13 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
else: else:
return actual_value, last_value return actual_value, last_value
def set_last_value(self, io_name: str, value): def set_value(self, io_name: str, value, just_last_value=False):
"""
Set last value for widget to sync after driver reset.
:param io_name: Name of IO
:param value: Process value as <class 'bool'> or <class 'bytes'>
"""
# child = self.findChild(self.search_class, io_name)
child = self.__qwa[io_name]
if child.property("frm"):
value = struct.unpack(child.property("frm"), value)[0]
elif type(value) == bytearray:
value = value.decode()
child.setProperty("last_value", value)
def set_value(self, io_name: str, value):
""" """
Standard set function for a value of different widgets. Standard set function for a value of different widgets.
:param io_name: Name of IO :param io_name: Name of IO
:param value: New value as bytes or bool for widget :param value: New value as bytes or bool for widget
:param just_last_value: Just set last value property
""" """
# child = self.findChild(self.search_class, io_name) # child = self.findChild(self.search_class, io_name)
child = self.__qwa[io_name] child = self.__qwa[io_name]
@@ -360,4 +354,5 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
value = value.decode() value = value.decode()
child.setProperty("last_value", value) child.setProperty("last_value", value)
child.setValue(value) if not just_last_value:
child.setValue(value)