Created
April 11, 2025 13:09
-
-
Save mcwnuq/cea8c40d07be8c0d1235b36a843cf513 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import openrazer.client | |
| import time | |
| def get_color(battery_level): | |
| """Return the interpolated RGB color based on the battery level.""" | |
| if battery_level == 100: | |
| return 0, 0, 255 # Blue for 100% | |
| if battery_level <= 50: | |
| # Interpolation from red (255, 0, 0) to yellow (255, 255, 0) | |
| green = int(battery_level * 5.1) # Scale 0-50% to 0-255 for green | |
| red = 255 | |
| blue = 0 | |
| else: | |
| # Interpolation from yellow (255, 255, 0) to green (0, 255, 0) | |
| red = int(255 - ((battery_level - 50) * 5.1)) # Scale 50-100% to 255-0 for red | |
| green = 255 | |
| blue = 0 | |
| return red, green, blue | |
| def main(): | |
| # Initialize the OpenRazer client | |
| client = openrazer.client.DeviceManager() | |
| devices = client.devices | |
| if not devices: | |
| print("No Razer devices found!") | |
| return | |
| # Find the Basilisk V3 Pro device | |
| basilisk = None | |
| for device in devices: | |
| if "Basilisk V3 Pro" in device.name: | |
| basilisk = device | |
| break | |
| if not basilisk: | |
| print("Razer Basilisk V3 Pro not found!") | |
| return | |
| print(f"Device found: {basilisk.name}") | |
| while True: | |
| # Get the battery percentage | |
| battery_level = basilisk.battery_level | |
| print(f"Battery Level: {battery_level}%") | |
| # Determine the color | |
| red, green, blue = get_color(battery_level) | |
| print(f"Setting color to: R={red}, G={green}, B={blue}") | |
| # Set the static color for the device | |
| basilisk.fx.static(red, green, blue) | |
| # Sleep for a while before re-checking | |
| time.sleep(60) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment