Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions CircuitPython_Sip_and_Puff/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions CircuitPython_Sip_and_Puff/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

detector = puff_detector.PuffDetector()


@detector.on_sip
def on_sip(strength, duration):
if strength == puff_detector.STRONG:
Expand Down
15 changes: 8 additions & 7 deletions CircuitPython_Sip_and_Puff/puff_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@
input_type_string = " "
# pylint:disable=too-many-locals,exec-used,eval-used


class PuffDetector:
def __init__(
self,
min_pressure=MIN_PRESSURE,
high_pressure=HIGH_PRESSURE,
config_filename="settings.json",
display_timeout=1,
self,
min_pressure=MIN_PRESSURE,
high_pressure=HIGH_PRESSURE,
config_filename="settings.json",
display_timeout=1,
):
# misc detection state
self.current_pressure = 0
Expand Down Expand Up @@ -104,7 +105,6 @@ def _init_stuff(self):
self.pressure_sensor.filter_enabled = True
self.pressure_sensor.filter_config = True


def _load_config(self):
if not self._config_filename in os.listdir("/"):
return
Expand Down Expand Up @@ -245,6 +245,7 @@ def _update_display_strings(self):

if self.start_polarity == 1:
self.state_str = "PUFF STARTED..."

def _update_display(self):
self._update_display_strings()
banner = label.Label(FONT, text=BANNER_STRING, color=COLOR)
Expand Down Expand Up @@ -276,7 +277,7 @@ def _update_display(self):
high_pressure_label.x = 0
high_pressure_label.y = BOTTOM_ROW

splash = Group(max_size=10)
splash = Group()
splash.append(banner)
splash.append(state)
splash.append(detector_result)
Expand Down
3 changes: 3 additions & 0 deletions CircuitPython_Sip_and_Puff/serial_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

detector = puff_detector.PuffDetector()


@detector.on_sip
def on_sip(strength, duration):
if strength == puff_detector.STRONG:
Expand All @@ -11,6 +12,7 @@ def on_sip(strength, duration):
log_str = "DETECTED::SIP:%s::DURATION:%0.3f" % (strength_str, duration)
print(log_str)


@detector.on_puff
def on_puff(strength, duration):
if strength == puff_detector.STRONG:
Expand All @@ -20,4 +22,5 @@ def on_puff(strength, duration):
log_str = "DETECTED::PUFF:%s::DURATION:%0.3f" % (strength_str, duration)
print(log_str)


detector.run()
7 changes: 5 additions & 2 deletions CircuitPython_Sip_and_Puff/simple_hid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@

detector = puff_detector.PuffDetector()


@detector.on_sip
def on_sip(strength, duration):#pylint:disable=unused-argument
def on_sip(strength, duration): # pylint:disable=unused-argument
if strength == puff_detector.STRONG:
kbd.send(Keycode.LEFT_ARROW)
kbd.send(Keycode.LEFT_ARROW)
if strength == puff_detector.SOFT:
kbd.send(Keycode.LEFT_ARROW)


@detector.on_puff
def on_puff(strength, duration):#pylint:disable=unused-argument
def on_puff(strength, duration): # pylint:disable=unused-argument
if strength == puff_detector.STRONG:
kbd.send(Keycode.RIGHT_ARROW)
kbd.send(Keycode.RIGHT_ARROW)
if strength == puff_detector.SOFT:
kbd.send(Keycode.RIGHT_ARROW)


detector.run()