-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreen_test.py
77 lines (61 loc) · 1.73 KB
/
screen_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
import utest
from highord import *
from display import *
from pyb import *
from screen import *
from utilities import *
from cmemgr import Mapper
from context import ContextChain
oled = OLED(I2C(2, mode=I2C.MASTER))
console = Console(oled)
oled.init()
oled.clear()
# 四个按钮: 上 左 右 确定
cur_time = [1, 1, 0, 0, 0]
val_borders = [(1, 12), (1, 30), 23, 59, 59]
separator = ['/', ' ', ':', ':']
cur_sel = -1
def redraw():
with console.session:
console[1][1] = 'Current Time:'
for i in range(len(separator)):
console[2][(i + 1) * 3] = separator[i]
for i in range(len(cur_time)):
cc = ContextChain([console.padding(2, char='0')])
if cur_sel == i:
cc.append(console.reverse)
with cc:
console[2][1 + 3 * i] = cur_time[i]
@key_handler('Y6')
def key2():
if cur_sel >= 0:
cur_time[cur_sel] += 1
cur_border = val_borders[cur_sel]
min_val, max_val = cur_border if type(cur_border) is tuple else (0, cur_border)
cur_time[cur_sel] = (cur_time[cur_sel] - min_val) % (max_val - min_val + 1) + min_val
redraw()
@key_handler('Y7')
def key3():
global cur_sel
cur_sel += 1
cur_sel %= len(cur_time)
redraw()
@key_handler('Y8')
def key4():
# 确认
global cur_sel
cur_sel = -1
redraw()
if __name__ == '__main__':
redraw()
Mapper.run(use_main_thread=True)
# 这个按键应该是物理上坏了
@key_handler('Y5')
def key1():
print('key1 pressed!')
# global cur_num
# cur_num -= 1
# print(cur_num)
# console[2][1] = str(cur_num)
# 只允许往上调整时间
# 月 日 时 分