|
@@ -1,6 +1,6 @@
|
|
import RPi.GPIO as GPIO
|
|
import RPi.GPIO as GPIO
|
|
import time
|
|
import time
|
|
-from lib.mqtt import create_client, control_player, create_config
|
|
|
|
|
|
+from lib.mqtt import create_client, control_player, create_config, check_current_status
|
|
|
|
|
|
client = create_client()
|
|
client = create_client()
|
|
|
|
|
|
@@ -17,15 +17,23 @@ for pin in BUTTON_PINS:
|
|
|
|
|
|
# Callback functions to handle button presses
|
|
# Callback functions to handle button presses
|
|
def button_callback_1(channel):
|
|
def button_callback_1(channel):
|
|
- print("Button 1 pressed!")
|
|
|
|
- control_player(client, "PLAY")
|
|
|
|
|
|
+ if check_current_status() == "PLAY":
|
|
|
|
+ print("Button 1 pressed! Pausing playback.")
|
|
|
|
+ client = create_client()
|
|
|
|
+ control_player(client, "PAUSE")
|
|
|
|
+ else:
|
|
|
|
+ print("Button 1 pressed! Playing.")
|
|
|
|
+ client = create_client()
|
|
|
|
+ control_player(client, "PLAY")
|
|
|
|
|
|
def button_callback_2(channel):
|
|
def button_callback_2(channel):
|
|
print("Button 2 pressed!")
|
|
print("Button 2 pressed!")
|
|
|
|
+ client = create_client()
|
|
control_player(client, "PAUSE")
|
|
control_player(client, "PAUSE")
|
|
|
|
|
|
def button_callback_3(channel):
|
|
def button_callback_3(channel):
|
|
print("Button 3 pressed!")
|
|
print("Button 3 pressed!")
|
|
|
|
+ client = create_client()
|
|
|
|
|
|
# Add event detection for each button press
|
|
# Add event detection for each button press
|
|
GPIO.add_event_detect(BUTTON_PINS[0], GPIO.FALLING, callback=button_callback_1, bouncetime=200)
|
|
GPIO.add_event_detect(BUTTON_PINS[0], GPIO.FALLING, callback=button_callback_1, bouncetime=200)
|