Explorar el Código

continue vibration until button is pressed

Fabian Peter Hammerle hace 2 años
padre
commit
f17869f17e
Se han modificado 1 ficheros con 8 adiciones y 2 borrados
  1. 8 2
      vibrating_alarm_m5stickc.py

+ 8 - 2
vibrating_alarm_m5stickc.py

@@ -106,6 +106,7 @@ class App:
         self._alarm_hour_text_box = None
         self._alarm_minute_text_box = None
         self._battery_status_text_box = None
+        self._alarm_active = False
         self._vibration_motor_pin = None
 
     def _reschedule_sleep(self, interrupt: bool) -> None:
@@ -131,13 +132,18 @@ class App:
 
     def _button_a_pressed(self) -> None:
         self._reschedule_sleep(interrupt=True)
-        self._menu_position = (self._menu_position + 1) % 5
+        if self._alarm_active:
+            print("alarm stopped")
+            self._alarm_active = False
+        else:
+            self._menu_position = (self._menu_position + 1) % 5
         # https://docs.micropython.org/en/latest/library/micropython.html#micropython.schedule
         micropython.schedule(self._update_menu, None)
 
     def _alarm(self) -> None:
         print("ALARM")
-        for _ in range(3):
+        self._alarm_active = True
+        while self._alarm_active:
             self._vibration_motor_pin.on()  # type: ignore
             utime.sleep(0.5)
             self._vibration_motor_pin.off()  # type: ignore