diff --git a/workflow2.py b/workflow2.py index de7999c..02e1aae 100644 --- a/workflow2.py +++ b/workflow2.py @@ -24,8 +24,8 @@ import lib.wledControl as wledControl # ## in der Ui_MainWindow-Klasse wird die GUI erstellt - der MainThread läuft in dieser -> Farben Drop Down -## Aufsetzen der Datenbank und Waagenverbindung -# Definieren der Datenbankverbindung +# ## Aufsetzen der Datenbank und Waagenverbindung +# # Definieren der Datenbankverbindung db_config = { 'user': 'dbUser', 'password': 'dbPassword', @@ -34,10 +34,24 @@ db_config = { 'port': 3306 # Standard port for MariaDB } -# Establishing the connection -conn = mariadb.connect(**db_config) -# Create a cursor to execute queries -cursor = conn.cursor() +# # Establishing the connection +# conn = mariadb.connect(**db_config) +# # Create a cursor to execute queries +# cursor = conn.cursor() + +try: + # Attempt to establish the connection + conn = mariadb.connect(**db_config) + print("Database connection established successfully.") + + # Create a cursor to execute queries + cursor = conn.cursor() +except mariadb.Error as e: + # Handle connection errors + print(f"Error connecting to the database: {e}") + conn = None + cursor = None + # Configuration of the serial port try: @@ -487,10 +501,8 @@ class Ui_MainWindow(object): # new camera workflow self.startCamBtn.setText(_translate("MainWindow", "Start Camera")) - # self.startCamBtn.clicked.connect(self.startCamBtnClicked) self.stopCamBtn.setText(_translate("MainWindow", "Stop Camera")) self.camWorkFlowcheckBox.setText(_translate("MainWindow", "Camera Workflow")) - # self.camWorkFlowcheckBox.clicked.connect(self.onCheckboxCheck) self.modelComboBox # relay control buttons @@ -504,7 +516,6 @@ class Ui_MainWindow(object): self.offLightBtn.setText(_translate("MainWindow", "Turn off all LEDs")) self.blinkLightBtn.setText(_translate("MainWindow", "Blink last LED")) - def mousePressEvent(self, event): print("Das MainWindow wurde angeklickt.") self.setFocus() @@ -565,6 +576,9 @@ class Ui_MainWindow(object): for col in range(tableObject.columnCount()-1): tableObject.item(rowID, col).setBackground(QtGui.QColor(r,g,b)) + # call change led color + light_app.map_color_to_led(r,g,b) + def auftragsBtnClicked(self): databaseQueryWorking = False #wird für die Überprüfung, ob die Datenbankabfrage fehlerhaft ist, verwendet auftragEinzelteilDaten = [] @@ -815,7 +829,6 @@ class Ui_MainWindow(object): self.checkWaageThread.wait() print("Der CheckWaage-Thread wurde beendet.") - # new class for Camera Object detection with YOLOv8 class CameraStreamApp(QtWidgets.QMainWindow): def __init__(self, ui): @@ -867,7 +880,7 @@ class CameraStreamApp(QtWidgets.QMainWindow): # Convert the frame from BGR (OpenCV format) to RGB # frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) - frame = cv2.cvtColor(processed_frame, cv2.COLOR_BGR2RGB) # might change nomenclature later? + frame = cv2.cvtColor(processed_frame, cv2.COLOR_BGR2RGB) # Convert the frame to QImage h, w, ch = frame.shape @@ -897,17 +910,45 @@ class LightControl(QtWidgets.QMainWindow): super().__init__() self.ui = ui + # init relay control self.ui.startSpotlightBtn.clicked.connect(self.spot_on) self.ui.stopSpotlightBtn.clicked.connect(self.spot_off) self.r = sainsmartrelay.SainsmartRelay() - + + # init led control self.ui.redLightBtn.clicked.connect(self.red_on) self.ui.yellowLightBtn.clicked.connect(self.yellow_on) self.ui.greenLightBtn.clicked.connect(self.green_on) self.ui.offLightBtn.clicked.connect(self.leds_off) self.ui.blinkLightBtn.clicked.connect(self.leds_blink) self.w = wledControl.WLEDController(port="/dev/serial/by-path/pci-0000:00:14.0-usbv2-0:1:1.0-port0") + # self.w.switch_to_green() # at appstart the light is green + # self.w.change_effect() # and switches to green blinking until the workflow gets started successfully + + def map_color(self, color): + """ + Map an RGB color to the corresponding WLED action based on predefined ranges. + + :param color: A tuple of (R, G, B) values, where each component is an integer between 0 and 255. + """ + red, green, blue = color + # Check if the color is red (high R, low G and B) + if red > 200 and green < 100 and blue < 100: + self.switch_to_red() + + # Check if the color is green (high G, low R and B) + elif red < 100 and green > 200 and blue < 100: + self.switch_to_green() + + # Check if the color is yellow (high R and G, low B) + elif red > 200 and green > 200 and blue < 100: + self.switch_to_yellow() + + # If none of the above, turn off the LEDs + else: + self.turn_off_all() + def spot_on(self): print("Turn on light clicked") self.r.turn_on(1)