2020-02-03 20:24:09 +01:00
|
|
|
import clock
|
|
|
|
import gc
|
|
|
|
import machine
|
|
|
|
|
|
|
|
class Manager(object):
|
|
|
|
def __init__(self, watch):
|
|
|
|
self.watch = watch
|
|
|
|
self.switch(clock.ClockApp())
|
|
|
|
self.sleep_at = watch.rtc.uptime + 90
|
2020-02-04 09:49:10 +01:00
|
|
|
self.charging = True
|
2020-02-03 20:24:09 +01:00
|
|
|
|
|
|
|
def switch(self, app):
|
|
|
|
self.app = app
|
|
|
|
app.draw(self.watch)
|
|
|
|
|
|
|
|
def tick(self):
|
|
|
|
if self.sleep_at:
|
|
|
|
if self.watch.rtc.update():
|
|
|
|
self.app.update(self.watch)
|
|
|
|
|
|
|
|
if self.watch.button.value():
|
|
|
|
self.sleep_at = self.watch.rtc.uptime + 15
|
|
|
|
|
|
|
|
if self.watch.rtc.uptime > self.sleep_at:
|
|
|
|
self.watch.backlight.set(0)
|
|
|
|
self.watch.display.poweroff()
|
2020-02-04 09:49:10 +01:00
|
|
|
self.charging = self.watch.battery.charging()
|
2020-02-03 20:24:09 +01:00
|
|
|
self.sleep_at = None
|
2020-02-03 23:45:12 +01:00
|
|
|
|
|
|
|
gc.collect()
|
2020-02-03 20:24:09 +01:00
|
|
|
else:
|
|
|
|
self.watch.rtc.update()
|
|
|
|
|
2020-02-04 09:49:10 +01:00
|
|
|
charging = self.watch.battery.charging()
|
|
|
|
if self.watch.button.value() or self.charging != charging:
|
2020-02-03 20:24:09 +01:00
|
|
|
self.watch.display.poweron()
|
|
|
|
self.app.update(self.watch)
|
|
|
|
self.watch.backlight.set(2)
|
|
|
|
|
|
|
|
self.sleep_at = self.watch.rtc.uptime + 15
|
|
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
while True:
|
|
|
|
self.tick()
|
|
|
|
machine.deepsleep()
|