/
primer.py
48 lines (41 loc) · 1.92 KB
/
primer.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
import asyncio,yaml,json,importlib
from Primer.Handlers import recorder_handler, button_handler, display_handler, mikroserver_handler, gesture_handler
from Primer.IO.Audio.Recorder import Recorder
from Primer.IO.Audio.Player import Player
from Primer.IO.Gesture import Gesture
from Primer.Student import Student
from Primer.Folio import Folio
class PersonalPrimer:
def __init__(self):
with open('/home/fibel/config.yaml', 'r') as file:
self.config = yaml.safe_load(file)
with open(self.config['lesson0'], 'r') as file:
self.all_folios = json.load(file)
self.display_driver=importlib.import_module("Primer.IO.EPD."+self.config['EPD']['driver'])
self.queue=dict()
async def start(self):
#GPT4::The asyncio.Queue objects must be created in the same event loop where they are used.
self.queue={
'button' : asyncio.Queue(),
'display' : asyncio.Queue(),
'gesture' : asyncio.Queue(),
'mikroserver' : asyncio.Queue(),
'student' : asyncio.Queue()
}
self.display=self.display_driver.EInkDisplay(self.config)
self.student=Student(self)
self.folio=Folio(self)
self.gesture=Gesture(self)
self.loop = asyncio.get_running_loop() #necessary for synchronous libraries like PyAudio
self.recorder=Recorder(self)
self.player=Player(self)
await self.queue['display'].put({"c":self.config['auth']['hi']})
#we pass the main object to all handlers so that they can access it through pp. or self.pp
await asyncio.gather(
button_handler.handle_button(self),
recorder_handler.handle_recorder(self),
mikroserver_handler.handle_mikroserver(self),
gesture_handler.handle_gesture(self),
display_handler.handle_display(self)
)
asyncio.run(PersonalPrimer().start())