update: led light control ui

This commit is contained in:
Your Name 2024-11-23 23:11:06 +01:00
parent 0de0791acb
commit df3ac9119c
2 changed files with 46 additions and 22 deletions

View File

@ -78,6 +78,9 @@ Falls Sie die Datenbank lokal testen möchten, starten Sie Docker Compose im Pro
docker-compose up -d docker-compose up -d
``` ```
### 4. Software für USB Relay Board installieren
https://github.com/scheiber-sa/sainsmartUsbRelay
## Anwendung ## Anwendung
### Programmstart ### Programmstart

View File

@ -29,7 +29,7 @@ import cv2
import os import os
import lib.sainsmartrelay as sainsmartrelay import lib.sainsmartrelay as sainsmartrelay
import lib.wledControl as wledControl
db_config = { db_config = {
'user': 'dbUser', 'user': 'dbUser',
@ -456,7 +456,7 @@ class Ui_MainWindow(object):
self.graphicsView.setGeometry(QtCore.QRect(10, int(1080/2), 661, int(480*1.05))) # position and size of camera frame # int(640*1.05) self.graphicsView.setGeometry(QtCore.QRect(10, int(1080/2), 661, int(480*1.05))) # position and size of camera frame # int(640*1.05)
self.graphicsView.setObjectName("graphicsView") self.graphicsView.setObjectName("graphicsView")
# relay control # relay control buttons
self.startSpotlightBtn = QtWidgets.QPushButton(self.centralwidget) self.startSpotlightBtn = QtWidgets.QPushButton(self.centralwidget)
self.startSpotlightBtn.setGeometry(QtCore.QRect(700+200, int(1080/2)+100, 161, 25)) #int(1080/2)+100 self.startSpotlightBtn.setGeometry(QtCore.QRect(700+200, int(1080/2)+100, 161, 25)) #int(1080/2)+100
self.startSpotlightBtn.setObjectName("startSpotlightBtn") self.startSpotlightBtn.setObjectName("startSpotlightBtn")
@ -464,6 +464,18 @@ class Ui_MainWindow(object):
self.stopSpotlightBtn.setGeometry(QtCore.QRect(700+200, int(1080/2)+150, 161, 25)) self.stopSpotlightBtn.setGeometry(QtCore.QRect(700+200, int(1080/2)+150, 161, 25))
self.stopSpotlightBtn.setObjectName("stopSpotlightBtn") self.stopSpotlightBtn.setObjectName("stopSpotlightBtn")
# led control buttons
self.redLightBtn = QtWidgets.QPushButton(self.centralwidget)
self.redLightBtn.setGeometry(QtCore.QRect(700+200, int(1080/2)+200, 161, 25))
self.yellowLightBtn = QtWidgets.QPushButton(self.centralwidget)
self.yellowLightBtn.setGeometry(QtCore.QRect(700+200, int(1080/2)+250, 161, 25))
self.greenLightBtn = QtWidgets.QPushButton(self.centralwidget)
self.greenLightBtn.setGeometry(QtCore.QRect(700+200, int(1080/2)+300, 161, 25))
self.offLightBtn = QtWidgets.QPushButton(self.centralwidget)
self.offLightBtn.setGeometry(QtCore.QRect(700+200, int(1080/2)+350, 161, 25))
self.blinkLightBtn = QtWidgets.QPushButton(self.centralwidget)
self.blinkLightBtn.setGeometry(QtCore.QRect(700+200, int(1080/2)+400, 161, 25))
#self.myTestLambda = lambda: self.worker.checkWaageStartSignal.emit(einzelteilID, self.teileZuViel, self.auftragsnummer) #self.myTestLambda = lambda: self.worker.checkWaageStartSignal.emit(einzelteilID, self.teileZuViel, self.auftragsnummer)
''' '''
@ -567,10 +579,16 @@ class Ui_MainWindow(object):
# self.camWorkFlowcheckBox.clicked.connect(self.onCheckboxCheck) # self.camWorkFlowcheckBox.clicked.connect(self.onCheckboxCheck)
self.modelComboBox self.modelComboBox
# relay control # relay control buttons
self.startSpotlightBtn.setText(_translate("MainWindow", "Turn on light")) self.startSpotlightBtn.setText(_translate("MainWindow", "Turn on light"))
self.stopSpotlightBtn.setText(_translate("MainWindow", "Turn off light")) self.stopSpotlightBtn.setText(_translate("MainWindow", "Turn off light"))
# led control buttons
self.redLightBtn.setText(_translate("MainWindow", "Turn on red LED"))
self.yellowLightBtn.setText(_translate("MainWindow", "Turn on yellow LED"))
self.greenLightBtn.setText(_translate("MainWindow", "Turn on green LED"))
self.offLightBtn.setText(_translate("MainWindow", "Turn off all LEDs"))
self.blinkLightBtn.setText(_translate("MainWindow", "Blink last LED"))
def mousePressEvent(self, event): def mousePressEvent(self, event):
@ -1054,8 +1072,8 @@ class CameraStreamApp(QtWidgets.QMainWindow):
self.yolo_stream.cap.release() self.yolo_stream.cap.release()
event.accept() event.accept()
# new class for relay control # new class for light control
class RelayControl(QtWidgets.QMainWindow): class LightControl(QtWidgets.QMainWindow):
def __init__(self, ui): def __init__(self, ui):
super().__init__() super().__init__()
self.ui = ui self.ui = ui
@ -1064,6 +1082,13 @@ class RelayControl(QtWidgets.QMainWindow):
self.ui.stopSpotlightBtn.clicked.connect(self.spot_off) self.ui.stopSpotlightBtn.clicked.connect(self.spot_off)
self.r = sainsmartrelay.SainsmartRelay() self.r = sainsmartrelay.SainsmartRelay()
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")
def spot_on(self): def spot_on(self):
print("Turn on light clicked") print("Turn on light clicked")
self.r.turn_on(1) self.r.turn_on(1)
@ -1074,27 +1099,23 @@ class RelayControl(QtWidgets.QMainWindow):
def red_on(self): def red_on(self):
print("Red light is on") print("Red light is on")
self.r.turn_on(2) self.w.switch_to_red()
def red_off(self):
print("Red light is off")
self.r.turn_off(2)
def yellow_on(self): def yellow_on(self):
print("Yellow light is on") print("Yellow light is on")
self.r.turn_on(3) self.w.switch_to_yellow()
def yellow_off(self):
print("Yellow light is off")
self.r.turn_off(3)
def green_on(self): def green_on(self):
print("Green light is on") print("Green light is on")
self.r.turn_on(4) self.w.switch_to_green()
def green_off(self): def leds_off(self):
print("Green light is off") print("LEDs are off")
self.r.turn_off(4) self.w.turn_off_all()
def leds_blink(self):
print("Previous color is blinking")
self.w.change_effect()
if __name__ == "__main__": if __name__ == "__main__":
import sys import sys
@ -1105,8 +1126,8 @@ if __name__ == "__main__":
# Initialize the CameraStreamApp with the UI # Initialize the CameraStreamApp with the UI
camera_app = CameraStreamApp(ui) camera_app = CameraStreamApp(ui)
# initialize relay app # initialize light control app
relay_app = RelayControl(ui) light_app = LightControl(ui)
MainWindow.show() MainWindow.show()
sys.exit(app.exec_()) sys.exit(app.exec_())