-
Notifications
You must be signed in to change notification settings - Fork 0
/
RazerStatusRows.py
executable file
·97 lines (73 loc) · 3.29 KB
/
RazerStatusRows.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python3
from openrazer.client import DeviceManager, constants as razer_constants
import math
import numpy as np
import time
from colour import Color
import psutil
# Constants and Configurations
DEBUG = True
BATTERY_HIGH_THRESHOLD = 0.69
BATTERY_LOW_THRESHOLD = 1-BATTERY_HIGH_THRESHOLD
SLEEP_INTERVAL = 0.5
# Initialize Device Manager
device_manager = DeviceManager()
devices = device_manager.devices
if DEBUG:
import matplotlib.pyplot as plt
def find_advanced_devices(device_list):
advanced_devices = []
for device in device_list.copy():
if not device.fx.advanced:
print(f"Skipping device {device.name} ({device.serial})")
device_list.remove(device)
else:
advanced_devices.append(device)
return advanced_devices
def create_gradient_colors(start_color, end_color, num_steps):
gradient = list(Color(start_color).range_to(Color(end_color), num_steps + 1))
return [list(np.array(x.get_rgb()) * 255) for x in gradient]
def main():
advanced_devices = find_advanced_devices(devices)
if not advanced_devices:
print("No advanced devices found.")
return
device = advanced_devices[0]
rows = device.fx.advanced.rows
cols = device.fx.advanced.cols
row_sizes = [15, 14, 14, 14, 14, 14]
color_gradient = create_gradient_colors("orange", "red", row_sizes[1] + 1)
charging_animation_status = 0
while True:
battery_level = psutil.sensors_battery().percent / 100
temperature = np.max([x[0].current for x in np.array(list(psutil.sensors_temperatures().values())).reshape(-1)]) / 100
with open("/sys/class/power_supply/AC0/online") as f:
charging_status = int(f.read())
row_limits = [0] * len(row_sizes)
row_limits[0] = np.clip(math.ceil(battery_level * row_sizes[0]), 1, None)
row_limits[1] = np.clip(math.ceil(temperature * row_sizes[1]), 1, None)
# Create an empty RGB matrix
rgbs_matrix = np.zeros((rows, cols, 3), dtype=int)
# Set default white colors
rgbs_matrix[0, :] = [255, 255, 255]
rgbs_matrix[1, :] = [255, 255, 255]
rgbs_matrix[2, :] = [255, 255, 255]
rgbs_matrix[3, :] = [255, 255, 255]
rgbs_matrix[4, :] = [255, 255, 255]
rgbs_matrix[5, :] = [255, 255, 255]
# Set green/red for battery level
rgbs_matrix[0, 1:row_limits[0] + 1] = ([0,255,0] if battery_level>=BATTERY_HIGH_THRESHOLD else ([255,0,0] if battery_level<=BATTERY_LOW_THRESHOLD else [0,0,255]))
if charging_status:
rgbs_matrix[0, charging_animation_status] = [0, 0, 255] if battery_level >= BATTERY_HIGH_THRESHOLD else [0, 255, 0]
charging_animation_status = (charging_animation_status + 1) % (row_limits[0]+1)
# Set gradient for temperature
rgbs_matrix[1, :row_limits[1] + 1] = color_gradient[:row_limits[1] + 1]
device.fx.advanced.matrix.reset()
for i in range(rows):
for j in range(cols):
device.fx.advanced.matrix[i, j] = list(rgbs_matrix[i, j])
device.fx.advanced.draw()
time.sleep(SLEEP_INTERVAL)
if __name__ == "__main__":
print(f"Found {len(devices)} Razer devices")
main()