Prechádzať zdrojové kódy

migrate from machine.RTC to m5stack.rtc (to actually persist time)

Fabian Peter Hammerle 3 rokov pred
rodič
commit
546632ed89
1 zmenil súbory, kde vykonal 3 pridanie a 4 odobranie
  1. 3 4
      vibrating_alarm_m5stickc.py

+ 3 - 4
vibrating_alarm_m5stickc.py

@@ -9,7 +9,7 @@ import m5ui
 import machine
 import micropython
 import utils
-from m5stack import axp, btnA, btnB, lcd
+from m5stack import axp, btnA, btnB, lcd, rtc
 
 _FONT = lcd.FONT_DejaVu40
 _DEFAULT_FONT_COLOR = lcd.WHITE
@@ -20,7 +20,6 @@ _SCREEN_WIDTH, _SCREEN_HEIGHT = lcd.winsize()
 class App:
     # pylint: disable=too-few-public-methods,too-many-instance-attributes
     def __init__(self) -> None:
-        self._rtc = machine.RTC()
         self._clock_text_box = None
         self._menu_position = 0
         self._alarm_hour = None
@@ -34,7 +33,7 @@ class App:
         # > [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 = self._rtc.datetime()[4:7]
+        hour, minute, seconds = rtc.now()[3:]
         return (hour * 60 + minute) * 60 + seconds
 
     @property
@@ -117,7 +116,7 @@ class App:
         micropython.schedule(self._update_alarm_time, None)
 
     def _format_time(self) -> str:
-        return "{:02d}:{:02d}".format(*self._rtc.datetime()[4:6])
+        return "{:02d}:{:02d}".format(*rtc.now()[3:5])
 
     def _setup_clock(self) -> None:
         # https://github.com/m5stack/UIFlow-Code/wiki/M5UI#textbox