-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdisplayScreen.py
63 lines (51 loc) · 1.77 KB
/
displayScreen.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
#!/user/bin/env python3
# -*- coding:utf-8 -*-
from __future__ import unicode_literals
from luma.core.render import canvas
import time
import RPi.GPIO as GPIO # noqa: N814
import logging
import config
import setup
import statusbar
# link back to SetupClass for readability
device = setup.SetupClass.device
def draw_list(draw, text):
edge_left = 0
y_pos = 10
spacing = 10
for line in text:
draw.text((edge_left, y_pos),
text=line,
font=config.TEXT_FONT,
fill=config.FG)
y_pos += spacing
# main entry point for this class, generally from menuClass.startMenu()
def display(text, wait=True):
logging.debug("ENTERING DISPLAY SCREEN")
time.sleep(0.2) # prevent instant selection from new menu
status = statusbar.init()
alarm_clock = 0
while 1:
if (time.time() > alarm_clock):
alarm_clock = time.time() + config.STATUS_FREQUENCY
status = statusbar.get_status(status)
# handle keypresses
# user hits cancel
if (GPIO.input(config.KEY_CANCEL_PIN) == False): # noqa: E712
return None
if (GPIO.input(config.KEY_UP_PIN) == False): # noqa: E712
return None
if (GPIO.input(config.KEY_SELECT_PIN) == False): # noqa: E712
return None
if (GPIO.input(config.KEY_DOWN_PIN) == False): # noqa: E712
return None
# paint the screen
with canvas(device, dither=False) as draw:
statusbar.draw(draw, status)
draw_list(draw, text)
# wait is False if this is a loading screen
if (wait == False):
return None
# debounce keys
time.sleep(0.1)