-
Notifications
You must be signed in to change notification settings - Fork 0
/
rainbow.py
65 lines (49 loc) · 1.87 KB
/
rainbow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
import time
import random
import argparse
from colorsys import hsv_to_rgb
def hexify(number: int) -> str:
return hex(number)[2:]
def main(args: argparse.Namespace):
progress = 0.0
s = args.saturation
v = args.value
dt = 1.0 / args.frames
speed = args.speed
zone_offset = args.offset
zones = {
"wheel": 0,
"dpi" : zone_offset * 1,
"logo" : zone_offset * 2
}
zones_fd = {zone: open(f"/sys/class/leds/corsair_m65::{zone}/brightness", "w") for zone in zones}
while True:
for zone in zones.keys():
zone_h = zones[zone] + progress
if zone_h > 1.0:
zone_h -= 1.0
(r, g, b) = hsv_to_rgb(zone_h, s, v)
rgb = int(0xFF * r) << 16
rgb += int(0xFF * g) << 8
rgb += int(0xFF * b) << 0
print(f"{rgb}", file=zones_fd[zone])
zones_fd[zone].flush()
time.sleep(dt)
progress += dt * speed
while progress > 1.0:
progress -= 1.0
def float01(value: str) -> float:
f = float(value)
if f < 0.0 or f > 1.0:
raise ValueError("Value in range [0, 1] was expected")
return f
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Make mouse leds do a rainbow-like effect")
parser.add_argument("--speed", default=0.3, dest="speed", help="Hue change speed", type=float01)
parser.add_argument("--frames", default=20, dest="frames", help="Color changes per second", type=int)
parser.add_argument("--saturation", default=0.90, dest="saturation", help="Color saturation", type=float01)
parser.add_argument("--value", default=0.99, dest="value", help="Color value", type=float01)
parser.add_argument("--offset", default=0.07, dest="offset", help="Zones hue offset", type=float01)
args = parser.parse_args()
main(args)