Skip to content
Snippets Groups Projects
Commit 823c00a7 authored by markus's avatar markus
Browse files

Add option to set time

parent 927d3057
Branches
No related tags found
No related merge requests found
......@@ -174,6 +174,8 @@ class Clock:
elif button_pressed and v & buttons.BOTTOM_RIGHT != 0:
self.setTheme(self.theme + 1)
self.writeConfig()
elif button_pressed and v & buttons.TOP_RIGHT != 0:
self.setTime(disp, localtime)
except KeyboardInterrupt:
for i in range(11):
......@@ -245,6 +247,44 @@ class Clock:
disp.update()
def setTime(self, disp, localtime):
accepted = False
blank = False
previously_pressed_button = buttons.TOP_RIGHT
button_repeat_counter = 0
set_seconds = utime.mktime(localtime)
while not accepted:
v = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT | buttons.TOP_RIGHT)
button_pressed = v != 0
if button_pressed:
if v & previously_pressed_button != 0:
button_repeat_counter += 1
else:
if v & buttons.BOTTOM_LEFT != 0:
previously_pressed_button = buttons.BOTTOM_LEFT
elif v & buttons.BOTTOM_RIGHT != 0:
previously_pressed_button = buttons.BOTTOM_RIGHT
elif v & buttons.TOP_RIGHT != 0 and previously_pressed_button != buttons.TOP_RIGHT:
accepted = True
else:
previously_pressed_button = 0
else:
previously_pressed_button = 0
button_repeat_counter = 0
seconds_change = int(min(1.1**button_repeat_counter, 60*23))
if previously_pressed_button == buttons.BOTTOM_LEFT:
set_seconds -= seconds_change
elif previously_pressed_button == buttons.BOTTOM_RIGHT:
set_seconds += seconds_change
self.updateClock(disp, utime.localtime(set_seconds))
utime.sleep_ms(23)
utime.set_time(int(set_seconds))
def circlePoint(self, t):
return (
int(round(self.radius * math.cos(t))) + self.center[0],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment