Skip to content

Commit

Permalink
ui changes, handle same sensors in main screen
Browse files Browse the repository at this point in the history
  • Loading branch information
LoSk-p committed Mar 22, 2024
1 parent 660c918 commit 5c79fd8
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 110 deletions.
36 changes: 29 additions & 7 deletions app/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def __init__(self, sensors):
self._sensor_objects = sensors
self._board_data = BoardData()
self._parser_strategy = None
self._connected_sockets: tp.Dict[str, int] = {}
# self._connected_sockets: tp.Dict[str, int] = {}
self._connected_sockets: tp.Dict[int, str] = {}
self._sensors = {}
self._sockets = {}
for sensor in self._sensor_objects:
Expand Down Expand Up @@ -59,20 +60,38 @@ def parser(self, data: str) -> bool:
return self._parser_strategy.get_parser(data, self._message_id).parse(
self._board_data
)

def get_current_sensor_for_socket(self, socket: int) -> tp.Optional[str]:
return self._connected_sockets.get(socket, None)
# for sensor_name in self._connected_sockets:
# if self._connected_sockets[sensor_name] == socket:
# return sensor_name

def update_connected_sockets(self, connected_sockets: tp.Dict):
self._connected_sockets = connected_sockets
_LOGGER.debug(f"Update connected sockets: {connected_sockets}")

def get_sensors_data(self) -> tp.Dict:
sensors_data = {}
for sensor_name in self._connected_sockets:
sensors_data[sensor_name] = self._board_data.sensors_data[
self._connected_sockets[sensor_name]
]
for socket in self._connected_sockets:
sensors_data[self._connected_sockets[socket]] = self._board_data.sensors_data[socket]
return sensors_data
# sensors_data = {}
# for sensor_name in self._connected_sockets:
# sensors_data[sensor_name] = self._board_data.sensors_data[
# self._connected_sockets[sensor_name]
# ]
# return sensors_data

def get_calibration_coeffs(self, sensor_name: str) -> tp.Dict:
return self._board_data.calibration_coeffs[self._connected_sockets[sensor_name]]
socket = self._get_socket_for_sensor_name(sensor_name)
return self._board_data.calibration_coeffs[socket]
# return self._board_data.calibration_coeffs[self._connected_sockets[sensor_name]]

def _get_socket_for_sensor_name(self, sensor_name: str) -> int:
for socket in self._connected_sockets:
if self._connected_sockets[socket] == sensor_name:
return socket

def get_board_info(self) -> tp.Dict:
return self._board_data.board_info
Expand Down Expand Up @@ -174,8 +193,11 @@ def get_calibration_command(
consentration, solution_number = self._sensors[sensor_name].get_consentration(
calibration_solution
)
# socket_command = self._socket_calibration_commands[
# self._connected_sockets[sensor_name]
# ][solution_number]
socket_command = self._socket_calibration_commands[
self._connected_sockets[sensor_name]
self._get_socket_for_sensor_name(sensor_name)
][solution_number]
return f"{socket_command}{consentration}".encode(), "#?"

Expand Down
17 changes: 17 additions & 0 deletions app/gui/label_color_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from PyQt5.QtWidgets import QLabel, QGraphicsColorizeEffect
from PyQt5.QtGui import QColor
from PyQt5.QtCore import Qt

def set_green_label_color(label: QLabel):
_set_label_color(label, Qt.darkGreen)

def set_red_label_color(label: QLabel):
_set_label_color(label, Qt.darkRed)

def set_yellow_label_color(label: QLabel):
_set_label_color(label, Qt.darkYellow)

def _set_label_color(label: QLabel, color: QColor):
color_effect = QGraphicsColorizeEffect()
color_effect.setColor(color)
label.setGraphicsEffect(color_effect)
Loading

0 comments on commit 5c79fd8

Please sign in to comment.