-
Notifications
You must be signed in to change notification settings - Fork 0
/
panel_liveshow.py
executable file
·95 lines (68 loc) · 3.01 KB
/
panel_liveshow.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
"""
Author: Adam Knowles
Version: 0.1
Description: Run the live show on the panel
GitHub Repository: https://github.com/Pharkie/AdamGalactic/ClockRolling.py
License: GNU General Public License (GPL)
"""
import uasyncio
import utime # type: ignore
import config
import utils
import datetime_utils
import panel_attract_functions
import urandom # type: ignore
async def advance_clock_slowly(old_values):
# print("rolling_clock() called")
# old_values = datetime_utils.get_time_values()
real_time = utime.mktime(utime.localtime())
sleep_duration = 0
for i in range(4):
# Artificially alter the current time as a tuple
fake_time_tuple = utime.localtime(real_time + i)
new_values = list(datetime_utils.get_time_values(fake_time_tuple))
delayed_delay = 0.05 * pow(2, i)
panel_attract_functions.update_clock_display(new_values, old_values, delay=delayed_delay, reverse=False)
# Exponential acceleration
sleep_duration = 1 * pow(1.25, i)
await uasyncio.sleep(sleep_duration)
old_values = new_values.copy()
return fake_time_tuple
async def rollback_clock_to_madness(fake_start_time_tuple):
# print("rollback_clock_to_madness() called")
# print(f"fake_start_time_tuple: {fake_start_time_tuple}")
start_time = utime.mktime(fake_start_time_tuple)
subtract_secs = 0
for counter in range(70):
# Max sets a reasonable minimum value for the delay and sleep_duration
delay = max(0.001, 0.2 * pow(0.6, counter))
sleep_duration = max(0.001, 1 * pow(0.6, counter))
# Artificially alter the current time as a tuple
fake_time_tuple = utime.localtime(start_time - subtract_secs)
new_values = list(datetime_utils.get_time_values(fake_time_tuple))
# Initiliase old_values on the first loop to be the same as values
if counter == 0:
old_values = new_values.copy()
delay = 0
sleep_duration = 0
print(f"counter {counter} delay {delay} sleep_duration = {sleep_duration} subtract_secs {subtract_secs}")
panel_attract_functions.update_clock_display(new_values, old_values, delay=delay, reverse=True)
await uasyncio.sleep(sleep_duration)
old_values = new_values.copy()
# Exponential acceleration
subtract_secs += int( 1 * pow(1.25, counter))
# Min sets a reasonable ceiling value of seconds to subtract
if subtract_secs > 43000:
subtract_secs = urandom.randint(100, 50000)
async def main():
# await utils.scroll_msg("Showtime")
time_tuple_at_end = uasyncio.run(panel_attract_functions.rolling_clock(4))
# print(f"time_tuple_at_end: {time_tuple_at_end}")
fake_time_tuple_at_end = uasyncio.run(advance_clock_slowly(time_tuple_at_end))
uasyncio.run(rollback_clock_to_madness(fake_time_tuple_at_end))
utils.clear_picoboard()
if __name__ == "__main__":
utils.clear_picoboard()
datetime_utils.sync_rtc()
uasyncio.run(main())
# print(utime.localtime())