Debian Codegraph @

daemon/openrazer_daemon/dbus_services/dbus_methods/lanceheadte.py

raw
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.logo', 'setLogoWave', in_sig='i')
7 def set_logo_wave(self, direction):
8 """
9 Set the wave effect on the device
10
11 :param direction: (0|1) - down to up, (1|2) up to down
12 :type direction: int
13 """
14 self.logger.debug("DBus call set_logo_wave")
15
16 # Notify others
17 self.send_effect_event('setWave', direction)
18
19 # remember effect
20 self.set_persistence("logo", "effect", 'wave')
21 self.set_persistence("logo", "wave_dir", int(direction))
22
23 driver_path = self.get_driver_path('logo_matrix_effect_wave')
24
25 if direction not in self.WAVE_DIRS:
26 direction = self.WAVE_DIRS[0]
27
28 with open(driver_path, 'w') as driver_file:
29 driver_file.write(str(direction))
30
31
32 @endpoint('razer.device.lighting.scroll', 'setScrollWave', in_sig='i')
33 def set_scroll_wave(self, direction):
34 """
35 Set the wave effect on the device
36
37 :param direction: (0|1) - down to up, (1|2) up to down
38 :type direction: int
39 """
40 self.logger.debug("DBus call set_scroll_wave")
41
42 # Notify others
43 self.send_effect_event('setWave', direction)
44
45 # remember effect
46 self.set_persistence("scroll", "effect", 'wave')
47 self.set_persistence("scroll", "wave_dir", int(direction))
48
49 driver_path = self.get_driver_path('scroll_matrix_effect_wave')
50
51 if direction not in self.WAVE_DIRS:
52 direction = self.WAVE_DIRS[0]
53
54 with open(driver_path, 'w') as driver_file:
55 driver_file.write(str(direction))
56
57
58 @endpoint('razer.device.lighting.left', 'getLeftBrightness', out_sig='d')
59 def get_left_brightness(self):
60 """
61 Get the device's brightness
62
63 :return: Brightness
64 :rtype: float
65 """
66 self.logger.debug("DBus call get_left_brightness")
67
68 return self.zone["left"]["brightness"]
69
70
71 @endpoint('razer.device.lighting.left', 'setLeftBrightness', in_sig='d')
72 def set_left_brightness(self, brightness):
73 """
74 Set the device's brightness
75
76 :param brightness: Brightness
77 :type brightness: int
78 """
79 self.logger.debug("DBus call set_left_brightness")
80
81 driver_path = self.get_driver_path('left_led_brightness')
82
83 self.method_args['brightness'] = brightness
84
85 if brightness > 100:
86 brightness = 100
87 elif brightness < 0:
88 brightness = 0
89
90 self.set_persistence("left", "brightness", int(brightness))
91
92 brightness = int(round(brightness * (255.0 / 100.0)))
93
94 with open(driver_path, 'w') as driver_file:
95 driver_file.write(str(brightness))
96
97 # Notify others
98 self.send_effect_event('setBrightness', brightness)
99
100
101 @endpoint('razer.device.lighting.left', 'setLeftWave', in_sig='i')
102 def set_left_wave(self, direction):
103 """
104 Set the wave effect on the device
105
106 :param direction: (0|1) - down to up, (1|2) up to down
107 :type direction: int
108 """
109 self.logger.debug("DBus call set_left_wave")
110
111 # Notify others
112 self.send_effect_event('setWave', direction)
113
114 # remember effect
115 self.set_persistence("left", "effect", 'wave')
116 self.set_persistence("left", "wave_dir", int(direction))
117
118 driver_path = self.get_driver_path('left_matrix_effect_wave')
119
120 if direction not in self.WAVE_DIRS:
121 direction = self.WAVE_DIRS[0]
122
123 with open(driver_path, 'w') as driver_file:
124 driver_file.write(str(direction))
125
126
127 @endpoint('razer.device.lighting.left', 'setLeftStatic', in_sig='yyy')
128 def set_left_static(self, red, green, blue):
129 """
130 Set the device to static colour
131
132 :param red: Red component
133 :type red: int
134
135 :param green: Green component
136 :type green: int
137
138 :param blue: Blue component
139 :type blue: int
140 """
141 self.logger.debug("DBus call set_left_static")
142
143 # Notify others
144 self.send_effect_event('setStatic', red, green, blue)
145
146 # remember effect
147 self.set_persistence("left", "effect", 'static')
148 self.zone["left"]["colors"][0:3] = int(red), int(green), int(blue)
149
150 rgb_driver_path = self.get_driver_path('left_matrix_effect_static')
151
152 payload = bytes([red, green, blue])
153
154 with open(rgb_driver_path, 'wb') as rgb_driver_file:
155 rgb_driver_file.write(payload)
156
157
158 @endpoint('razer.device.lighting.left', 'setLeftSpectrum')
159 def set_left_spectrum(self):
160 """
161 Set the device to spectrum mode
162 """
163 self.logger.debug("DBus call set_left_spectrum")
164
165 # Notify others
166 self.send_effect_event('setSpectrum')
167
168 # remember effect
169 self.set_persistence("left", "effect", 'spectrum')
170
171 effect_driver_path = self.get_driver_path('left_matrix_effect_spectrum')
172
173 with open(effect_driver_path, 'w') as effect_driver_file:
174 effect_driver_file.write('1')
175
176
177 @endpoint('razer.device.lighting.left', 'setLeftNone')
178 def set_left_none(self):
179 """
180 Set the device to effect none
181 """
182 self.logger.debug("DBus call set_left_none")
183
184 # Notify others
185 self.send_effect_event('setNone')
186
187 # remember effect
188 self.set_persistence("left", "effect", 'none')
189
190 driver_path = self.get_driver_path('left_matrix_effect_none')
191
192 with open(driver_path, 'w') as driver_file:
193 driver_file.write('1')
194
195
196 @endpoint('razer.device.lighting.left', 'setLeftReactive', in_sig='yyyy')
197 def set_left_reactive(self, red, green, blue, speed):
198 """
199 Set the device to reactive effect
200
201 :param red: Red component
202 :type red: int
203
204 :param green: Green component
205 :type green: int
206
207 :param blue: Blue component
208 :type blue: int
209
210 :param speed: Speed
211 :type speed: int
212 """
213 self.logger.debug("DBus call set_left_reactive")
214
215 driver_path = self.get_driver_path('left_matrix_effect_reactive')
216
217 # Notify others
218 self.send_effect_event('setReactive', red, green, blue, speed)
219
220 # remember effect
221 self.set_persistence("left", "effect", 'reactive')
222 self.zone["left"]["colors"][0:3] = int(red), int(green), int(blue)
223
224 if speed not in (1, 2, 3, 4):
225 speed = 4
226
227 self.set_persistence("left", "speed", int(speed))
228
229 payload = bytes([speed, red, green, blue])
230
231 with open(driver_path, 'wb') as driver_file:
232 driver_file.write(payload)
233
234
235 @endpoint('razer.device.lighting.left', 'setLeftBreathRandom')
236 def set_left_breath_random(self):
237 """
238 Set the device to random colour breathing effect
239 """
240 self.logger.debug("DBus call set_left_breath_random")
241
242 # Notify others
243 self.send_effect_event('setBreathRandom')
244
245 # remember effect
246 self.set_persistence("left", "effect", 'breathRandom')
247
248 driver_path = self.get_driver_path('left_matrix_effect_breath')
249
250 payload = b'1'
251
252 with open(driver_path, 'wb') as driver_file:
253 driver_file.write(payload)
254
255
256 @endpoint('razer.device.lighting.left', 'setLeftBreathSingle', in_sig='yyy')
257 def set_left_breath_single(self, red, green, blue):
258 """
259 Set the device to single colour breathing effect
260
261 :param red: Red component
262 :type red: int
263
264 :param green: Green component
265 :type green: int
266
267 :param blue: Blue component
268 :type blue: int
269 """
270 self.logger.debug("DBus call set_left_breath_single")
271
272 # Notify others
273 self.send_effect_event('setBreathSingle', red, green, blue)
274
275 # remember effect
276 self.set_persistence("left", "effect", 'breathSingle')
277 self.zone["left"]["colors"][0:3] = int(red), int(green), int(blue)
278
279 driver_path = self.get_driver_path('left_matrix_effect_breath')
280
281 payload = bytes([red, green, blue])
282
283 with open(driver_path, 'wb') as driver_file:
284 driver_file.write(payload)
285
286
287 @endpoint('razer.device.lighting.left', 'setLeftBreathDual', in_sig='yyyyyy')
288 def set_left_breath_dual(self, red1, green1, blue1, red2, green2, blue2):
289 """
290 Set the device to dual colour breathing effect
291
292 :param red1: Red component
293 :type red1: int
294
295 :param green1: Green component
296 :type green1: int
297
298 :param blue1: Blue component
299 :type blue1: int
300
301 :param red2: Red component
302 :type red2: int
303
304 :param green2: Green component
305 :type green2: int
306
307 :param blue2: Blue component
308 :type blue2: int
309 """
310 self.logger.debug("DBus call set_left_breath_dual")
311
312 # Notify others
313 self.send_effect_event('setBreathDual', red1, green1, blue1, red2, green2, blue2)
314
315 # remember effect
316 self.set_persistence("left", "effect", 'breathDual')
317 self.zone["left"]["colors"][0:6] = int(red1), int(green1), int(blue1), int(red2), int(green2), int(blue2)
318
319 driver_path = self.get_driver_path('left_matrix_effect_breath')
320
321 payload = bytes([red1, green1, blue1, red2, green2, blue2])
322
323 with open(driver_path, 'wb') as driver_file:
324 driver_file.write(payload)
325
326
327 @endpoint('razer.device.lighting.right', 'getRightBrightness', out_sig='d')
328 def get_right_brightness(self):
329 """
330 Get the device's brightness
331 :return: Brightness
332 :rtype: float
333 """
334 self.logger.debug("DBus call get_right_brightness")
335
336 return self.zone["right"]["brightness"]
337
338
339 @endpoint('razer.device.lighting.right', 'setRightBrightness', in_sig='d')
340 def set_right_brightness(self, brightness):
341 """
342 Set the device's brightness
343
344 :param brightness: Brightness
345 :type brightness: int
346 """
347 self.logger.debug("DBus call set_right_brightness")
348
349 driver_path = self.get_driver_path('right_led_brightness')
350
351 self.method_args['brightness'] = brightness
352
353 if brightness > 100:
354 brightness = 100
355 elif brightness < 0:
356 brightness = 0
357
358 self.set_persistence("right", "brightness", int(brightness))
359
360 brightness = int(round(brightness * (255.0 / 100.0)))
361
362 with open(driver_path, 'w') as driver_file:
363 driver_file.write(str(brightness))
364
365 # Notify others
366 self.send_effect_event('setBrightness', brightness)
367
368
369 @endpoint('razer.device.lighting.right', 'setRightWave', in_sig='i')
370 def set_right_wave(self, direction):
371 """
372 Set the wave effect on the device
373
374 :param direction: (0|1) - down to up, (1|2) up to down
375 :type direction: int
376 """
377 self.logger.debug("DBus call set_right_wave")
378
379 # Notify others
380 self.send_effect_event('setWave', direction)
381
382 # remember effect
383 self.set_persistence("right", "effect", 'wave')
384 self.set_persistence("right", "wave_dir", int(direction))
385
386 driver_path = self.get_driver_path('right_matrix_effect_wave')
387
388 if direction not in self.WAVE_DIRS:
389 direction = self.WAVE_DIRS[0]
390
391 with open(driver_path, 'w') as driver_file:
392 driver_file.write(str(direction))
393
394
395 @endpoint('razer.device.lighting.right', 'setRightStatic', in_sig='yyy')
396 def set_right_static(self, red, green, blue):
397 """
398 Set the device to static colour
399
400 :param red: Red component
401 :type red: int
402
403 :param green: Green component
404 :type green: int
405
406 :param blue: Blue component
407 :type blue: int
408 """
409 self.logger.debug("DBus call set_right_static")
410
411 # Notify others
412 self.send_effect_event('setStatic', red, green, blue)
413
414 # remember effect
415 self.set_persistence("right", "effect", 'static')
416 self.zone["right"]["colors"][0:3] = int(red), int(green), int(blue)
417
418 rgb_driver_path = self.get_driver_path('right_matrix_effect_static')
419
420 payload = bytes([red, green, blue])
421
422 with open(rgb_driver_path, 'wb') as rgb_driver_file:
423 rgb_driver_file.write(payload)
424
425
426 @endpoint('razer.device.lighting.right', 'setRightSpectrum')
427 def set_right_spectrum(self):
428 """
429 Set the device to spectrum mode
430 """
431 self.logger.debug("DBus call set_right_spectrum")
432
433 # Notify others
434 self.send_effect_event('setSpectrum')
435
436 # remember effect
437 self.set_persistence("right", "effect", 'spectrum')
438
439 effect_driver_path = self.get_driver_path('right_matrix_effect_spectrum')
440
441 with open(effect_driver_path, 'w') as effect_driver_file:
442 effect_driver_file.write('1')
443
444
445 @endpoint('razer.device.lighting.right', 'setRightNone')
446 def set_right_none(self):
447 """
448 Set the device to effect none
449 """
450 self.logger.debug("DBus call set_right_none")
451
452 # Notify others
453 self.send_effect_event('setNone')
454
455 # remember effect
456 self.set_persistence("right", "effect", 'none')
457
458 driver_path = self.get_driver_path('right_matrix_effect_none')
459
460 with open(driver_path, 'w') as driver_file:
461 driver_file.write('1')
462
463
464 @endpoint('razer.device.lighting.right', 'setRightReactive', in_sig='yyyy')
465 def set_right_reactive(self, red, green, blue, speed):
466 """
467 Set the device to reactive effect
468
469 :param red: Red component
470 :type red: int
471
472 :param green: Green component
473 :type green: int
474
475 :param blue: Blue component
476 :type blue: int
477
478 :param speed: Speed
479 :type speed: int
480 """
481 self.logger.debug("DBus call set_right_reactive")
482
483 driver_path = self.get_driver_path('right_matrix_effect_reactive')
484
485 # Notify others
486 self.send_effect_event('setReactive', red, green, blue, speed)
487
488 # remember effect
489 self.set_persistence("right", "effect", 'reactive')
490 self.zone["right"]["colors"][0:3] = int(red), int(green), int(blue)
491
492 if speed not in (1, 2, 3, 4):
493 speed = 4
494
495 self.set_persistence("right", "speed", int(speed))
496
497 payload = bytes([speed, red, green, blue])
498
499 with open(driver_path, 'wb') as driver_file:
500 driver_file.write(payload)
501
502
503 @endpoint('razer.device.lighting.right', 'setRightBreathRandom')
504 def set_right_breath_random(self):
505 """
506 Set the device to random colour breathing effect
507 """
508 self.logger.debug("DBus call set_right_breath_random")
509
510 # Notify others
511 self.send_effect_event('setBreathRandom')
512
513 # remember effect
514 self.set_persistence("right", "effect", 'breathRandom')
515
516 driver_path = self.get_driver_path('right_matrix_effect_breath')
517
518 payload = b'1'
519
520 with open(driver_path, 'wb') as driver_file:
521 driver_file.write(payload)
522
523
524 @endpoint('razer.device.lighting.right', 'setRightBreathSingle', in_sig='yyy')
525 def set_right_breath_single(self, red, green, blue):
526 """
527 Set the device to single colour breathing effect
528
529 :param red: Red component
530 :type red: int
531
532 :param green: Green component
533 :type green: int
534
535 :param blue: Blue component
536 :type blue: int
537 """
538 self.logger.debug("DBus call set_right_breath_single")
539
540 # Notify others
541 self.send_effect_event('setBreathSingle', red, green, blue)
542
543 # remember effect
544 self.set_persistence("right", "effect", 'breathSingle')
545 self.zone["right"]["colors"][0:3] = int(red), int(green), int(blue)
546
547 driver_path = self.get_driver_path('right_matrix_effect_breath')
548
549 payload = bytes([red, green, blue])
550
551 with open(driver_path, 'wb') as driver_file:
552 driver_file.write(payload)
553
554
555 @endpoint('razer.device.lighting.right', 'setRightBreathDual', in_sig='yyyyyy')
556 def set_right_breath_dual(self, red1, green1, blue1, red2, green2, blue2):
557 """
558 Set the device to dual colour breathing effect
559
560 :param red1: Red component
561 :type red1: int
562
563 :param green1: Green component
564 :type green1: int
565
566 :param blue1: Blue component
567 :type blue1: int
568
569 :param red2: Red component
570 :type red2: int
571
572 :param green2: Green component
573 :type green2: int
574
575 :param blue2: Blue component
576 :type blue2: int
577 """
578 self.logger.debug("DBus call set_right_breath_dual")
579
580 # Notify others
581 self.send_effect_event('setBreathDual', red1, green1, blue1, red2, green2, blue2)
582
583 # remember effect
584 self.set_persistence("right", "effect", 'breathDual')
585 self.zone["right"]["colors"][0:6] = int(red1), int(green1), int(blue1), int(red2), int(green2), int(blue2)
586
587 driver_path = self.get_driver_path('right_matrix_effect_breath')
588
589 payload = bytes([red1, green1, blue1, red2, green2, blue2])
590
591 with open(driver_path, 'wb') as driver_file:
592 driver_file.write(payload)
593
594
595 @endpoint('razer.device.lighting.backlight', 'setBacklightWave', in_sig='i')
596 def set_backlight_wave(self, direction):
597 """
598 Set the wave effect on the device
599
600 :param direction: (0|1) - down to up, (1|2) up to down
601 :type direction: int
602 """
603 self.logger.debug("DBus call set_backlight_wave")
604
605 # Notify others
606 self.send_effect_event('setWave', direction)
607
608 # remember effect
609 self.set_persistence("backlight", "effect", 'wave')
610 self.set_persistence("backlight", "wave_dir", int(direction))
611
612 driver_path = self.get_driver_path('backlight_matrix_effect_wave')
613
614 if direction not in self.WAVE_DIRS:
615 direction = self.WAVE_DIRS[0]
616
617 with open(driver_path, 'w') as driver_file:
618 driver_file.write(str(direction))
619
620
621 @endpoint('razer.device.lighting.backlight', 'setBacklightStatic', in_sig='yyy')
622 def set_backlight_static(self, red, green, blue):
623 """
624 Set the device to static colour
625
626 :param red: Red component
627 :type red: int
628
629 :param green: Green component
630 :type green: int
631
632 :param blue: Blue component
633 :type blue: int
634 """
635 self.logger.debug("DBus call set_backlight_static")
636
637 # Notify others
638 self.send_effect_event('setStatic', red, green, blue)
639
640 # remember effect
641 self.set_persistence("backlight", "effect", 'static')
642 self.zone["backlight"]["colors"][0:3] = int(red), int(green), int(blue)
643
644 rgb_driver_path = self.get_driver_path('backlight_matrix_effect_static')
645
646 payload = bytes([red, green, blue])
647
648 with open(rgb_driver_path, 'wb') as rgb_driver_file:
649 rgb_driver_file.write(payload)
650
651
652 @endpoint('razer.device.lighting.backlight', 'setBacklightSpectrum')
653 def set_backlight_spectrum(self):
654 """
655 Set the device to spectrum mode
656 """
657 self.logger.debug("DBus call set_backlight_spectrum")
658
659 # Notify others
660 self.send_effect_event('setSpectrum')
661
662 # remember effect
663 self.set_persistence("backlight", "effect", 'spectrum')
664
665 effect_driver_path = self.get_driver_path('backlight_matrix_effect_spectrum')
666
667 with open(effect_driver_path, 'w') as effect_driver_file:
668 effect_driver_file.write('1')
669
670
671 @endpoint('razer.device.lighting.backlight', 'setBacklightNone')
672 def set_backlight_none(self):
673 """
674 Set the device to effect none
675 """
676 self.logger.debug("DBus call set_backlight_none")
677
678 # Notify others
679 self.send_effect_event('setNone')
680
681 # remember effect
682 self.set_persistence("backlight", "effect", 'none')
683
684 driver_path = self.get_driver_path('backlight_matrix_effect_none')
685
686 with open(driver_path, 'w') as driver_file:
687 driver_file.write('1')
688
689
690 @endpoint('razer.device.lighting.backlight', 'setBacklightOn')
691 def set_backlight_on(self):
692 """
693 Set the device to effect on
694 """
695 self.logger.debug("DBus call set_backlight_on")
696
697 # Notify others
698 self.send_effect_event('setOn')
699
700 # remember effect
701 self.set_persistence("backlight", "effect", 'on')
702
703 driver_path = self.get_driver_path('backlight_matrix_effect_on')
704
705 with open(driver_path, 'w') as driver_file:
706 driver_file.write('1')
707
708
709 @endpoint('razer.device.lighting.backlight', 'setBacklightReactive', in_sig='yyyy')
710 def set_backlight_reactive(self, red, green, blue, speed):
711 """
712 Set the device to reactive effect
713
714 :param red: Red component
715 :type red: int
716
717 :param green: Green component
718 :type green: int
719
720 :param blue: Blue component
721 :type blue: int
722
723 :param speed: Speed
724 :type speed: int
725 """
726 self.logger.debug("DBus call set_backlight_reactive")
727
728 driver_path = self.get_driver_path('backlight_matrix_effect_reactive')
729
730 # Notify others
731 self.send_effect_event('setReactive', red, green, blue, speed)
732
733 # remember effect
734 self.set_persistence("backlight", "effect", 'reactive')
735 self.zone["backlight"]["colors"][0:3] = int(red), int(green), int(blue)
736
737 if speed not in (1, 2, 3, 4):
738 speed = 4
739
740 self.set_persistence("backlight", "speed", int(speed))
741
742 payload = bytes([speed, red, green, blue])
743
744 with open(driver_path, 'wb') as driver_file:
745 driver_file.write(payload)
746
747
748 @endpoint('razer.device.lighting.backlight', 'setBacklightBreathRandom')
749 def set_backlight_breath_random(self):
750 """
751 Set the device to random colour breathing effect
752 """
753 self.logger.debug("DBus call set_backlight_breath_random")
754
755 # Notify others
756 self.send_effect_event('setBreathRandom')
757
758 # remember effect
759 self.set_persistence("backlight", "effect", 'breathRandom')
760
761 driver_path = self.get_driver_path('backlight_matrix_effect_breath')
762
763 payload = b'1'
764
765 with open(driver_path, 'wb') as driver_file:
766 driver_file.write(payload)
767
768
769 @endpoint('razer.device.lighting.backlight', 'setBacklightBreathSingle', in_sig='yyy')
770 def set_backlight_breath_single(self, red, green, blue):
771 """
772 Set the device to single colour breathing effect
773
774 :param red: Red component
775 :type red: int
776
777 :param green: Green component
778 :type green: int
779
780 :param blue: Blue component
781 :type blue: int
782 """
783 self.logger.debug("DBus call set_backlight_breath_single")
784
785 # Notify others
786 self.send_effect_event('setBreathSingle', red, green, blue)
787
788 # remember effect
789 self.set_persistence("backlight", "effect", 'breathSingle')
790 self.zone["backlight"]["colors"][0:3] = int(red), int(green), int(blue)
791
792 driver_path = self.get_driver_path('backlight_matrix_effect_breath')
793
794 payload = bytes([red, green, blue])
795
796 with open(driver_path, 'wb') as driver_file:
797 driver_file.write(payload)
798
799
800 @endpoint('razer.device.lighting.backlight', 'setBacklightBreathDual', in_sig='yyyyyy')
801 def set_backlight_breath_dual(self, red1, green1, blue1, red2, green2, blue2):
802 """
803 Set the device to dual colour breathing effect
804
805 :param red1: Red component
806 :type red1: int
807
808 :param green1: Green component
809 :type green1: int
810
811 :param blue1: Blue component
812 :type blue1: int
813
814 :param red2: Red component
815 :type red2: int
816
817 :param green2: Green component
818 :type green2: int
819
820 :param blue2: Blue component
821 :type blue2: int
822 """
823 self.logger.debug("DBus call set_backlight_breath_dual")
824
825 # Notify others
826 self.send_effect_event('setBreathDual', red1, green1, blue1, red2, green2, blue2)
827
828 # remember effect
829 self.set_persistence("backlight", "effect", 'breathDual')
830 self.zone["backlight"]["colors"][0:6] = int(red1), int(green1), int(blue1), int(red2), int(green2), int(blue2)
831
832 driver_path = self.get_driver_path('backlight_matrix_effect_breath')
833
834 payload = bytes([red1, green1, blue1, red2, green2, blue2])
835
836 with open(driver_path, 'wb') as driver_file:
837 driver_file.write(payload)