diff --git a/readme.md b/readme.md index ce02a75..64bdca5 100644 --- a/readme.md +++ b/readme.md @@ -78,6 +78,9 @@ Falls Sie die Datenbank lokal testen möchten, starten Sie Docker Compose im Pro docker-compose up -d ``` +### 4. Software für USB Relay Board installieren +https://github.com/scheiber-sa/sainsmartUsbRelay + ## Anwendung ### Programmstart diff --git a/workflow.py b/workflow.py index f657a54..c143130 100644 --- a/workflow.py +++ b/workflow.py @@ -29,7 +29,7 @@ import cv2 import os import lib.sainsmartrelay as sainsmartrelay - +import lib.wledControl as wledControl db_config = { '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.setObjectName("graphicsView") - # relay control + # relay control buttons 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.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.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) ''' @@ -567,10 +579,16 @@ class Ui_MainWindow(object): # self.camWorkFlowcheckBox.clicked.connect(self.onCheckboxCheck) self.modelComboBox - # relay control + # relay control buttons self.startSpotlightBtn.setText(_translate("MainWindow", "Turn on 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): @@ -1054,8 +1072,8 @@ class CameraStreamApp(QtWidgets.QMainWindow): self.yolo_stream.cap.release() event.accept() -# new class for relay control -class RelayControl(QtWidgets.QMainWindow): +# new class for light control +class LightControl(QtWidgets.QMainWindow): def __init__(self, ui): super().__init__() self.ui = ui @@ -1064,6 +1082,13 @@ class RelayControl(QtWidgets.QMainWindow): self.ui.stopSpotlightBtn.clicked.connect(self.spot_off) 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): print("Turn on light clicked") self.r.turn_on(1) @@ -1074,27 +1099,23 @@ class RelayControl(QtWidgets.QMainWindow): def red_on(self): print("Red light is on") - self.r.turn_on(2) - - def red_off(self): - print("Red light is off") - self.r.turn_off(2) + self.w.switch_to_red() def yellow_on(self): print("Yellow light is on") - self.r.turn_on(3) - - def yellow_off(self): - print("Yellow light is off") - self.r.turn_off(3) + self.w.switch_to_yellow() def green_on(self): print("Green light is on") - self.r.turn_on(4) + self.w.switch_to_green() - def green_off(self): - print("Green light is off") - self.r.turn_off(4) + def leds_off(self): + print("LEDs are off") + self.w.turn_off_all() + + def leds_blink(self): + print("Previous color is blinking") + self.w.change_effect() if __name__ == "__main__": import sys @@ -1105,8 +1126,8 @@ if __name__ == "__main__": # Initialize the CameraStreamApp with the UI camera_app = CameraStreamApp(ui) - # initialize relay app - relay_app = RelayControl(ui) + # initialize light control app + light_app = LightControl(ui) MainWindow.show() sys.exit(app.exec_()) \ No newline at end of file