|
@@ -18,7 +18,7 @@ _SCREEN_WIDTH, _SCREEN_HEIGHT = lcd.winsize()
|
|
|
|
|
|
|
|
|
class App:
|
|
|
- # pylint: disable=too-few-public-methods
|
|
|
+ # pylint: disable=too-few-public-methods,too-many-instance-attributes
|
|
|
def __init__(self) -> None:
|
|
|
self._rtc = None
|
|
|
self._clock_text_box = None
|
|
@@ -27,6 +27,7 @@ class App:
|
|
|
self._alarm_minute = None
|
|
|
self._alarm_hour_text_box = None
|
|
|
self._alarm_minute_text_box = None
|
|
|
+ self._alarm_timer = None
|
|
|
|
|
|
def _load_alarm_time(self) -> None:
|
|
|
with open(_ALARM_TIME_PATH, "r") as alarm_time_file:
|
|
@@ -59,6 +60,27 @@ class App:
|
|
|
# https://docs.micropython.org/en/latest/library/micropython.html#micropython.schedule
|
|
|
micropython.schedule(self._update_menu, None)
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def _alert() -> None:
|
|
|
+ print("ALARM")
|
|
|
+
|
|
|
+ def _alarm(self, timer: machine.Timer) -> None:
|
|
|
+ # pylint: disable=unused-argument; callback
|
|
|
+ micropython.schedule(lambda n: self._alert(), None)
|
|
|
+ micropython.schedule(lambda n: self._configure_alarm_timer(), None)
|
|
|
+
|
|
|
+ def _configure_alarm_timer(self) -> None:
|
|
|
+ now_hour, now_minute = self._rtc.datetime()[4:6] # type: ignore
|
|
|
+ minutes_until_alarm = (
|
|
|
+ (self._alarm_hour - now_hour) * 60 + self._alarm_minute - now_minute - 1
|
|
|
+ ) % (24 * 60) + 1
|
|
|
+ print("alarm in ", minutes_until_alarm, " min")
|
|
|
+ self._alarm_timer.init( # type: ignore
|
|
|
+ period=minutes_until_alarm * 60 * 1000, # ms
|
|
|
+ mode=machine.Timer.ONE_SHOT,
|
|
|
+ callback=self._alarm,
|
|
|
+ )
|
|
|
+
|
|
|
def _update_alarm_time(self, event_arg: None) -> None:
|
|
|
# pylint: disable=unused-argument; callback
|
|
|
self._alarm_hour_text_box.setText( # type: ignore
|
|
@@ -68,6 +90,7 @@ class App:
|
|
|
"{:02d}".format(self._alarm_minute) # type: ignore
|
|
|
)
|
|
|
self._save_alarm_time()
|
|
|
+ self._configure_alarm_timer()
|
|
|
|
|
|
def _button_b_pressed(self) -> None:
|
|
|
if self._menu_position == 1:
|
|
@@ -130,6 +153,9 @@ class App:
|
|
|
_DEFAULT_FONT_COLOR,
|
|
|
rotate=90,
|
|
|
)
|
|
|
+ # machine.Timer(1).init(...) breaks button handling
|
|
|
+ self._alarm_timer = machine.Timer(2)
|
|
|
+ self._configure_alarm_timer()
|
|
|
|
|
|
def run(self) -> None:
|
|
|
m5ui.setScreenColor(0x000000) # clear screen
|