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.
This commit is contained in:
parent
3892f07e62
commit
b124a747dd
1 changed files with 35 additions and 0 deletions
|
@ -29,6 +29,40 @@ class Display(ST7789_SPI):
|
||||||
|
|
||||||
super().__init__(240, 240, spi, cs=cs, dc=dc, res=rst)
|
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):
|
class RTC(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.uptime = 0
|
self.uptime = 0
|
||||||
|
@ -49,6 +83,7 @@ class RTC(object):
|
||||||
|
|
||||||
display = Display()
|
display = Display()
|
||||||
backlight = Backlight()
|
backlight = Backlight()
|
||||||
|
battery = Battery()
|
||||||
rtc = RTC()
|
rtc = RTC()
|
||||||
vibrator = Vibrator(Pin('MOTOR', Pin.OUT, value=0), active_low=True)
|
vibrator = Vibrator(Pin('MOTOR', Pin.OUT, value=0), active_low=True)
|
||||||
button = Pin('BUTTON', Pin.IN, quiet=True)
|
button = Pin('BUTTON', Pin.IN, quiet=True)
|
||||||
|
|
Loading…
Reference in a new issue