|
@@ -0,0 +1,56 @@
|
|
|
+import os
|
|
|
+import RPi.GPIO as GPIO
|
|
|
+import time
|
|
|
+from dotenv import load_dotenv
|
|
|
+from lib.mqtt import create_client, update_disc, control_player, create_config, check_current_disc
|
|
|
+
|
|
|
+
|
|
|
+load_dotenv()
|
|
|
+
|
|
|
+
|
|
|
+broker = os.environ.get("broker")
|
|
|
+port = int(os.environ.get("port"))
|
|
|
+
|
|
|
+username = os.environ.get("username")
|
|
|
+password = os.environ.get("password")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+client = create_client(broker, port, username, password)
|
|
|
+
|
|
|
+create_config(client)
|
|
|
+
|
|
|
+
|
|
|
+BUTTON_PINS = [17, 18, 27]
|
|
|
+
|
|
|
+GPIO.setmode(GPIO.BCM)
|
|
|
+
|
|
|
+
|
|
|
+for pin in BUTTON_PINS:
|
|
|
+ GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
|
|
+
|
|
|
+
|
|
|
+def button_callback_1(channel):
|
|
|
+ print("Button 1 pressed!")
|
|
|
+ control_player(client, "PLAY")
|
|
|
+
|
|
|
+def button_callback_2(channel):
|
|
|
+ print("Button 2 pressed!")
|
|
|
+ control_player(client, "PAUSE")
|
|
|
+
|
|
|
+def button_callback_3(channel):
|
|
|
+ print("Button 3 pressed!")
|
|
|
+
|
|
|
+
|
|
|
+GPIO.add_event_detect(BUTTON_PINS[0], GPIO.FALLING, callback=button_callback_1, bouncetime=200)
|
|
|
+GPIO.add_event_detect(BUTTON_PINS[1], GPIO.FALLING, callback=button_callback_2, bouncetime=200)
|
|
|
+GPIO.add_event_detect(BUTTON_PINS[2], GPIO.FALLING, callback=button_callback_3, bouncetime=200)
|
|
|
+
|
|
|
+try:
|
|
|
+
|
|
|
+ while True:
|
|
|
+ time.sleep(1)
|
|
|
+except KeyboardInterrupt:
|
|
|
+ pass
|
|
|
+finally:
|
|
|
+ GPIO.cleanup()
|