1
1
from adafruit_hid .keyboard import Keyboard
2
2
from adafruit_hid .keycode import Keycode
3
+ import puff_detector
3
4
5
+ kbd = Keyboard ()
4
6
5
- def log (message ):
6
- print ("\t \t HIDDEMO::%s" % message )
7
+ detector = puff_detector .PuffDetector ()
7
8
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 )
8
16
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 )
13
24
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