diff --git a/TODO.md b/TODO.md index 6e8b2d7..ee35e74 100644 --- a/TODO.md +++ b/TODO.md @@ -58,6 +58,7 @@ applications. ## WASP + * [X] Add dd/mm/yyyy support to RTC * [ ] Button driver (interrupt based) * [ ] Touch sensor driver * [ ] Event driven application framework diff --git a/micropython b/micropython index a982035..2e5cb3e 160000 --- a/micropython +++ b/micropython @@ -1 +1 @@ -Subproject commit a982035fdfd2dc12d375446472f0a2b1a99dd386 +Subproject commit 2e5cb3eb32bcd4d72a328697db5442a9950969c0 diff --git a/tools/wasptool b/tools/wasptool index 635cb07..a6faf38 100755 --- a/tools/wasptool +++ b/tools/wasptool @@ -77,7 +77,7 @@ def handle_rtc(c): now = time.localtime() # Set the time - c.sendline(f'watch.rtc.set_time(({now[3]}, {now[4]}, {now[5]}))') + c.sendline(f'watch.rtc.set_localtime(({now[0]}, {now[1]}, {now[2]}, {now[3]}, {now[4]}, {now[5]}, {now[6]}, {now[7]}))') c.expect('>>> ') def handle_upload(c, fname): diff --git a/wasp/boards/simulator/watch.py b/wasp/boards/simulator/watch.py index 75bd232..6e7fcee 100644 --- a/wasp/boards/simulator/watch.py +++ b/wasp/boards/simulator/watch.py @@ -74,6 +74,9 @@ class RTC(object): self.uptime = now return True + def get_localtime(self): + return time.localtime() + def get_time(self): now = time.localtime() return (now[3], now[4], now[5]) diff --git a/wasp/drivers/nrf_rtc.py b/wasp/drivers/nrf_rtc.py index c130a76..54c58f1 100644 --- a/wasp/drivers/nrf_rtc.py +++ b/wasp/drivers/nrf_rtc.py @@ -1,5 +1,7 @@ """ Real Time Clock based on the nRF-family low power counter """ +import time + #class Stim(object): # def __init__(self): # self(0) @@ -11,16 +13,12 @@ # return self.c class RTC(object): - """Real Time Clock based on the nRF-family low power counter. - - TODO: Maintain hh:mm:ss as an array so we can report time - without memory allocation. - """ + """Real Time Clock based on the nRF-family low power counter.""" def __init__(self, counter): self.counter = counter self.uptime = 0 - self.set_time((12, 0, 0)) + self.set_localtime((2020, 2, 18, 12, 0, 0, 0, 0)) def update(self): newcount = self.counter.counter() @@ -34,25 +32,28 @@ class RTC(object): self.lastcount &= (1 << 24) - 1 self.uptime += elapsed - - self.ss += elapsed - if self.ss >= 60: - self.mm += self.ss // 60 - self.ss %= 60 - - if self.mm >= 60: - self.hh += self.mm // 60 - self.mm %= 60 - self.hh %= 24 - return True - def set_time(self, t): + def set_localtime(self, t): self.lastcount = self.counter.counter() - self.hh = t[0] - self.mm = t[1] - self.ss = t[2] + + if len(t) < 8: + yyyy = t[0] + mm = t[1] + dd = t[2] + HH = t[3] + MM = t[4] + SS = t[5] + + t = (yyyy, mm, dd, HH, MM, SS, 0, 0) + + lt = time.mktime(t) + self.offset = lt - self.uptime + + def get_localtime(self): + self.update() + return time.localtime(self.offset + self.uptime) def get_time(self): - self.update() - return (self.hh, self.mm, self.ss) + localtime = self.get_localtime() + return localtime[3:6]