From 475fab30b11cb466fcdf678db7d4ded22876bbd3 Mon Sep 17 00:00:00 2001 From: Alan Christie Date: Sun, 27 Feb 2022 11:19:54 +0000 Subject: [PATCH] A fix for RTC (getting stuck) Adds 'month_name()' function to RTC --- pico/rtc.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/pico/rtc.py b/pico/rtc.py index 1df8e2f..48d5a0f 100644 --- a/pico/rtc.py +++ b/pico/rtc.py @@ -1,4 +1,4 @@ -"""A simplified real-time clock. +"""A simplified micropython-style real-time clock. A wrapper around the RV3028 I2C module. """ import time @@ -19,6 +19,21 @@ ('year', 'month', 'dom', 'dow', 'h', 'm', 's')) +# Short text representation of the month +# (1-based, i.e. Jan == 1) +_MONTH_NAME = ["---", + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] + + +def month_name(month: int) -> str: + """Returns the short name of the Month. + """ + assert 0 < month <= 12 + + return _MONTH_NAME[month] + + class RTC: """A wrapper around the Pimoroni BreakoutRTC class, a driver for the RV3028 RTC I2C breakout module. @@ -30,8 +45,8 @@ def __init__(self, sda: int, scl: int): # Create an object from the expected (built-in) Pimoroni library # that gives us access to the RV3028 RTC. We use this # to set the value after editing. - pimoroni_i2c: PimoroniI2C = PimoroniI2C(sda=sda, scl=scl) - self._rtc: BreakoutRTC = BreakoutRTC(pimoroni_i2c) + self._pimoroni_i2c: PimoroniI2C = PimoroniI2C(sda=sda, scl=scl) + self._rtc: BreakoutRTC = BreakoutRTC(self._pimoroni_i2c) # Setting backup switchover mode to '3' # means the device will switch to battery # when the power supply drops out.