Mercurial > system76-keyboard-colors
comparison 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 |
comparison
equal
deleted
inserted
replaced
2:091a1f59a79c | 3:eb2aa09653bd |
---|---|
1 from keyboard_colors.color_profile import ProfileManager, Color | |
2 from threading import Event | |
3 import keyboard_colors | |
4 import keyboard_colors.psutilx.psutilx | |
5 import signal | |
6 | |
7 | |
8 class KeyboardColorDaemon: | |
9 | |
10 transition_wait_time = 100 | |
11 | |
12 def __init__(self): | |
13 signal.signal(signal.SIGINT, self.signal_handler) | |
14 self.profile_manager = ProfileManager() | |
15 # self.run(keyboard_colors.custom.custom.ColorProfile()) | |
16 self.run(keyboard_colors.psutilx.psutilx.ColorProfile()) | |
17 | |
18 def run(self, profile): | |
19 # color = profile.color | |
20 color = Color.from_hex('#FF3300') | |
21 wait_time = profile.frequency_time - profile.transition_time | |
22 transition_steps = int(profile.transition_time / self.transition_wait_time) | |
23 | |
24 # print(Color.get_step_color(color, profile.next_color(), .3)) | |
25 # return | |
26 | |
27 self.break_event = Event() | |
28 while not self.break_event.is_set(): | |
29 next_color = profile.next_color() | |
30 step_colors = Color.get_steps(color, next_color, transition_steps) | |
31 | |
32 for step_color in step_colors: | |
33 print(step_color) | |
34 with open('/sys/devices/platform/system76/leds/system76::kbd_backlight/color_left', 'w') as f: | |
35 f.write(step_color.to_hex()) | |
36 self.break_event.wait(self.transition_wait_time / 1000) | |
37 | |
38 color = next_color | |
39 self.break_event.wait(wait_time / 1000) | |
40 | |
41 def signal_handler(self, signal, frame): | |
42 self.break_event.set() | |
43 | |
44 | |
45 if __name__ == "__main__": | |
46 KeyboardColorDaemon() |