summaryrefslogtreecommitdiff
path: root/wasp/drivers
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-02-19 19:32:06 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-02-19 19:57:08 (GMT)
commitf689c90498b58a5198bb56a2d3d5211db9670283 (patch)
treed5b319751bd62e0e0de74c83b7323e624f5291d3 /wasp/drivers
parentc9ab38d75722027ee63c0626dde873045afbfc0b (diff)
wasp: Add full dd-mm-yyyy calender tracking
Diffstat (limited to 'wasp/drivers')
-rw-r--r--wasp/drivers/nrf_rtc.py45
1 files changed, 23 insertions, 22 deletions
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]