You've already forked TEF6686_Driver
store rtc time offset
This commit is contained in:
15
rtc.py
15
rtc.py
@@ -2,10 +2,16 @@ import datetime
|
||||
from protocol import I2CPCClient
|
||||
|
||||
def sync_rtc(p: I2CPCClient):
|
||||
TIMEOFFSET_ADDR = 2275
|
||||
dtime = datetime.datetime.now(datetime.UTC)
|
||||
|
||||
utc_off = d.total_seconds() / 3600 if (d := datetime.datetime.now().astimezone().utcoffset()) else 0
|
||||
if(p.version()[-1] >= 2): p.write_eeprom(TIMEOFFSET_ADDR, int(utc_off).to_bytes(1, signed=True))
|
||||
else: dtime = datetime.datetime.now()
|
||||
|
||||
ADDRESS = 0x32
|
||||
p.write_i2c(ADDRESS, b"\x1f\x40") # halt the clock
|
||||
|
||||
dtime = datetime.datetime.now()
|
||||
def toBCD(val: int) -> int:
|
||||
return ((val // 10) << 4) | (val % 10)
|
||||
data = b"\x10"
|
||||
@@ -18,4 +24,9 @@ def sync_rtc(p: I2CPCClient):
|
||||
data += toBCD((1900 + dtime.year - 26) % 100).to_bytes(1)
|
||||
p.write_i2c(ADDRESS, data)
|
||||
|
||||
p.write_i2c(ADDRESS, b"\x1f\x00") # start the clock
|
||||
p.write_i2c(ADDRESS, b"\x1f\x00") # start the clock
|
||||
|
||||
p = I2CPCClient("COM17")
|
||||
sync_rtc(p)
|
||||
p.reboot()
|
||||
p.close()
|
||||
Reference in New Issue
Block a user