Skip to content

Commit

Permalink
A fix for RTC (getting stuck)
Browse files Browse the repository at this point in the history
Adds 'month_name()' function to RTC
  • Loading branch information
Alan Christie committed Feb 27, 2022
1 parent 010ddee commit 475fab3
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions pico/rtc.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 475fab3

Please sign in to comment.