|
@@ -31,6 +31,14 @@ def _handle_pending_events():
|
|
utime.sleep_ms(11)
|
|
utime.sleep_ms(11)
|
|
|
|
|
|
|
|
|
|
|
|
+def _get_current_daytime() -> int:
|
|
|
|
+ # > [contradictory to] official micropython documentation, to set RTC,
|
|
|
|
+ # > use particular tuple (year , month, day, week=0, hour, minute, second, timestamp=0)
|
|
|
|
+ # https://community.m5stack.com/topic/3108/m5stack-core2-micropython-rtc-example
|
|
|
|
+ hour, minute, seconds = rtc.now()[3:]
|
|
|
|
+ return (hour * 60 + minute) * 60 + seconds
|
|
|
|
+
|
|
|
|
+
|
|
class App:
|
|
class App:
|
|
# pylint: disable=too-few-public-methods,too-many-instance-attributes
|
|
# pylint: disable=too-few-public-methods,too-many-instance-attributes
|
|
def __init__(self) -> None:
|
|
def __init__(self) -> None:
|
|
@@ -45,14 +53,6 @@ class App:
|
|
self._alarm_timer = None
|
|
self._alarm_timer = None
|
|
self._battery_status_text_box = None
|
|
self._battery_status_text_box = None
|
|
|
|
|
|
- @property
|
|
|
|
- def _now_daytime(self) -> int:
|
|
|
|
- # > [contradictory to] official micropython documentation, to set RTC,
|
|
|
|
- # > use particular tuple (year , month, day, week=0, hour, minute, second, timestamp=0)
|
|
|
|
- # https://community.m5stack.com/topic/3108/m5stack-core2-micropython-rtc-example
|
|
|
|
- hour, minute, seconds = rtc.now()[3:]
|
|
|
|
- return (hour * 60 + minute) * 60 + seconds
|
|
|
|
-
|
|
|
|
@property
|
|
@property
|
|
def _alarm_daytime(self) -> int:
|
|
def _alarm_daytime(self) -> int:
|
|
return (self._alarm_hour * 60 + self._alarm_minute) * 60 # type: ignore
|
|
return (self._alarm_hour * 60 + self._alarm_minute) * 60 # type: ignore
|
|
@@ -107,7 +107,7 @@ class App:
|
|
micropython.schedule(lambda n: self._configure_alarm_timer(), None)
|
|
micropython.schedule(lambda n: self._configure_alarm_timer(), None)
|
|
|
|
|
|
def _configure_alarm_timer(self) -> None:
|
|
def _configure_alarm_timer(self) -> None:
|
|
- seconds_until_alarm = (self._alarm_daytime - self._now_daytime - 1) % (
|
|
|
|
|
|
+ seconds_until_alarm = (self._alarm_daytime - _get_current_daytime() - 1) % (
|
|
24 * 60 * 60
|
|
24 * 60 * 60
|
|
) + 1
|
|
) + 1
|
|
print("alarm in ", seconds_until_alarm / 60, " min")
|
|
print("alarm in ", seconds_until_alarm / 60, " min")
|