-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (51 loc) · 2.08 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
import time
import os
import supervisor
from lib.makrobuddy.helpers.TextManager import TextManager
from lib.makrobuddy.helpers.SpriteManager import SpriteManager
from lib.makrobuddy.helpers.Display import Display
from lib.makrobuddy.helpers.EventManager import EventManager
from lib.makrobuddy.eletronic_components.RotaryEncoder import RotaryEncoder
from lib.makrobuddy.eletronic_components.MechanicalSwitches import MechanicalSwitches
print(os.uname().machine)
time.sleep(0.5)
# Disable auto_reload
supervisor.disable_autoreload()
rotary_encoder = RotaryEncoder()
mechanical_switches = MechanicalSwitches()
event_manager = EventManager()
display = Display()
text_manager = TextManager(display.width, display.height)
text_manager.set_text("MakroBuddy 1.0")
display.GC9A01.show(text_manager.group)
display.GC9A01.refresh()
character = "dog"
available_character = os.listdir("/sprites")
while rotary_encoder.button.value == True:
character = available_character[rotary_encoder.encoder.position %
len(available_character)]
text_manager.set_text("Choose your char: " + character)
display.GC9A01.refresh()
sprite_manager = SpriteManager(character, display.width, display.height)
display.GC9A01.show(sprite_manager.main_group)
display.GC9A01.refresh()
while True:
now = time.monotonic()
# display some art if there is no important message!
if not event_manager.showing_message and now >= sprite_manager.last_blink_time + sprite_manager.blink_off_duration:
sprite_manager.run(now)
display.GC9A01.refresh()
message = event_manager.run(now)
if message != None:
text_manager.set_text(message)
display.GC9A01.show(text_manager.group)
display.GC9A01.refresh()
# important messages should stay like 30 seconds on the screen!
if (event_manager.last_time_read + event_manager.ttl) <= now:
event_manager.showing_message = False
display.GC9A01.show(sprite_manager.main_group)
display.GC9A01.refresh()
rotary_encoder.run()
mechanical_switches.run()
# debounce
time.sleep(0.01)