wasp: Add full dd-mm-yyyy calender tracking

This commit is contained in:
Daniel Thompson 2020-02-19 19:32:06 +00:00
parent c9ab38d757
commit f689c90498
5 changed files with 30 additions and 25 deletions

View file

@ -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

@ -1 +1 @@
Subproject commit a982035fdfd2dc12d375446472f0a2b1a99dd386
Subproject commit 2e5cb3eb32bcd4d72a328697db5442a9950969c0

View file

@ -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):

View file

@ -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])

View file

@ -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]