-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui_test.py
105 lines (84 loc) · 2.6 KB
/
ui_test.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""
UI, Framebuffer driver & touch driver test code
"""
import pygame
import trio
from loguru import logger
from basic_ui_framework import *
from framebuffer_driver import *
from touch_driver import *
pygame.init()
def bake_ui():
_trans = (25, 25, 25, 255)
symbol_font = pygame.font.SysFont("freeserif", 50)
temp_font = pygame.font.SysFont("notosansmono", 50)
state_font = pygame.font.SysFont("undotum", 40)
ui = {
"Temp up": TextButton(
(10, 10), (70, 70), "▲", color=(255, 0, 0, 255), font=symbol_font
),
"Temp down": TextButton(
(10, 80), (70, 140), "▼", color=(0, 0, 255, 255), font=symbol_font
),
"Power": TextButton(
(10, 250), (70, 310), "⚡", color=(100, 100, 100, 255), font=symbol_font
),
"Temp target": TextBox(
(220, 10),
(470, 70),
"TGT --°C",
color=_trans,
text_color=(0, 255, 0, 255),
font=temp_font,
),
"Temp current": TextBox(
(220, 80),
(470, 140),
"CUR --°C",
color=_trans,
text_color=(255, 255, 255, 255),
font=temp_font,
),
# "Wind angle": TextBox((100, 80), (100, 130), "WC", color=_trans, text_color=(255, 255, 255, 255)),
# "Wind speed": TextBox((100, 80), (100, 130), "CUR: --'C", color=_trans, text_color=(255, 255, 255, 255)),
"Operation Mode": TextBox(
(370, 260),
(470, 310),
"꺼짐",
color=_trans,
text_color=(255, 255, 255, 255),
font=state_font,
),
}
return UIManager(**ui)
async def main():
# init framebuffer
framebuffer_init()
fb_d = FramebufferDriver()
fb_d.show_splash()
fb_d.update_sync()
# init touch driver
touch_d = TouchDriver("LCD35", "event0")
# init ui framework
ui_framework_init(fb_d.screen)
ui = bake_ui()
# Power toggle example
sample_flag = True
async def demo_action(*_):
nonlocal sample_flag
if sample_flag:
ui["Power"].set_color(0, 255, 0, 255)
else:
ui["Power"].set_color(100, 100, 100, 255)
sample_flag = not sample_flag
ui["Power"].on_click = demo_action
# Startup tasks
async with trio.open_nursery() as nursery:
# load loops
nursery.start_soon(ui.poll_touch, touch_d)
logger.debug("Startup complete")
while True:
ui.draw_all()
nursery.start_soon(fb_d.update)
await trio.sleep(0.1)
trio.run(main)