diff --git a/src/main/python/main/ayab/engine/communication_mock.py b/src/main/python/main/ayab/engine/communication_mock.py index 837f132e..f90415a5 100644 --- a/src/main/python/main/ayab/engine/communication_mock.py +++ b/src/main/python/main/ayab/engine/communication_mock.py @@ -22,7 +22,6 @@ import logging from time import sleep -from collections import deque from PySide6.QtWidgets import QMessageBox @@ -47,8 +46,9 @@ def __del__(self) -> None: def reset(self): self.__is_open = False self.__is_started = False - self.rx_msg_list = deque([], maxlen=100) + self.rx_msg_list = list() self.__line_count = 0 + self.__started_row = False def is_open(self) -> bool: """Return status of the interface.""" @@ -109,29 +109,36 @@ def cnf_line_API6(self, line_number, color, flags, line_data) -> bool: """Send a row of stitch data.""" return True - def update_API6(self) -> tuple[bytes, Token, int]: + def update_API6(self) -> tuple[bytes | None, Token, int]: """Read and parse data packet.""" if self.__is_open and self.__is_started: - reqLine = bytes([Token.reqLine.value, self.__line_count]) - self.__line_count += 1 - self.__line_count %= 256 - self.rx_msg_list.append(reqLine) - if self.__delay: - sleep(1) # wait for knitting progress dialog to update - # step through output line by line - if self.__step: - # pop up box waits for user input before moving on to next line - msg = QMessageBox() - msg.setIcon(QMessageBox.Icon.Information) - msg.setText("Line number = " + str(self.__line_count)) - msg.setStandardButtons( - QMessageBox.StandardButton.Ok | QMessageBox.StandardButton.Cancel - ) - ret = None - ret = msg.exec_() - while ret is None: - pass + # Alternate between reqLine and no message + # (so that the UI makes the end-of-line sound for each row) + if self.__started_row: + self.__started_row = False + reqLine = bytes([Token.reqLine.value, self.__line_count]) + self.__line_count += 1 + self.__line_count %= 256 + self.rx_msg_list.append(reqLine) + if self.__delay: + sleep(1) # wait for knitting progress dialog to update + # step through output line by line + if self.__step: + # pop up box waits for user input before moving on to next line + msg = QMessageBox() + msg.setIcon(QMessageBox.Icon.Information) + msg.setText("Line number = " + str(self.__line_count)) + msg.setStandardButtons( + QMessageBox.StandardButton.Ok + | QMessageBox.StandardButton.Cancel + ) + ret = None + ret = msg.exec_() + while ret is None: + pass + else: + self.__started_row = True if len(self.rx_msg_list) > 0: - return self.parse_API6(self.rx_msg_list.popleft()) # FIFO + return self.parse_API6(self.rx_msg_list.pop(0)) # FIFO # else return self.parse_API6(None) diff --git a/src/main/python/main/ayab/tests/test_communication_mock.py b/src/main/python/main/ayab/tests/test_communication_mock.py index 8bee5a86..452efc6b 100644 --- a/src/main/python/main/ayab/tests/test_communication_mock.py +++ b/src/main/python/main/ayab/tests/test_communication_mock.py @@ -107,6 +107,9 @@ def test_req_line_API6(self): ) self.comm_dummy.update_API6() # cnfStart + # Alternates between requesting a line and no output for i in range(0, 256): bytes_read = self.comm_dummy.update_API6() assert bytes_read == (bytearray([Token.reqLine.value, i]), Token.reqLine, i) + bytes_read = self.comm_dummy.update_API6() + assert bytes_read == (None, Token.none, 0)