-
-
Notifications
You must be signed in to change notification settings - Fork 515
/
fx.py
1241 lines (938 loc) · 36.6 KB
/
fx.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SPDX-License-Identifier: GPL-2.0-or-later
import numpy as _np
import dbus as _dbus
# from openrazer.client.constants import WAVE_LEFT, WAVE_RIGHT, REACTIVE_500MS, REACTIVE_1000MS, REACTIVE_1500MS, REACTIVE_2000MS
from openrazer.client import constants as c
# TODO logging.debug if value out of range v1.1
def clamp_ubyte(value):
"""
Clamp a value to 0->255
Aka -3453
:param value: Integer
:type value: int
:return: Integer 0->255
:rtype: int
"""
if value > 255:
value = 255
elif value < 0:
value = 0
return value
# Default Chroma lighting
class BaseRazerFX(object):
def __init__(self, serial: str, capabilities: dict, daemon_dbus=None):
self._capabilities = capabilities
if daemon_dbus is None:
session_bus = _dbus.SessionBus()
daemon_dbus = session_bus.get_object("org.razer", "/org/razer/device/{0}".format(serial))
self._dbus = daemon_dbus
def has(self, capability: str) -> bool:
"""
Convenience function to check capability
Uses the main device capability list and automatically prefixes 'lighting_'
:param capability: Device capability
:type capability: str
:return: True or False
:rtype: bool
"""
return self._capabilities.get('lighting_' + capability, False)
class RazerFX(BaseRazerFX):
def __init__(self, serial: str, capabilities: dict, daemon_dbus=None, matrix_dims=(-1, -1)):
super().__init__(serial, capabilities, daemon_dbus)
self._lighting_dbus = _dbus.Interface(self._dbus, "razer.device.lighting.chroma")
# all() part basically checks that all dimensions are present (-1 is bad)
if self.has('led_matrix') and all([dim >= 1 for dim in matrix_dims]):
self.advanced = RazerAdvancedFX(serial, capabilities, daemon_dbus=self._dbus, matrix_dims=matrix_dims)
else:
self.advanced = None
# Only keyboards will have ripple set
if self.has('led_matrix') and self.has('ripple'):
self._custom_lighting_dbus = _dbus.Interface(self._dbus, "razer.device.lighting.custom")
else:
self._custom_lighting_dbus = None
self.misc = MiscLighting(serial, capabilities, self._dbus)
@property
def effect(self) -> str:
"""
Get current effect
:return: Effect name ("static", "spectrum", etc.)
:rtype: str
"""
return self._lighting_dbus.getEffect()
@property
def colors(self) -> bytearray:
"""
Get current effect colors
:return: Effect colors (an array of 9 bytes, for 3 colors in RGB format)
:rtype: bytearray
"""
return bytes(self._lighting_dbus.getEffectColors())
@property
def speed(self) -> int:
"""
Get current effect speed
:return: Effect speed (a value between 0 and 3)
:rtype: int
"""
return self._lighting_dbus.getEffectSpeed()
@property
def wave_dir(self) -> int:
"""
Get current wave direction
:return: Wave direction (WAVE_LEFT or WAVE_RIGHT)
:rtype: int
"""
return self._lighting_dbus.getWaveDir()
def none(self) -> bool:
"""
No effect
:return: True if success, False otherwise
:rtype: bool
"""
if self.has('none'):
self._lighting_dbus.setNone()
return True
return False
def spectrum(self) -> bool:
"""
Spectrum effect
:return: True if success, False otherwise
:rtype: bool
"""
if self.has('spectrum'):
self._lighting_dbus.setSpectrum()
return True
return False
def wave(self, direction: int) -> bool:
"""
Wave effect
:param direction: Wave direction either WAVE_RIGHT (0x01) or WAVE_LEFT (0x02)
:type direction: int
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If direction is invalid
"""
if direction not in (c.WAVE_LEFT, c.WAVE_RIGHT):
raise ValueError("Direction must be WAVE_RIGHT (0x01) or WAVE_LEFT (0x02)")
if self.has('wave'):
self._lighting_dbus.setWave(direction)
return True
return False
def wheel(self, direction: int) -> bool:
"""
Wheel effect
:param direction: Wheel direction either WHEEL_RIGHT or WHEEL_LEFT
:type direction: int
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If direction is invalid
"""
if direction not in (c.WHEEL_LEFT, c.WHEEL_RIGHT):
raise ValueError("Direction must be WHEEL_RIGHT (0x01) or WHEEL_LEFT (0x02)")
if self.has('wheel'):
self._lighting_dbus.setWheel(direction)
return True
return False
def static(self, red: int, green: int, blue: int) -> bool:
"""
Static effect
:param red: Red component. Must be 0->255
:type red: int
:param green: Green component. Must be 0->255
:type green: int
:param blue: Blue component. Must be 0->255
:type blue: int
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If parameters are invalid
"""
if not isinstance(red, int):
raise ValueError("Red is not an integer")
if not isinstance(green, int):
raise ValueError("Green is not an integer")
if not isinstance(blue, int):
raise ValueError("Blue is not an integer")
if self.has('static'):
red = clamp_ubyte(red)
green = clamp_ubyte(green)
blue = clamp_ubyte(blue)
self._lighting_dbus.setStatic(red, green, blue)
return True
return False
def reactive(self, red: int, green: int, blue: int, time: int) -> bool:
"""
Reactive effect
:param time: Reactive speed. One of REACTIVE_500MS, REACTIVE_1000MS, REACTIVE_1500MS or REACTIVE_2000MS
:param time: int
:param red: Red component. Must be 0->255
:type red: int
:param green: Green component. Must be 0->255
:type green: int
:param blue: Blue component. Must be 0->255
:type blue: int
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If parameters are invalid
"""
if time not in (c.REACTIVE_500MS, c.REACTIVE_1000MS, c.REACTIVE_1500MS, c.REACTIVE_2000MS):
raise ValueError("Time not one of REACTIVE_500MS, REACTIVE_1000MS, REACTIVE_1500MS or REACTIVE_2000MS")
if not isinstance(red, int):
raise ValueError("Red is not an integer")
if not isinstance(green, int):
raise ValueError("Green is not an integer")
if not isinstance(blue, int):
raise ValueError("Blue is not an integer")
if self.has('reactive'):
red = clamp_ubyte(red)
green = clamp_ubyte(green)
blue = clamp_ubyte(blue)
self._lighting_dbus.setReactive(red, green, blue, time)
return True
return False
def breath_single(self, red: int, green: int, blue: int) -> bool:
"""
Breath effect - single colour
:param red: Red component. Must be 0->255
:type red: int
:param green: Green component. Must be 0->255
:type green: int
:param blue: Blue component. Must be 0->255
:type blue: int
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If parameters are invalid
"""
if not isinstance(red, int):
raise ValueError("Red is not an integer")
if not isinstance(green, int):
raise ValueError("Green is not an integer")
if not isinstance(blue, int):
raise ValueError("Blue is not an integer")
if self.has('breath_single'):
red = clamp_ubyte(red)
green = clamp_ubyte(green)
blue = clamp_ubyte(blue)
self._lighting_dbus.setBreathSingle(red, green, blue)
return True
return False
# TODO Change to tuple of rgb
def breath_dual(self, red: int, green: int, blue: int, red2: int, green2: int, blue2: int) -> bool:
"""
Breath effect - single colour
:param red: First red component. Must be 0->255
:type red: int
:param green: First green component. Must be 0->255
:type green: int
:param blue: First blue component. Must be 0->255
:type blue: int
:param red2: Second red component. Must be 0->255
:type red2: int
:param green2: Second green component. Must be 0->255
:type green2: int
:param blue2: Second blue component. Must be 0->255
:type blue2: int
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If parameters are invalid
"""
if not isinstance(red, int):
raise ValueError("Primary red is not an integer")
if not isinstance(green, int):
raise ValueError("Primary green is not an integer")
if not isinstance(blue, int):
raise ValueError("Primary blue is not an integer")
if not isinstance(red2, int):
raise ValueError("Secondary red is not an integer")
if not isinstance(green2, int):
raise ValueError("Secondary green is not an integer")
if not isinstance(blue2, int):
raise ValueError("Secondary blue is not an integer")
if self.has('breath_dual'):
red = clamp_ubyte(red)
green = clamp_ubyte(green)
blue = clamp_ubyte(blue)
red2 = clamp_ubyte(red2)
green2 = clamp_ubyte(green2)
blue2 = clamp_ubyte(blue2)
self._lighting_dbus.setBreathDual(red, green, blue, red2, green2, blue2)
return True
return False
def breath_triple(self, red: int, green: int, blue: int, red2: int, green2: int, blue2: int, red3: int, green3: int, blue3: int) -> bool:
"""
Breath effect - single colour
:param red: First red component. Must be 0->255
:type red: int
:param green: First green component. Must be 0->255
:type green: int
:param blue: First blue component. Must be 0->255
:type blue: int
:param red2: Second red component. Must be 0->255
:type red2: int
:param green2: Second green component. Must be 0->255
:type green2: int
:param blue2: Second blue component. Must be 0->255
:type blue2: int
:param red3: Second red component. Must be 0->255
:type red3: int
:param green3: Second green component. Must be 0->255
:type green3: int
:param blue3: Second blue component. Must be 0->255
:type blue3: int
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If parameters are invalid
"""
if not isinstance(red, int):
raise ValueError("Primary red is not an integer")
if not isinstance(green, int):
raise ValueError("Primary green is not an integer")
if not isinstance(blue, int):
raise ValueError("Primary blue is not an integer")
if not isinstance(red2, int):
raise ValueError("Secondary red is not an integer")
if not isinstance(green2, int):
raise ValueError("Secondary green is not an integer")
if not isinstance(blue2, int):
raise ValueError("Secondary blue is not an integer")
if not isinstance(red3, int):
raise ValueError("Tertiary red is not an integer")
if not isinstance(green3, int):
raise ValueError("Tertiary green is not an integer")
if not isinstance(blue3, int):
raise ValueError("Tertiary blue is not an integer")
if self.has('breath_triple'):
red = clamp_ubyte(red)
green = clamp_ubyte(green)
blue = clamp_ubyte(blue)
red2 = clamp_ubyte(red2)
green2 = clamp_ubyte(green2)
blue2 = clamp_ubyte(blue2)
red3 = clamp_ubyte(red3)
green3 = clamp_ubyte(green3)
blue3 = clamp_ubyte(blue3)
self._lighting_dbus.setBreathTriple(red, green, blue, red2, green2, blue2, red3, green3, blue3)
return True
return False
def breath_random(self) -> bool:
"""
Breath effect - random colours
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If parameters are invalid
"""
if self.has('breath_random'):
self._lighting_dbus.setBreathRandom()
return True
return False
def ripple(self, red: int, green: int, blue: int, refreshrate: float = c.RIPPLE_REFRESH_RATE) -> bool:
"""
Set the Ripple Effect.
The refresh rate should be set to about 0.05 for a decent effect
:param red: Red RGB component
:rtype red: int
:param green: Green RGB component
:type green: int
:param blue: Blue RGB component
:type blue: int
:param refreshrate: Effect refresh rate
:type refreshrate: float
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If arguments are invalid
"""
if not isinstance(refreshrate, float):
raise ValueError("Refresh rate is not a float")
if not isinstance(red, int):
raise ValueError("Red is not an integer")
if not isinstance(green, int):
raise ValueError("Green is not an integer")
if not isinstance(blue, int):
raise ValueError("Blue is not an integer")
if self.has('ripple'):
red = clamp_ubyte(red)
green = clamp_ubyte(green)
blue = clamp_ubyte(blue)
self._custom_lighting_dbus.setRipple(red, green, blue, refreshrate)
return True
return False
def ripple_random(self, refreshrate: float = c.RIPPLE_REFRESH_RATE):
"""
Set the Ripple Effect with random colours
The refresh rate should be set to about 0.05 for a decent effect
:param refreshrate: Effect refresh rate
:type refreshrate: float
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If arguments are invalid
"""
if not isinstance(refreshrate, float):
raise ValueError("Refresh rate is not a float")
if self.has('ripple_random'):
self._custom_lighting_dbus.setRippleRandomColour(refreshrate)
return True
return False
def starlight_single(self, red: int, green: int, blue: int, time: int) -> bool:
"""
Starlight effect
:param red: Red component. Must be 0->255
:type red: int
:param green: Green component. Must be 0->255
:type green: int
:param blue: Blue component. Must be 0->255
:type blue: int
:param time: Starlight speed
:type time: int
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If parameters are invalid
"""
if time not in (c.STARLIGHT_FAST, c.STARLIGHT_NORMAL, c.STARLIGHT_SLOW):
raise ValueError("Time not one of STARLIGHT_FAST, STARLIGHT_NORMAL or STARLIGHT_SLOW")
if not isinstance(red, int):
raise ValueError("Red is not an integer")
if not isinstance(green, int):
raise ValueError("Green is not an integer")
if not isinstance(blue, int):
raise ValueError("Blue is not an integer")
if self.has('starlight_single'):
red = clamp_ubyte(red)
green = clamp_ubyte(green)
blue = clamp_ubyte(blue)
self._lighting_dbus.setStarlightSingle(red, green, blue, time)
return True
return False
def starlight_dual(self, red: int, green: int, blue: int, red2: int, green2: int, blue2: int, time: int) -> bool:
"""
Starlight effect
:param red: Red component. Must be 0->255
:type red: int
:param green: Green component. Must be 0->255
:type green: int
:param blue: Blue component. Must be 0->255
:type blue: int
:param red2: Red component. Must be 0->255
:type red2: int
:param green2: Green component. Must be 0->255
:type green2: int
:param blue2: Blue component. Must be 0->255
:type blue2: int
:param time: Starlight speed
:type time: int
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If parameters are invalid
"""
if time not in (c.STARLIGHT_FAST, c.STARLIGHT_NORMAL, c.STARLIGHT_SLOW):
raise ValueError("Time not one of STARLIGHT_FAST, STARLIGHT_NORMAL or STARLIGHT_SLOW")
if not isinstance(red, int):
raise ValueError("Red is not an integer")
if not isinstance(green, int):
raise ValueError("Green is not an integer")
if not isinstance(blue, int):
raise ValueError("Blue is not an integer")
if not isinstance(red2, int):
raise ValueError("Red 2 is not an integer")
if not isinstance(green2, int):
raise ValueError("Green 2 is not an integer")
if not isinstance(blue2, int):
raise ValueError("Blue 2 is not an integer")
if self.has('starlight_dual'):
red = clamp_ubyte(red)
green = clamp_ubyte(green)
blue = clamp_ubyte(blue)
red2 = clamp_ubyte(red2)
green2 = clamp_ubyte(green2)
blue2 = clamp_ubyte(blue2)
self._lighting_dbus.setStarlightDual(red, green, blue, red2, green2, blue2, time)
return True
return False
def starlight_random(self, time: int) -> bool:
"""
Starlight effect
:param time: Starlight speed
:type time: int
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If parameters are invalid
"""
if time not in (c.STARLIGHT_FAST, c.STARLIGHT_NORMAL, c.STARLIGHT_SLOW):
raise ValueError("Time not one of STARLIGHT_FAST, STARLIGHT_NORMAL or STARLIGHT_SLOW")
if self.has('starlight_random'):
self._lighting_dbus.setStarlightRandom(time)
return True
return False
class RazerAdvancedFX(BaseRazerFX):
def __init__(self, serial: str, capabilities: dict, daemon_dbus=None, matrix_dims=(-1, -1)):
super().__init__(serial, capabilities, daemon_dbus)
# Only init'd when there's a matrix
self._capabilities = capabilities
if not all([dim >= 1 for dim in matrix_dims]):
raise ValueError("Matrix dimensions cannot contain -1")
if daemon_dbus is None:
session_bus = _dbus.SessionBus()
daemon_dbus = session_bus.get_object("org.razer", "/org/razer/device/{0}".format(serial))
self._matrix_dims = matrix_dims
self._lighting_dbus = _dbus.Interface(daemon_dbus, "razer.device.lighting.chroma")
self.matrix = Frame(matrix_dims)
@property
def cols(self):
"""
Number of columns in matrix
:return: Columns
:rtype: int
"""
return self._matrix_dims[1]
@property
def rows(self):
"""
Number of rows in matrix
:return: Rows
:rtype: int
"""
return self._matrix_dims[0]
def _draw(self, ba):
self._lighting_dbus.setKeyRow(ba)
self._lighting_dbus.setCustom()
def draw(self):
"""
Draw what's in the current frame buffer
"""
self._draw(bytes(self.matrix))
def draw_fb_or(self):
self._draw(bytes(self.matrix.draw_with_fb_or()))
def set_key(self, column_id, rgb, row_id=0): # Not needed on mice
if self.has('led_single'):
if isinstance(rgb, (tuple, list)) and len(rgb) == 3 and all([isinstance(component, int) for component in rgb]):
if row_id < self._matrix_dims[0] and column_id < self._matrix_dims[1]:
self._lighting_dbus.setKey(row_id, column_id, [clamp_ubyte(component) for component in rgb])
else:
raise ValueError("Row or column out of bounds. Max dimensions are: {0},{1}".format(*self._matrix_dims))
else:
raise ValueError("RGB must be an RGB tuple")
def restore(self):
"""
Restore the device to the last effect
"""
self._lighting_dbus.restoreLastEffect()
class SingleLed(BaseRazerFX):
def __init__(self, serial: str, capabilities: dict, daemon_dbus=None, led_name='logo'):
super().__init__(serial, capabilities, daemon_dbus)
self._led_name = led_name
self._lighting_dbus = _dbus.Interface(self._dbus, "razer.device.lighting.{0}".format(led_name))
def _shas(self, item):
return self.has('{0}_{1}'.format(self._led_name, item))
def _getattr(self, name):
attr = name.replace('#', self._led_name.title().replace("_", ""))
return getattr(self._lighting_dbus, attr, None)
@property
def active(self) -> bool:
func = self._getattr('get#Active')
if func is not None:
return func()
else:
return False
@active.setter
def active(self, value: bool):
func = self._getattr('set#Active')
if func is not None:
if value:
func(True)
else:
func(False)
@property
def effect(self) -> str:
"""
Get current effect
:return: Effect name ("static", "spectrum", etc.)
:rtype: str
"""
return str(self._getattr('get#Effect')())
@property
def colors(self) -> bytearray:
"""
Get current effect colors
:return: Effect colors (an array of 9 bytes, for 3 colors in RGB format)
:rtype: bytearray
"""
return bytes(self._getattr('get#EffectColors')())
@property
def speed(self) -> int:
"""
Get current effect speed
:return: Effect speed (a value between 0 and 3)
:rtype: int
"""
return int(self._getattr('get#EffectSpeed')())
@property
def wave_dir(self) -> int:
"""
Get current wave direction
:return: Wave direction (WAVE_LEFT or WAVE_RIGHT)
:rtype: int
"""
return int(self._getattr('get#WaveDir')())
@property
def brightness(self):
if self._shas('brightness'):
return float(self._getattr('get#Brightness')())
return 0.0
@brightness.setter
def brightness(self, brightness: float):
if self._shas('brightness'):
if not isinstance(brightness, (float, int)):
raise ValueError("Brightness is not a float")
if brightness > 100:
brightness = 100.0
elif brightness < 0:
brightness = 0.0
self._getattr('set#Brightness')(brightness)
def blinking(self, red: int, green: int, blue: int) -> bool:
if not isinstance(red, int):
raise ValueError("Red is not an integer")
if not isinstance(green, int):
raise ValueError("Green is not an integer")
if not isinstance(blue, int):
raise ValueError("Blue is not an integer")
if self._shas('blinking'):
red = clamp_ubyte(red)
green = clamp_ubyte(green)
blue = clamp_ubyte(blue)
self._getattr('set#Blinking')(red, green, blue)
return True
return False
def pulsate(self, red: int, green: int, blue: int) -> bool:
if not isinstance(red, int):
raise ValueError("Red is not an integer")
if not isinstance(green, int):
raise ValueError("Green is not an integer")
if not isinstance(blue, int):
raise ValueError("Blue is not an integer")
if self._shas('pulsate'):
red = clamp_ubyte(red)
green = clamp_ubyte(green)
blue = clamp_ubyte(blue)
self._getattr('set#Pulsate')(red, green, blue)
return True
return False
def static(self, red: int, green: int, blue: int) -> bool:
if not isinstance(red, int):
raise ValueError("Red is not an integer")
if not isinstance(green, int):
raise ValueError("Green is not an integer")
if not isinstance(blue, int):
raise ValueError("Blue is not an integer")
if self._shas('static'):
red = clamp_ubyte(red)
green = clamp_ubyte(green)
blue = clamp_ubyte(blue)
self._getattr('set#Static')(red, green, blue)
return True
return False
def wave(self, direction: int) -> bool:
if direction not in (c.WAVE_LEFT, c.WAVE_RIGHT):
raise ValueError("Direction must be WAVE_RIGHT (0x01) or WAVE_LEFT (0x02)")
if self._shas('wave'):
self._getattr('set#Wave')(direction)
return True
return False
def none(self) -> bool:
if self._shas('none'):
self._getattr('set#None')()
return True
return False
def on(self) -> bool:
if self._shas('on'):
self._getattr('set#On')()
return True
return False
def spectrum(self) -> bool:
if self._shas('spectrum'):
self._getattr('set#Spectrum')()
return True
return False
def reactive(self, red: int, green: int, blue: int, time: int) -> bool:
"""
Reactive effect
:param time: Reactive speed. One of REACTIVE_500MS, REACTIVE_1000MS, REACTIVE_1500MS or REACTIVE_2000MS
:param time: int
:param red: Red component. Must be 0->255
:type red: int
:param green: Green component. Must be 0->255
:type green: int
:param blue: Blue component. Must be 0->255
:type blue: int
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If parameters are invalid
"""
if time not in (c.REACTIVE_500MS, c.REACTIVE_1000MS, c.REACTIVE_1500MS, c.REACTIVE_2000MS):
raise ValueError("Time not one of REACTIVE_500MS, REACTIVE_1000MS, REACTIVE_1500MS or REACTIVE_2000MS")
if not isinstance(red, int):
raise ValueError("Red is not an integer")
if not isinstance(green, int):
raise ValueError("Green is not an integer")
if not isinstance(blue, int):
raise ValueError("Blue is not an integer")
if self._shas('reactive'):
red = clamp_ubyte(red)
green = clamp_ubyte(green)
blue = clamp_ubyte(blue)
self._getattr('set#Reactive')(red, green, blue, time)
return True
return False
def breath_single(self, red: int, green: int, blue: int) -> bool:
"""
Breath effect - single colour
:param red: Red component. Must be 0->255
:type red: int
:param green: Green component. Must be 0->255
:type green: int
:param blue: Blue component. Must be 0->255
:type blue: int
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If parameters are invalid
"""
if not isinstance(red, int):
raise ValueError("Red is not an integer")
if not isinstance(green, int):
raise ValueError("Green is not an integer")
if not isinstance(blue, int):
raise ValueError("Blue is not an integer")
if self._shas('breath_single'):
red = clamp_ubyte(red)
green = clamp_ubyte(green)
blue = clamp_ubyte(blue)
self._getattr('set#BreathSingle')(red, green, blue)
return True
return False
# TODO Change to tuple of rgb
def breath_dual(self, red: int, green: int, blue: int, red2: int, green2: int, blue2: int) -> bool:
"""
Breath effect - single colour
:param red: First red component. Must be 0->255
:type red: int
:param green: First green component. Must be 0->255
:type green: int
:param blue: First blue component. Must be 0->255
:type blue: int
:param red2: Second red component. Must be 0->255
:type red2: int
:param green2: Second green component. Must be 0->255
:type green2: int
:param blue2: Second blue component. Must be 0->255
:type blue2: int
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If parameters are invalid
"""
if not isinstance(red, int):
raise ValueError("Primary red is not an integer")
if not isinstance(green, int):
raise ValueError("Primary green is not an integer")
if not isinstance(blue, int):
raise ValueError("Primary blue is not an integer")
if not isinstance(red2, int):
raise ValueError("Secondary red is not an integer")
if not isinstance(green2, int):
raise ValueError("Secondary green is not an integer")
if not isinstance(blue2, int):
raise ValueError("Secondary blue is not an integer")
if self._shas('breath_dual'):
red = clamp_ubyte(red)
green = clamp_ubyte(green)
blue = clamp_ubyte(blue)
red2 = clamp_ubyte(red2)
green2 = clamp_ubyte(green2)
blue2 = clamp_ubyte(blue2)
self._getattr('set#BreathDual')(red, green, blue, red2, green2, blue2)
return True
return False
def breath_random(self) -> bool:
"""
Breath effect - random colours
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If parameters are invalid
"""
if self._shas('breath_random'):
self._getattr('set#BreathRandom')()