From c3e5f0313be23bd177bcd856bd4ede95d9e5a27f Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 26 Nov 2024 08:33:45 +0100 Subject: [PATCH] update: led control working --- lib/wledControl.py | 12 ++++++++++-- workflow2.py | 32 +++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/lib/wledControl.py b/lib/wledControl.py index 4046e53..d2b86f9 100644 --- a/lib/wledControl.py +++ b/lib/wledControl.py @@ -61,10 +61,18 @@ class WLEDController: """Turn off all lights.""" self.send_command('{"ps":"4"}') - def change_effect(self): - """Change the color effect.""" + def blink_yellow(self): + """Blink in yellow.""" self.send_command('{"ps":"5"}') + def blink_red(self): + """blink in red.""" + self.send_command('{"ps":"7"}') + + def blink_green(self): + """blink in green.""" + self.send_command('{"ps":"6"}') + # Example usage: if __name__ == "__main__": controller = WLEDController(port="/dev/serial/by-path/pci-0000:00:14.0-usbv2-0:1:1.0-port0") diff --git a/workflow2.py b/workflow2.py index 55a508f..8afc7a6 100644 --- a/workflow2.py +++ b/workflow2.py @@ -514,7 +514,7 @@ class Ui_MainWindow(object): 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")) + self.blinkLightBtn.setText(_translate("MainWindow", "Blink Yellow LED")) def mousePressEvent(self, event): print("Das MainWindow wurde angeklickt.") @@ -920,10 +920,20 @@ class LightControl(QtWidgets.QMainWindow): 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.ui.blinkLightBtn.clicked.connect(self.blink_yellow) 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 + self.w.connect() + #self.w.switch_to_green() # at appstart the light is green + self.w.blink_green() # and switches to green blinking until the workflow gets started successfully# + + # Connect app exit signal to the cleanup method + app.aboutToQuit.connect(self.cleanup) + + def cleanup(self): + """Clean up resources and switch off LEDs.""" + print("Cleaning up resources and switching off LEDs") + self.leds_off() # Turn off LEDs + self.w.disconnect() # Disconnect WLED controller def map_color(self, color): """ @@ -973,9 +983,17 @@ class LightControl(QtWidgets.QMainWindow): print("LEDs are off") self.w.turn_off_all() - def leds_blink(self): - print("Previous color is blinking") - self.w.change_effect() + def blink_yellow(self): + print("Yellow color is blinking") + self.w.blink_yellow() + + def blink_red(self): + print("Red color is blinking") + self.w.blink_red() + + def blink_green(self): + print("Green color is blinking") + self.w.blink_green() if __name__ == "__main__": import sys