update: led control working

This commit is contained in:
Your Name 2024-11-26 08:33:45 +01:00
parent cde8a1bd15
commit c3e5f0313b
2 changed files with 35 additions and 9 deletions

View File

@ -61,10 +61,18 @@ class WLEDController:
"""Turn off all lights.""" """Turn off all lights."""
self.send_command('{"ps":"4"}') self.send_command('{"ps":"4"}')
def change_effect(self): def blink_yellow(self):
"""Change the color effect.""" """Blink in yellow."""
self.send_command('{"ps":"5"}') 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: # Example usage:
if __name__ == "__main__": if __name__ == "__main__":
controller = WLEDController(port="/dev/serial/by-path/pci-0000:00:14.0-usbv2-0:1:1.0-port0") controller = WLEDController(port="/dev/serial/by-path/pci-0000:00:14.0-usbv2-0:1:1.0-port0")

View File

@ -514,7 +514,7 @@ class Ui_MainWindow(object):
self.yellowLightBtn.setText(_translate("MainWindow", "Turn on yellow LED")) self.yellowLightBtn.setText(_translate("MainWindow", "Turn on yellow LED"))
self.greenLightBtn.setText(_translate("MainWindow", "Turn on green LED")) self.greenLightBtn.setText(_translate("MainWindow", "Turn on green LED"))
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 Yellow LED"))
def mousePressEvent(self, event): def mousePressEvent(self, event):
print("Das MainWindow wurde angeklickt.") print("Das MainWindow wurde angeklickt.")
@ -920,10 +920,20 @@ class LightControl(QtWidgets.QMainWindow):
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.blink_yellow)
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.connect()
#self.w.switch_to_green() # at appstart the light is green #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.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): def map_color(self, color):
""" """
@ -973,9 +983,17 @@ class LightControl(QtWidgets.QMainWindow):
print("LEDs are off") print("LEDs are off")
self.w.turn_off_all() self.w.turn_off_all()
def leds_blink(self): def blink_yellow(self):
print("Previous color is blinking") print("Yellow color is blinking")
self.w.change_effect() 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__": if __name__ == "__main__":
import sys import sys