-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMagicRadio.py
executable file
·65 lines (55 loc) · 2.09 KB
/
MagicRadio.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
#!/usr/bin/python
import FictionalTuner
import SerialHandler
import PyGameHandler
import LogHistorian
import InputControl
import MRGlobals
import MRLogging
import logging
import time
# Holder for the two threads created
threads = []
# Keeping track of boot time
bootTime = time.time()
# Initialize logging
MRLogging.init_logging()
# Delete logs that are out of date
LogHistorian.deleteAgedLogs()
# Initialize the connection with the arduino
logging.info("Connecting to Arduino...")
serialArduino = SerialHandler.initSerial()
logging.info("Connected to Arduino")
# Begin the thread which reads input from the arduino
logging.info("Beginning input control thread...")
readingThread = InputControl.readThread(serialArduino)
readingThread.start()
threads.append(readingThread)
logging.info("Input Thread running")
# Initialize the audio playback with pygame
logging.info("Beginning PyGameInit")
PyGameHandler.initPygame()
logging.info("Initialized Pygame")
# Begin the audio loop thread
# This is started before the tuner is to allow volume control of static while the spectrum is built
playingThread = PyGameHandler.audioLooper()
playingThread.start()
threads.append(playingThread)
logging.info("Audio playback has begun")
# Setup of Tuner / spectrum
logging.info("Setting up tuner")
playingThread.tuner = FictionalTuner.fictTuner()
elapsedBootTime = time.time() - bootTime
logging.info("Tuner has been set-up, boot took %d seconds" % elapsedBootTime)
# MRGlobals.booting being false allows the playback thread to work properly with the spectrum.
MRGlobals.booting = False
# Move the start/end code to this if-statement, as this can be imported and function as a module.
if __name__ == "__main__":
# Keyboard interrupt is tuck in as a try/except since I run this as a service on my raspberryPi, and it'd crash the main thread
# since I used to use raw_input() and there'd literally be no way for input to occur.
try:
time.sleep(1)
except(KeyboardInterrupt):
MRGlobals.running = False
for thread in threads:
thread.join()