| 1 |
# SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
|
| 3 |
from openrazer_daemon.dbus_services import endpoint |
| 4 |
|
| 5 |
|
| 6 |
@endpoint('razer.device.lighting.backlight', 'getBacklightBrightness', out_sig='d') |
| 7 |
def get_backlight_brightness(self): |
| 8 |
""" |
| 9 |
Get the device's brightness |
| 10 |
""" |
| 11 |
self.logger.debug("DBus call get_backlight_brightness") |
| 12 |
|
| 13 |
return self.zone["backlight"]["brightness"] |
| 14 |
|
| 15 |
|
| 16 |
@endpoint('razer.device.lighting.backlight', 'setBacklightBrightness', in_sig='d') |
| 17 |
def set_backlight_brightness(self, brightness): |
| 18 |
""" |
| 19 |
Set the device's brightness |
| 20 |
""" |
| 21 |
self.logger.debug("DBus call set_backlight_brightness") |
| 22 |
|
| 23 |
driver_path = self.get_driver_path('backlight_led_brightness') |
| 24 |
|
| 25 |
self.method_args['brightness'] = brightness |
| 26 |
|
| 27 |
if brightness > 100: |
| 28 |
brightness = 100 |
| 29 |
elif brightness < 0: |
| 30 |
brightness = 0 |
| 31 |
|
| 32 |
self.set_persistence("backlight", "brightness", int(brightness)) |
| 33 |
|
| 34 |
brightness = int(round(brightness * (255.0 / 100.0))) |
| 35 |
|
| 36 |
with open(driver_path, 'w') as driver_file: |
| 37 |
driver_file.write(str(brightness)) |
| 38 |
|
| 39 |
# Notify others |
| 40 |
self.send_effect_event('setBrightness', brightness) |
| 41 |
|
| 42 |
|
| 43 |
@endpoint('razer.device.lighting.logo', 'getLogoActive', out_sig='b') |
| 44 |
def get_logo_active(self): |
| 45 |
""" |
| 46 |
Get if the logo is lit up |
| 47 |
""" |
| 48 |
self.logger.debug("DBus call get_logo_active") |
| 49 |
|
| 50 |
return self.zone["logo"]["active"] |
| 51 |
|
| 52 |
|
| 53 |
@endpoint('razer.device.lighting.logo', 'setLogoActive', in_sig='b') |
| 54 |
def set_logo_active(self, active): |
| 55 |
""" |
| 56 |
Set if the logo is lit up |
| 57 |
""" |
| 58 |
self.logger.debug("DBus call set_logo_active") |
| 59 |
|
| 60 |
# remember status |
| 61 |
self.set_persistence("logo", "active", bool(active)) |
| 62 |
|
| 63 |
driver_path = self.get_driver_path('logo_led_state') |
| 64 |
|
| 65 |
with open(driver_path, 'w') as driver_file: |
| 66 |
driver_file.write('1' if active else '0') |
| 67 |
|
| 68 |
|
| 69 |
@endpoint('razer.device.lighting.logo', 'getLogoBrightness', out_sig='d') |
| 70 |
def get_logo_brightness(self): |
| 71 |
""" |
| 72 |
Get the device's brightness |
| 73 |
""" |
| 74 |
self.logger.debug("DBus call get_logo_brightness") |
| 75 |
|
| 76 |
return self.zone["logo"]["brightness"] |
| 77 |
|
| 78 |
|
| 79 |
@endpoint('razer.device.lighting.logo', 'setLogoBrightness', in_sig='d') |
| 80 |
def set_logo_brightness(self, brightness): |
| 81 |
""" |
| 82 |
Set the device's brightness |
| 83 |
""" |
| 84 |
self.logger.debug("DBus call set_logo_brightness") |
| 85 |
|
| 86 |
driver_path = self.get_driver_path('logo_led_brightness') |
| 87 |
|
| 88 |
self.method_args['brightness'] = brightness |
| 89 |
|
| 90 |
if brightness > 100: |
| 91 |
brightness = 100 |
| 92 |
elif brightness < 0: |
| 93 |
brightness = 0 |
| 94 |
|
| 95 |
self.set_persistence("logo", "brightness", int(brightness)) |
| 96 |
|
| 97 |
brightness = int(round(brightness * (255.0 / 100.0))) |
| 98 |
|
| 99 |
with open(driver_path, 'w') as driver_file: |
| 100 |
driver_file.write(str(brightness)) |
| 101 |
|
| 102 |
# Notify others |
| 103 |
self.send_effect_event('setBrightness', brightness) |
| 104 |
|
| 105 |
|
| 106 |
@endpoint('razer.device.lighting.scroll', 'getScrollBrightness', out_sig='d') |
| 107 |
def get_scroll_brightness(self): |
| 108 |
""" |
| 109 |
Get the device's brightness |
| 110 |
""" |
| 111 |
self.logger.debug("DBus call get_scroll_brightness") |
| 112 |
|
| 113 |
return self.zone["scroll"]["brightness"] |
| 114 |
|
| 115 |
|
| 116 |
@endpoint('razer.device.lighting.scroll', 'setScrollBrightness', in_sig='d') |
| 117 |
def set_scroll_brightness(self, brightness): |
| 118 |
""" |
| 119 |
Set the device's brightness |
| 120 |
""" |
| 121 |
self.logger.debug("DBus call set_scroll_brightness") |
| 122 |
|
| 123 |
driver_path = self.get_driver_path('scroll_led_brightness') |
| 124 |
|
| 125 |
self.method_args['brightness'] = brightness |
| 126 |
|
| 127 |
if brightness > 100: |
| 128 |
brightness = 100 |
| 129 |
elif brightness < 0: |
| 130 |
brightness = 0 |
| 131 |
|
| 132 |
self.set_persistence("scroll", "brightness", int(brightness)) |
| 133 |
|
| 134 |
brightness = int(round(brightness * (255.0 / 100.0))) |
| 135 |
|
| 136 |
with open(driver_path, 'w') as driver_file: |
| 137 |
driver_file.write(str(brightness)) |
| 138 |
|
| 139 |
# Notify others |
| 140 |
self.send_effect_event('setBrightness', brightness) |