-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
74 lines (53 loc) · 2.04 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import time
from datetime import datetime
from itertools import cycle
from lib import epd2in13
from modules.calendar import Calendar
from modules.watches import Watches
class Application:
STATE_INIT_FULL_UPDATE = 1
STATE_INIT_PART_UPDATE = 2
STATE_SWITCH_SCREEN_INIT = 3
STATE_SWITCH_SCREEN_UPDATE = 4
def __init__(self, modules):
assert len(modules) > 0
self.epd = epd2in13.EPD()
self.modules = cycle(map(lambda m: (m[0], m[1]((self.epd.height, self.epd.width))), modules))
self.state = self.STATE_INIT_FULL_UPDATE
self.last_switch = datetime.min
self.active_module = None
def __del__(self):
self.epd.sleep()
def get_image(self):
return self.epd.getbuffer(self.active_module[1].image)
def loop(self):
self.epd.init(self.epd.FULL_UPDATE)
self.epd.Clear(255)
while True:
t = datetime.now()
if self.active_module is None or (t - self.last_switch).seconds >= self.active_module[0]:
self.active_module = next(self.modules)
self.last_switch = t
self.state = self.STATE_INIT_FULL_UPDATE
self.active_module[1].redraw()
if self.state == self.STATE_INIT_FULL_UPDATE:
self.epd.init(self.epd.FULL_UPDATE)
self.state = self.STATE_SWITCH_SCREEN_INIT
if self.state == self.STATE_INIT_PART_UPDATE:
self.epd.init(self.epd.PART_UPDATE)
self.state = self.STATE_SWITCH_SCREEN_UPDATE
if self.state == self.STATE_SWITCH_SCREEN_INIT:
self.epd.displayPartBaseImage(self.get_image())
self.state = self.STATE_INIT_PART_UPDATE
if self.state == self.STATE_SWITCH_SCREEN_UPDATE:
self.epd.displayPartial(self.get_image())
time.sleep(5)
if __name__ == '__main__':
app = Application([
(120, Watches),
(30, Calendar),
])
try:
app.loop()
except KeyboardInterrupt:
del app