view daemon.py @ 3:eb2aa09653bd default tip

beginnings of CPU colors, daemon
author Brad Greco <brad@bgreco.net>
date Mon, 29 Mar 2021 20:27:09 -0400
parents
children
line wrap: on
line source

from keyboard_colors.color_profile import ProfileManager, Color
from threading import Event
import keyboard_colors
import keyboard_colors.psutilx.psutilx
import signal


class KeyboardColorDaemon:

    transition_wait_time = 100

    def __init__(self):
        signal.signal(signal.SIGINT, self.signal_handler)
        self.profile_manager = ProfileManager()
        # self.run(keyboard_colors.custom.custom.ColorProfile())
        self.run(keyboard_colors.psutilx.psutilx.ColorProfile())

    def run(self, profile):
        # color = profile.color
        color = Color.from_hex('#FF3300')
        wait_time = profile.frequency_time - profile.transition_time
        transition_steps = int(profile.transition_time / self.transition_wait_time)

        # print(Color.get_step_color(color, profile.next_color(), .3))
        # return

        self.break_event = Event()
        while not self.break_event.is_set():
            next_color = profile.next_color()
            step_colors = Color.get_steps(color, next_color, transition_steps)

            for step_color in step_colors:
                print(step_color)
                with open('/sys/devices/platform/system76/leds/system76::kbd_backlight/color_left', 'w') as f:
                    f.write(step_color.to_hex())
                self.break_event.wait(self.transition_wait_time / 1000)

            color = next_color
            self.break_event.wait(wait_time / 1000)

    def signal_handler(self, signal, frame):
        self.break_event.set()


if __name__ == "__main__":
    KeyboardColorDaemon()