summaryrefslogtreecommitdiff
path: root/wasp
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-02-03 22:29:57 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-02-03 22:29:57 (GMT)
commitb124a747dd6097a7ca6f111da46067b7d86abe5b (patch)
tree25672ff283d909b3e60d0a5f4997204ab2ff8c07 /wasp
parent3892f07e62fcbbac128401f183bec66361f08db1 (diff)
wasp: simulator: Add battery level simulation
In order to get best test coverage the act of reading the battery results in the battery either charging or discharging.
Diffstat (limited to 'wasp')
-rw-r--r--wasp/boards/simulator/watch.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/wasp/boards/simulator/watch.py b/wasp/boards/simulator/watch.py
index e25d03c..75bd232 100644
--- a/wasp/boards/simulator/watch.py
+++ b/wasp/boards/simulator/watch.py
@@ -29,6 +29,40 @@ class Display(ST7789_SPI):
super().__init__(240, 240, spi, cs=cs, dc=dc, res=rst)
+class Battery(object):
+ def __init__(self):
+ self.voltage = 3.9
+ self.step = -0.01
+ self.powered = False
+
+ def charging(self):
+ self.voltage_mv()
+ return self.powered
+
+ def power(self):
+ self.voltage_mv()
+ return self.powered
+
+ def voltage_mv(self):
+ if self.voltage > 4:
+ self.step = -0.005
+ self.powered = False
+ elif self.voltage < 3.4:
+ self.step = 0.01
+ self.powered = True
+ self.voltage += self.step
+
+ return int(self.voltage * 1000)
+
+ def level(self):
+ mv = self.voltage_mv()
+ level = ((19 * mv) // 100) - 660
+ if level > 100:
+ return 100
+ if level < 0:
+ return 0
+ return level
+
class RTC(object):
def __init__(self):
self.uptime = 0
@@ -49,6 +83,7 @@ class RTC(object):
display = Display()
backlight = Backlight()
+battery = Battery()
rtc = RTC()
vibrator = Vibrator(Pin('MOTOR', Pin.OUT, value=0), active_low=True)
button = Pin('BUTTON', Pin.IN, quiet=True)