diff --git a/CircuitPython_Sip_and_Puff/.gitignore b/CircuitPython_Sip_and_Puff/.gitignore deleted file mode 100644 index 60bf81951..000000000 --- a/CircuitPython_Sip_and_Puff/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.pylintrc -__pycache__/* diff --git a/CircuitPython_Sip_and_Puff/code.py b/CircuitPython_Sip_and_Puff/code.py index df1ffec89..c8a8ce93d 100644 --- a/CircuitPython_Sip_and_Puff/code.py +++ b/CircuitPython_Sip_and_Puff/code.py @@ -2,6 +2,7 @@ detector = puff_detector.PuffDetector() + @detector.on_sip def on_sip(strength, duration): if strength == puff_detector.STRONG: diff --git a/CircuitPython_Sip_and_Puff/puff_detector.py b/CircuitPython_Sip_and_Puff/puff_detector.py index 5ab89463c..05ec98748 100644 --- a/CircuitPython_Sip_and_Puff/puff_detector.py +++ b/CircuitPython_Sip_and_Puff/puff_detector.py @@ -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 @@ -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 @@ -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) @@ -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) diff --git a/CircuitPython_Sip_and_Puff/serial_logger.py b/CircuitPython_Sip_and_Puff/serial_logger.py index b5ca86ebd..69ba477cb 100644 --- a/CircuitPython_Sip_and_Puff/serial_logger.py +++ b/CircuitPython_Sip_and_Puff/serial_logger.py @@ -2,6 +2,7 @@ detector = puff_detector.PuffDetector() + @detector.on_sip def on_sip(strength, duration): if strength == puff_detector.STRONG: @@ -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: @@ -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() diff --git a/CircuitPython_Sip_and_Puff/simple_hid.py b/CircuitPython_Sip_and_Puff/simple_hid.py index 29b30f189..f13562035 100644 --- a/CircuitPython_Sip_and_Puff/simple_hid.py +++ b/CircuitPython_Sip_and_Puff/simple_hid.py @@ -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()