diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-02-19 19:32:06 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-02-19 19:57:08 (GMT) |
| commit | f689c90498b58a5198bb56a2d3d5211db9670283 (patch) | |
| tree | d5b319751bd62e0e0de74c83b7323e624f5291d3 | |
| parent | c9ab38d75722027ee63c0626dde873045afbfc0b (diff) | |
wasp: Add full dd-mm-yyyy calender tracking
| -rw-r--r-- | TODO.md | 1 | ||||
| m--------- | micropython | 0 | ||||
| -rwxr-xr-x | tools/wasptool | 2 | ||||
| -rw-r--r-- | wasp/boards/simulator/watch.py | 3 | ||||
| -rw-r--r-- | wasp/drivers/nrf_rtc.py | 45 |
5 files changed, 28 insertions, 23 deletions
@@ -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 -Subproject a982035fdfd2dc12d375446472f0a2b1a99dd38 +Subproject 2e5cb3eb32bcd4d72a328697db5442a9950969c 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 + return True - self.ss += elapsed - if self.ss >= 60: - self.mm += self.ss // 60 - self.ss %= 60 + def set_localtime(self, t): + self.lastcount = self.counter.counter() - if self.mm >= 60: - self.hh += self.mm // 60 - self.mm %= 60 - self.hh %= 24 + if len(t) < 8: + yyyy = t[0] + mm = t[1] + dd = t[2] + HH = t[3] + MM = t[4] + SS = t[5] - return True + t = (yyyy, mm, dd, HH, MM, SS, 0, 0) - def set_time(self, t): - self.lastcount = self.counter.counter() - self.hh = t[0] - self.mm = t[1] - self.ss = t[2] + lt = time.mktime(t) + self.offset = lt - self.uptime - def get_time(self): + def get_localtime(self): self.update() - return (self.hh, self.mm, self.ss) + return time.localtime(self.offset + self.uptime) + + def get_time(self): + localtime = self.get_localtime() + return localtime[3:6] |
