11import RPi .GPIO as GPIO
22import time
3- try :
4- from plasma import legacy as plasma
5- except ImportError :
6- import plasma
3+ import apa102
74import atexit
85from threading import Thread
96
@@ -27,16 +24,14 @@ def __init__(self, pin_fancontrol=18, pin_button=17, button_poll_delay=0.05):
2724 self ._button_hold_time = 2.0
2825 self ._t_poll = None
2926
30- atexit .register (self ._cleanup )
31-
3227 GPIO .setwarnings (False )
3328 GPIO .setmode (GPIO .BCM )
3429 GPIO .setup (self ._pin_fancontrol , GPIO .OUT )
3530 GPIO .setup (self ._pin_button , GPIO .IN , pull_up_down = GPIO .PUD_UP )
3631
37- plasma . set_clear_on_exit ( True )
38- plasma . set_light_count ( 1 )
39- plasma . set_light ( 0 , 0 , 0 , 0 )
32+ self . _led = apa102 . APA102 ( 1 , 15 , 14 , None , brightness = 0.05 )
33+
34+ atexit . register ( self . _cleanup )
4035
4136 def start_polling (self ):
4237 """Start button polling."""
@@ -109,20 +104,24 @@ def set_fan(self, fan_state):
109104 GPIO .output (self ._pin_fancontrol , True if fan_state else False )
110105 return True if fan_state else False
111106
112- def set_light (self , r , g , b ):
107+ def set_light (self , r , g , b , brightness = None ):
113108 """Set LED.
114109
115110 :param r: Red (0-255)
116111 :param g: Green (0-255)
117112 :param b: Blue (0-255)
118113
119114 """
120- plasma .set_light (0 , r , g , b )
121- plasma .show ()
115+ self ._led .set_pixel (0 , r , g , b )
116+ if brightness is not None :
117+ self ._led .set_brightness (0 , brightness )
118+ self ._led .show ()
122119
123120 def _cleanup (self ):
124121 self .stop_polling ()
125122
123+ self .set_light (0 , 0 , 0 )
124+
126125 def _run (self ):
127126 self ._running = True
128127 last = 1
0 commit comments