77__version__ = '0.0.1'
88
99
10- class FANShim ():
11- def __init__ (self ):
12- self ._pin_fancontrol = 18
13- self ._pin_button = 17
10+ class FanShim ():
11+ def __init__ (self , pin_fancontrol = 18 , pin_button = 17 ):
12+ """FAN Shim.
13+
14+ :param pin_fancontrol: BCM pin for fan on/off
15+ :param pin_button: BCM pin for button
16+
17+ """
18+ self ._pin_fancontrol = pin_fancontrol
19+ self ._pin_button = pin_button
1420 self ._button_press_handler = None
1521 self ._button_release_handler = None
1622 self ._button_hold_handler = None
23+ self ._button_hold_time = 2.0
1724 self ._t_poll = None
1825
1926 atexit .register (self ._cleanup )
@@ -27,20 +34,23 @@ def __init__(self):
2734 plasma .set_light_count (1 )
2835 plasma .set_light (0 , 0 , 0 , 0 )
2936
30- self .start ()
37+ self .start_polling ()
3138
32- def start (self ):
39+ def start_polling (self ):
40+ """Start button polling."""
3341 if self ._t_poll is None :
3442 self ._t_poll = Thread (target = self ._run )
3543 self ._t_poll .daemon = True
3644 self ._t_poll .start ()
3745
38- def stop (self ):
46+ def stop_polling (self ):
47+ """Stop button polling."""
3948 if self ._t_poll is not None :
4049 self ._running = False
4150 self ._t_poll .join ()
4251
4352 def on_press (self , handler = None ):
53+ """Attach function to button press event."""
4454 def attach_handler (handler ):
4555 self ._button_press_handler = handler
4656
@@ -50,6 +60,7 @@ def attach_handler(handler):
5060 return attach_handler
5161
5262 def on_release (self , handler = None ):
63+ """Attach function to button release event."""
5364 def attach_handler (handler ):
5465 self ._button_release_handler = handler
5566
@@ -59,6 +70,7 @@ def attach_handler(handler):
5970 return attach_handler
6071
6172 def on_hold (self , handler = None ):
73+ """Attach function to button hold event."""
6274 def attach_handler (handler ):
6375 self ._button_hold_handler = handler
6476
@@ -76,9 +88,11 @@ def set_hold_time(self, hold_time):
7688 self ._button_hold_time = hold_time
7789
7890 def get_fan (self ):
91+ """Get current fan state."""
7992 return GPIO .input (self ._pin_fancontrol )
8093
8194 def toggle_fan (self ):
95+ """Toggle fan state."""
8296 return self .set_fan (False if self .get_fan () else True )
8397
8498 def set_fan (self , fan_state ):
@@ -91,6 +105,13 @@ def set_fan(self, fan_state):
91105 return True if fan_state else False
92106
93107 def set_light (self , r , g , b ):
108+ """Set LED.
109+
110+ :param r: Red (0-255)
111+ :param g: Green (0-255)
112+ :param b: Blue (0-255)
113+
114+ """
94115 plasma .set_light (0 , r , g , b )
95116 plasma .show ()
96117
0 commit comments