forked from snowyoneill/Linux-PredatorSense
-
Notifications
You must be signed in to change notification settings - Fork 2
/
keyboard.py
50 lines (45 loc) · 1.59 KB
/
keyboard.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
PAYLOAD_SIZE = 16
CHARACTER_DEVICE = "/dev/acer-gkbbl-0"
PAYLOAD_SIZE_STATIC_MODE = 4
CHARACTER_DEVICE_STATIC = "/dev/acer-gkbbl-static-0"
def set_mode(mode, zone, speed, brightness, direction, red, green, blue):
if mode == 0:
# Static coloring mode
if zone == 0: # All zones
for i in range(1, 5):
payload = [0] * PAYLOAD_SIZE_STATIC_MODE
payload[0] = 1 << (i - 1)
payload[1] = red
payload[2] = green
payload[3] = blue
with open(CHARACTER_DEVICE_STATIC, 'wb') as cd:
cd.write(bytes(payload))
else:
payload = [0] * PAYLOAD_SIZE_STATIC_MODE
payload[0] = 1 << (zone - 1)
payload[1] = red
payload[2] = green
payload[3] = blue
with open(CHARACTER_DEVICE_STATIC, 'wb') as cd:
cd.write(bytes(payload))
# Tell WMI To use STATIC coloring
# Dynamic coloring mode
payload = [0] * PAYLOAD_SIZE
payload[2] = brightness
payload[9] = 1
with open(CHARACTER_DEVICE, 'wb') as cd:
cd.write(bytes(payload))
else:
# Dynamic coloring mode
payload = [0] * PAYLOAD_SIZE
payload[0] = mode
payload[1] = speed
payload[2] = brightness
payload[3] = 8 if mode == 3 else 0
payload[4] = direction
payload[5] = red
payload[6] = green
payload[7] = blue
payload[9] = 1
with open(CHARACTER_DEVICE, 'wb') as cd:
cd.write(bytes(payload))