summaryrefslogtreecommitdiff
path: root/wasp
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-04-18 14:34:49 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-04-26 14:01:48 (GMT)
commit9348e758b20a84502baabe46e400dee1811fdd4c (patch)
treeb2b87804396b8fa2749842847f525d49b23dab7c /wasp
parent5b277e94f11474e3c34f943ee63b9155e96777e2 (diff)
wasp: nrf_rtc: Add a tiny bit of extra resolution
We now have a couple of applications (stopwatch, Game of Life) that benefit from sub-second precision. The micropython RTC/utime code for nrf still needs a major overhaul but this allows us to paper over the cracks for just a little longer.
Diffstat (limited to 'wasp')
-rw-r--r--wasp/apps/gameoflife.py2
-rw-r--r--wasp/drivers/nrf_rtc.py21
2 files changed, 14 insertions, 9 deletions
diff --git a/wasp/apps/gameoflife.py b/wasp/apps/gameoflife.py
index 95883c6..080c214 100644
--- a/wasp/apps/gameoflife.py
+++ b/wasp/apps/gameoflife.py
@@ -163,7 +163,7 @@ class GameOfLifeApp():
"""Activate the application."""
self._draw()
wasp.system.request_event(wasp.EventMask.TOUCH)
- wasp.system.request_tick(1000)
+ wasp.system.request_tick(625)
def tick(self, ticks):
"""Notify the application that its periodic tick is due."""
diff --git a/wasp/drivers/nrf_rtc.py b/wasp/drivers/nrf_rtc.py
index 497c3d6..7cbe065 100644
--- a/wasp/drivers/nrf_rtc.py
+++ b/wasp/drivers/nrf_rtc.py
@@ -20,8 +20,8 @@ class RTC(object):
def __init__(self, counter):
self.counter = counter
- self.uptime = 0
- self.set_localtime((2020, 2, 18, 12, 0, 0, 0, 0))
+ self._uptime = 0
+ self.set_localtime((2020, 3, 1, 3, 0, 0, 0, 0))
def update(self):
newcount = self.counter.counter()
@@ -30,11 +30,11 @@ class RTC(object):
return False
if split < 0:
split += (1 << 24)
- elapsed = split // 8
- self.lastcount += elapsed * 8
+
+ self.lastcount += split
self.lastcount &= (1 << 24) - 1
+ self._uptime += split
- self.uptime += elapsed
return True
def set_localtime(self, t):
@@ -51,16 +51,21 @@ class RTC(object):
t = (yyyy, mm, dd, HH, MM, SS, 0, 0)
lt = time.mktime(t)
- self.offset = lt - self.uptime
+ self.offset = lt - self._uptime
def get_localtime(self):
self.update()
- return time.localtime(self.offset + self.uptime)
+ return time.localtime(self.offset + (self._uptime >> 3))
def get_time(self):
localtime = self.get_localtime()
return localtime[3:6]
+ @property
+ def uptime(self):
+ """Provide the current uptime in seconds."""
+ return self._uptime // 8
+
def get_uptime_ms(self):
"""Return the current uptime in milliseconds."""
- return self.uptime * 1000
+ return self._uptime * 125