11from adafruit_hid .keyboard import Keyboard
22from adafruit_hid .keycode import Keycode
3+ import puff_detector
34
5+ kbd = Keyboard ()
46
5- def log (message ):
6- print ("\t \t HIDDEMO::%s" % message )
7+ detector = puff_detector .PuffDetector ()
78
9+ @detector .on_sip
10+ def on_sip (strength , duration ):
11+ if strength == puff_detector .STRONG :
12+ kbd .send (Keycode .LEFT_ARROW )
13+ kbd .send (Keycode .LEFT_ARROW )
14+ if strength == puff_detector .SOFT :
15+ kbd .send (Keycode .LEFT_ARROW )
816
9- class SimpleHid :
10- def __init__ (self ):
11- self .kbd = Keyboard ()
12- print ("SimpleHid inited" )
17+ @detector .on_puff
18+ def on_puff (strength , duration ):
19+ if strength == puff_detector .STRONG :
20+ kbd .send (Keycode .RIGHT_ARROW )
21+ kbd .send (Keycode .RIGHT_ARROW )
22+ if strength == puff_detector .SOFT :
23+ kbd .send (Keycode .RIGHT_ARROW )
1324
14- def run (self , detector , state_map , puff_stat ): # pylint:disable=unused-argument
15-
16- if state_map [detector .state ]["name" ] == "WAITING" :
17- self .kbd .send (Keycode .ONE )
18-
19- if state_map [detector .state ]["name" ] == "STARTED" :
20- self .kbd .send (Keycode .TWO )
21-
22- if state_map [detector .state ]["name" ] == "DETECTED" :
23- self .kbd .send (Keycode .SIX )
25+ detector .run ()
0 commit comments