refactor: move GPIO and pygame initialization into setup()

This commit is contained in:
2026-06-18 16:58:57 +02:00
parent 0621ab6190
commit 434c49b609
+4 -1
View File
@@ -59,10 +59,12 @@ def remove_pid_file():
pass
# GPIO Setup
BUTTON_PIN = 17
LED_PIN = 27
def setup():
"""Initialize GPIO and audio hardware. Call once before running."""
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_PIN, GPIO.OUT)
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
@@ -199,6 +201,7 @@ class AlarmClock:
def run_alarm(test_mode=False):
setup()
logging.info("Alarm clock started. Music is playing in an endless loop.")
if "pygame" in globals() and hasattr(pygame, "mixer") and pygame.mixer.get_init():
pygame.mixer.music.play(-1)