-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
executable file
·167 lines (116 loc) · 3.36 KB
/
__init__.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import utime
import leds
import display
import buttons
import simple_menu
import sys
sys.path.append('/apps/berlin_uhr/')
import segement as _segment
import render as _render
import brightness as _brightness
def render_gui(disp):
_, month, day, hours, mins, secs, _, _ = utime.localtime()
first_unit = hours
second_unit = mins
if MODE is "date":
first_unit = day
second_unit = month
global PREV_SECOND
if PREV_SECOND < secs:
disp.clear(col=_segment.Colors.black)
display_brightness, led_brightness = _brightness.calculated()
if WITH_BRIGHTNESS_ADJUST:
disp.backlight(display_brightness)
if WITH_SECONDS_LED:
display_seconds(secs, led_brightness)
if WITH_SECONDS:
_render.second(disp, secs)
_render.type(disp, MODE, first_unit, second_unit)
if WITH_HINTS:
_render.hint(disp, first_unit, second_unit)
disp.update()
if secs is 59:
PREV_SECOND = -1
else:
PREV_SECOND += 1
def display_seconds(sec, intensity):
leds.set_rocket(1, intensity) if sec % 2 == 0 else leds.set_rocket(1, 0)
# ==== configuration ==== #
WITH_SECONDS = True
WITH_SECONDS_LED = True
MODE = "time"
WITH_HINTS = True
WITH_BRIGHTNESS_ADJUST = True
DEV_MODE = False
PREV_SECOND = 0
def load_config():
toggle_seconds_mode()
toggle_date_mode()
toggle_hint_mode()
def toggle_date_mode():
button = buttons.read(buttons.TOP_RIGHT)
pressed = button != 0
if pressed:
date_mode_toggle()
def toggle_seconds_mode():
button = buttons.read(buttons.BOTTOM_LEFT)
pressed = button != 0
if pressed:
seconds_toggle()
def toggle_hint_mode():
button = buttons.read(buttons.BOTTOM_RIGHT)
pressed = button != 0
if pressed:
hints_toggle()
def state_2_str(state):
if state:
return "[Y]"
else:
return "[N]"
def seconds_toggle():
global WITH_SECONDS
WITH_SECONDS = not WITH_SECONDS
def seconds_led_toggle():
global WITH_SECONDS_LED
WITH_SECONDS_LED = not WITH_SECONDS_LED
def hints_toggle():
global WITH_HINTS
WITH_HINTS = not WITH_HINTS
def dev_mode_toggle():
global DEV_MODE
DEV_MODE = not DEV_MODE
def date_mode_toggle():
global MODE
if MODE is "time":
MODE = "date"
else:
MODE = "time"
def brightness_adjust_toggle():
global WITH_BRIGHTNESS_ADJUST
WITH_BRIGHTNESS_ADJUST = not WITH_BRIGHTNESS_ADJUST
class SettingsMenu(simple_menu.Menu):
color_1 = _segment.Colors.black
color_2 = _segment.Colors.black
color_text = _segment.Colors.yellow_on
color_sel = _segment.Colors.red_on
def on_select(self, name, index):
self.exit()
def setting_menu():
if WITH_HINTS:
SettingsMenu([
state_2_str(WITH_SECONDS) + " show seconds",
state_2_str(WITH_SECONDS_LED) + " seconds LED",
state_2_str(WITH_HINTS) + " show hints",
state_2_str(DEV_MODE) + " date mode",
state_2_str(WITH_BRIGHTNESS_ADJUST) + " auto brightness",
state_2_str(DEV_MODE) + " dev mode"
]).run()
# ==== execution ==== #
def main():
_brightness.start_light_sensor()
while True:
load_config()
# setting_menu()
with display.open() as _display:
render_gui(_display)
main()