Skip to content

Commit a2033cf

Browse files
committed
updated simple hid example
1 parent 89d2f03 commit a2033cf

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
from adafruit_hid.keyboard import Keyboard
22
from adafruit_hid.keycode import Keycode
3+
import puff_detector
34

5+
kbd = Keyboard()
46

5-
def log(message):
6-
print("\t\tHIDDEMO::%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

Comments
 (0)