This commit is contained in:
Björn Ellensohn 2024-11-24 18:18:27 +01:00
parent 5cce0a071c
commit 9ba16027b7

View File

@ -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 # ## in der Ui_MainWindow-Klasse wird die GUI erstellt - der MainThread läuft in dieser -> Farben Drop Down
## Aufsetzen der Datenbank und Waagenverbindung # ## Aufsetzen der Datenbank und Waagenverbindung
# Definieren der Datenbankverbindung # # Definieren der Datenbankverbindung
db_config = { db_config = {
'user': 'dbUser', 'user': 'dbUser',
'password': 'dbPassword', 'password': 'dbPassword',
@ -34,10 +34,24 @@ db_config = {
'port': 3306 # Standard port for MariaDB 'port': 3306 # Standard port for MariaDB
} }
# Establishing the connection # # 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) conn = mariadb.connect(**db_config)
print("Database connection established successfully.")
# Create a cursor to execute queries # Create a cursor to execute queries
cursor = conn.cursor() 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 # Configuration of the serial port
try: try:
@ -487,10 +501,8 @@ class Ui_MainWindow(object):
# new camera workflow # new camera workflow
self.startCamBtn.setText(_translate("MainWindow", "Start Camera")) self.startCamBtn.setText(_translate("MainWindow", "Start Camera"))
# self.startCamBtn.clicked.connect(self.startCamBtnClicked)
self.stopCamBtn.setText(_translate("MainWindow", "Stop Camera")) self.stopCamBtn.setText(_translate("MainWindow", "Stop Camera"))
self.camWorkFlowcheckBox.setText(_translate("MainWindow", "Camera Workflow")) self.camWorkFlowcheckBox.setText(_translate("MainWindow", "Camera Workflow"))
# self.camWorkFlowcheckBox.clicked.connect(self.onCheckboxCheck)
self.modelComboBox self.modelComboBox
# relay control buttons # relay control buttons
@ -504,7 +516,6 @@ class Ui_MainWindow(object):
self.offLightBtn.setText(_translate("MainWindow", "Turn off all LEDs")) self.offLightBtn.setText(_translate("MainWindow", "Turn off all LEDs"))
self.blinkLightBtn.setText(_translate("MainWindow", "Blink last LED")) self.blinkLightBtn.setText(_translate("MainWindow", "Blink last LED"))
def mousePressEvent(self, event): def mousePressEvent(self, event):
print("Das MainWindow wurde angeklickt.") print("Das MainWindow wurde angeklickt.")
self.setFocus() self.setFocus()
@ -565,6 +576,9 @@ class Ui_MainWindow(object):
for col in range(tableObject.columnCount()-1): for col in range(tableObject.columnCount()-1):
tableObject.item(rowID, col).setBackground(QtGui.QColor(r,g,b)) 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): def auftragsBtnClicked(self):
databaseQueryWorking = False #wird für die Überprüfung, ob die Datenbankabfrage fehlerhaft ist, verwendet databaseQueryWorking = False #wird für die Überprüfung, ob die Datenbankabfrage fehlerhaft ist, verwendet
auftragEinzelteilDaten = [] auftragEinzelteilDaten = []
@ -815,7 +829,6 @@ class Ui_MainWindow(object):
self.checkWaageThread.wait() self.checkWaageThread.wait()
print("Der CheckWaage-Thread wurde beendet.") print("Der CheckWaage-Thread wurde beendet.")
# new class for Camera Object detection with YOLOv8 # new class for Camera Object detection with YOLOv8
class CameraStreamApp(QtWidgets.QMainWindow): class CameraStreamApp(QtWidgets.QMainWindow):
def __init__(self, ui): def __init__(self, ui):
@ -867,7 +880,7 @@ class CameraStreamApp(QtWidgets.QMainWindow):
# Convert the frame from BGR (OpenCV format) to RGB # Convert the frame from BGR (OpenCV format) to RGB
# frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # 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 # Convert the frame to QImage
h, w, ch = frame.shape h, w, ch = frame.shape
@ -897,16 +910,44 @@ class LightControl(QtWidgets.QMainWindow):
super().__init__() super().__init__()
self.ui = ui self.ui = ui
# init relay control
self.ui.startSpotlightBtn.clicked.connect(self.spot_on) self.ui.startSpotlightBtn.clicked.connect(self.spot_on)
self.ui.stopSpotlightBtn.clicked.connect(self.spot_off) self.ui.stopSpotlightBtn.clicked.connect(self.spot_off)
self.r = sainsmartrelay.SainsmartRelay() self.r = sainsmartrelay.SainsmartRelay()
# init led control
self.ui.redLightBtn.clicked.connect(self.red_on) self.ui.redLightBtn.clicked.connect(self.red_on)
self.ui.yellowLightBtn.clicked.connect(self.yellow_on) self.ui.yellowLightBtn.clicked.connect(self.yellow_on)
self.ui.greenLightBtn.clicked.connect(self.green_on) self.ui.greenLightBtn.clicked.connect(self.green_on)
self.ui.offLightBtn.clicked.connect(self.leds_off) self.ui.offLightBtn.clicked.connect(self.leds_off)
self.ui.blinkLightBtn.clicked.connect(self.leds_blink) 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 = 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): def spot_on(self):
print("Turn on light clicked") print("Turn on light clicked")