diff --git a/config/machine_settings/defaults.ini b/config/machine_settings/defaults.ini index 0faf404..b663ba3 100644 --- a/config/machine_settings/defaults.ini +++ b/config/machine_settings/defaults.ini @@ -31,6 +31,10 @@ printer: address: COM3 baudrate: 115200 +[neo_pixels] +address: COM1 +baudrate: 9600 + [vision] detection_threshold: 0.3 ; recipes_path: ./config/vision_test_recipes diff --git a/simulate.sh b/simulate.sh index 80321e0..0a33979 100755 --- a/simulate.sh +++ b/simulate.sh @@ -20,6 +20,7 @@ python -B -u "./src/main.py" \ --sim-camera \ --sim-modbus \ --sim-os-label-printer \ +--sim-serial-neo-pixels \ --style windows \ $* 2> >(sed $'s/.*/\e[31m&\e[m/' >&2) # & # --about \ @@ -27,6 +28,8 @@ $* 2> >(sed $'s/.*/\e[31m&\e[m/' >&2) # & # --auto-login-user \ # --autotests-archive \ # --camera-edits \ +# --interact \ +# --no-gui \ # --no-tflite \ # --sim-archiver \ # --sim-serial-label-printer \ diff --git a/src/components/dummies/serial/serial.py b/src/components/dummies/serial/Serial.py similarity index 74% rename from src/components/dummies/serial/serial.py rename to src/components/dummies/serial/Serial.py index b5663fe..78e9495 100755 --- a/src/components/dummies/serial/serial.py +++ b/src/components/dummies/serial/Serial.py @@ -14,5 +14,12 @@ class Serial: self.log.debug(f"read: {d!r}") return d + def readline(self, n=-1): + if n < 0: + n = 8 + d = b"\x00" * n + self.log.debug(f"readline: {d!r}") + return d + def close(self): self.log.debug("close") diff --git a/src/components/dummies/serial/__init__.py b/src/components/dummies/serial/__init__.py index 31be0b6..bbdb4a6 100755 --- a/src/components/dummies/serial/__init__.py +++ b/src/components/dummies/serial/__init__.py @@ -1,5 +1,5 @@ import serial -from .serial import Serial +from .Serial import Serial serial.Serial = Serial diff --git a/src/components/neo_pixels.py b/src/components/neo_pixels.py index a50d28f..a890f62 100644 --- a/src/components/neo_pixels.py +++ b/src/components/neo_pixels.py @@ -2,7 +2,7 @@ import sys import traceback if "--sim-serial-neo-pixels" in sys.argv: - import components.dummies.serial as serial + from components.dummies.serial import serial else: import serial diff --git a/src/components/serial_label_printer.py b/src/components/serial_label_printer.py index e7ec820..25f385b 100644 --- a/src/components/serial_label_printer.py +++ b/src/components/serial_label_printer.py @@ -1,7 +1,7 @@ import sys if "--sim-serial-label-printer" in sys.argv: - import components.dummies.serial as serial + from components.dummies.serial import serial else: import serial diff --git a/src/main.py b/src/main.py index 74422a5..3dc159a 100644 --- a/src/main.py +++ b/src/main.py @@ -10,8 +10,8 @@ from datetime import datetime from pathlib import Path -def quit_app(signalnum, handler): - print(signalnum, handler) +def quit_app(signalnum=None, handler=None): + logging.info(f"quitting app. signal: {signalnum!r}, handler: {handler!r}") global app app.quit() quit() @@ -48,7 +48,7 @@ logging.basicConfig( try: # IMPORT PROJECT ONLY AFTER SETTING UP SIGNAL, FAULTHANDLER AND LOGGHING - from components import (ArchiveSynchronizer, GalaxyCamera, + from components import (ArchiveSynchronizer, GalaxyCamera, NeoPixels, Os_Label_Printer, RemoteAPI, TecnaMarpossProvasetT3, TestComponent, Vision, VisionSaver) @@ -78,6 +78,7 @@ try: "archive_synchronizer": {"c": ArchiveSynchronizer}, "galaxy_camera": {"c": GalaxyCamera, "k": {"paused": True}}, "label_printer": {"c": Os_Label_Printer, "t": False}, + "neo_pixels": {"c": NeoPixels, "t": False}, "remote_api": {"c": RemoteAPI, "k": {"main": self}}, "tecna_marposs_provaset_t3": {"c": TecnaMarpossProvasetT3}, "vision_saver": {"c": VisionSaver, "t": False}, @@ -104,35 +105,38 @@ try: QMessageBox.critical(None, "Errore Banco", f"Non e stato possibile connettersi al banco:\n\n{e}") quit() # connect camera frames to vision - self.components["vision"].set_sources({"galaxy_camera": self.components["galaxy_camera"].out}) + if "vision" in self.components and "galaxy_camera" in self.components: + self.components["vision"].set_sources({"galaxy_camera": self.components["galaxy_camera"].out}) # GUI INIT - # self.main_window = Main_Window(self.bench) - self.main_window = Main_Window() - # CONNECT MAIN WINDOW ACTIONS - self.main_window.archive_a.triggered.connect(self.open_archive) - if "--archive" in sys.argv: - self.main_window.archive_a.trigger() - self.main_window.autotests_archive_a.triggered.connect(self.open_autotests_archive) - if "--autotests-archive" in sys.argv: - self.main_window.autotests_archive_a.trigger() - self.main_window.about_a.triggered.connect(self.open_about) - if "--about" in sys.argv: - self.main_window.about_a.trigger() - self.main_window.admin_m.menuAction().setVisible(False) # admin menu should not be visible before an admin logs in - self.main_window.users_management_a.triggered.connect(self.open_users_management) - if "--users-management" in sys.argv: - self.main_window.users_management_a.trigger() - # OPEN LOGIN TAB - self.open_login() - # SHOW MAIN WINDOW - if "--panel" in sys.argv: - self.main_window.show() - elif "--maximized" in sys.argv: - self.main_window.showMaximized() - elif "--full-screen" in sys.argv: - self.main_window.showFullScreen() - else: - self.main_window.showFullScreen() + if "--no-gui" not in sys.argv: + # self.main_window = Main_Window(self.bench) + self.main_window = Main_Window() + # CONNECT MAIN WINDOW ACTIONS + self.main_window.archive_a.triggered.connect(self.open_archive) + if "--archive" in sys.argv: + self.main_window.archive_a.trigger() + self.main_window.autotests_archive_a.triggered.connect(self.open_autotests_archive) + if "--autotests-archive" in sys.argv: + self.main_window.autotests_archive_a.trigger() + self.main_window.about_a.triggered.connect(self.open_about) + if "--about" in sys.argv: + self.main_window.about_a.trigger() + self.main_window.admin_m.menuAction().setVisible(False) # admin menu should not be visible before an admin logs in + self.main_window.quit_a.triggered.connect(quit_app) + self.main_window.users_management_a.triggered.connect(self.open_users_management) + if "--users-management" in sys.argv: + self.main_window.users_management_a.trigger() + # OPEN LOGIN TAB + self.open_login() + # SHOW MAIN WINDOW + if "--panel" in sys.argv: + self.main_window.show() + elif "--maximized" in sys.argv: + self.main_window.showMaximized() + elif "--full-screen" in sys.argv: + self.main_window.showFullScreen() + else: + self.main_window.showFullScreen() def open_archive(self): self.main_window.open_dialog(Archive()) @@ -164,10 +168,21 @@ try: def open_test(self): self.main_window.open_tab(Test(self.config.machine_id, self.components)) + def open_test(self): + self.main_window.open_tab(Test(self.config.machine_id, self.components)) + if __name__ == "__main__": app = QApplication(sys.argv) main = Main() - app.exec() + if "--no-gui" not in sys.argv: + app.exec() + if "--interact" in sys.argv: + import code + import readline + variables = globals().copy() + variables.update(locals()) + shell = code.InteractiveConsole(variables) + shell.interact() except Exception: logging.exception(traceback.format_exc()) # extype, value, tb = sys.exc_info() diff --git a/src/ui/main_window/main_window.ui b/src/ui/main_window/main_window.ui index 2c3f092..17c9b43 100644 --- a/src/ui/main_window/main_window.ui +++ b/src/ui/main_window/main_window.ui @@ -31,6 +31,7 @@ Amministrazione + @@ -63,6 +64,11 @@ Archivio autotest + + + Esci + +