Skip to content

Commit a2f5837

Browse files
Set RTC clock if present
1 parent eb2abe4 commit a2f5837

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Frameworks:
1212

1313
OS:
1414
- LilyGo T-Watch S3 Plus: enable audio input (PDM microphone) and output (I2S speaker)
15-
- LilyGo T-Watch S3 Plus: get time from battery-powered Real Time Clock at startup
15+
- LilyGo T-Watch S3 Plus: enable battery-powered Real Time Clock to keep time
1616
- LilyGo T-Watch S3 Plus: add IMU accelerometer support so IMU app works
1717

1818

internal_filesystem/lib/mpos/board/lilygo_t_watch_s3_plus.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ def _handle_pmu_irq(_pin):
228228
rtc_tuple = (dt[0], dt[1], dt[2], dt[3], dt[4], dt[5], dt[6], 0)
229229
from machine import RTC
230230
RTC().datetime(rtc_tuple)
231+
from mpos import TimeZone
232+
TimeZone.rtc = rtc
231233
# Would be good to also do this:
232234
# rtc.setClockOutput(SensorPCF8563::CLK_DISABLE); //Disable clock output to conserve backup battery power
233235

internal_filesystem/lib/mpos/time.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ def sync_time():
2020
print('Syncing time with', ntptime.host)
2121
ntptime.settime() # Fetch and set time (in UTC)
2222
print("Time sync'ed successfully")
23+
if hasattr(TimeZone, "rtc"):
24+
print("Real Time Clock (RTC) found, setting it")
25+
try: # RTC driver might throw an exception
26+
import time
27+
TimeZone.rtc.datetime(time.localtime())
28+
except Exception as e:
29+
print(f"Exception while setting RTC time: {e}")
2330
TimeZone.refresh_timezone_preference() # if the time was sync'ed, then it needs refreshing
2431
except Exception as e:
2532
print('Failed to sync time:', e)

0 commit comments

Comments
 (0)