-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·96 lines (82 loc) · 2.3 KB
/
main.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
import gc
print(f"Starting Free Memory: {gc.mem_free()}.")
import os
import random
import board
import network
from modes import (
ant,
ant_dance,
highlife_colors,
life_colors,
life_simple,
rain,
rule30,
war,
wolfram_four,
wolfram_three,
wolfram_two,
)
from utils.gameboard import GameBoard
from utils.internettime import InternetTime
from utils.shuffle import shuffle
print(f"Modules Imported: {gc.mem_free()}.")
wifi = network.RobsNetwork(debug=True, status_neopixel=board.NEOPIXEL)
esp = wifi._wifi.esp
esp._debug = True
print(f"Network Initialized, Free Memory: {gc.mem_free()}.")
timezone = os.getenv("TIMEZONE", "America/Chicago")
clock_update = int(os.getenv("CLOCK_INTERNET_UPDATE", 3600))
disable_internet = os.getenv("DISABLE_INTERNET", "false").lower() == "true"
clock_enabled = os.getenv("CLOCK_ENABLED", "true").lower() == "true"
brightness = float(os.getenv("BRIGHTNESS", 100)) / 100.00
time_format = os.getenv("TIME_FORMAT", "24")
it = InternetTime(
wifi,
os.getenv("TIMEZONE", "America/Chicago"),
debug=True,
seconds_between_updates=clock_update,
disable_internet=disable_internet,
)
GAMEBOARD = GameBoard(
wifi,
it,
clock_enabled=clock_enabled,
brightness=brightness,
time_format=time_format,
)
RANDOM_EXCLUDE_MODES = ["rule30"]
MODES = {
"ant": ant,
"ant_dance": ant_dance,
"highlife_colors": highlife_colors,
"life_colors": life_colors,
"life_simple": life_simple,
"rain": rain,
"rule30": rule30,
"war": war,
"wolfram_two": wolfram_two,
"wolfram_three": wolfram_three,
"wolfram_four": wolfram_four,
}
run_forever = False
mode_name = os.getenv("MODE", False)
if mode_name:
if mode_name in MODES:
MODE = MODES[mode_name]
run_forever = True
else:
print(f"Mode {mode_name} not found, running random modes.")
RANDOM_OPTIONS = []
while True:
if run_forever:
print(f"Running {mode_name} forever.")
MODE.run(GAMEBOARD, True)
else:
if not RANDOM_OPTIONS:
RANDOM_OPTIONS = list(set(MODES.keys()) - set(RANDOM_EXCLUDE_MODES))
shuffle(RANDOM_OPTIONS)
mode_name = RANDOM_OPTIONS.pop()
print(f"Running {mode_name} until it finishes.")
MODES[mode_name].run(GAMEBOARD, False)
gc.collect()