96 lines
2.2 KiB
Python
96 lines
2.2 KiB
Python
from gpiozero import Button
|
|
from signal import pause
|
|
import time
|
|
import subprocess
|
|
import beepy as beep
|
|
|
|
|
|
|
|
Button.was_held = False
|
|
|
|
|
|
def vol_up(btn):
|
|
btn.was_held = True
|
|
while btn.was_held:
|
|
# print("Vol Up")
|
|
result = subprocess.run(
|
|
[f"mpc volume +10"],
|
|
stdout=subprocess.PIPE,
|
|
shell=True,
|
|
).stdout.decode("utf-8")
|
|
# beep(sound=1)
|
|
time.sleep(0.5)
|
|
|
|
|
|
def vol_down(btn):
|
|
btn.was_held = True
|
|
while btn.was_held:
|
|
# print("Vol Down")
|
|
result = subprocess.run(
|
|
[f"mpc volume -10"],
|
|
stdout=subprocess.PIPE,
|
|
shell=True,
|
|
).stdout.decode("utf-8")
|
|
# beep(sound=1)
|
|
time.sleep(0.5)
|
|
|
|
|
|
def playpause_down(btn):
|
|
btn.was_held = True
|
|
while btn.was_held:
|
|
print("playpause")
|
|
time.sleep(1)
|
|
|
|
|
|
def released(btn):
|
|
if not btn.was_held:
|
|
pressed(btn)
|
|
btn.was_held = False
|
|
|
|
|
|
def pressed(btn):
|
|
if btn._pin.number == 15:
|
|
# print("next")
|
|
result = subprocess.run(
|
|
[f"python ./player.py next"],
|
|
stdout=subprocess.PIPE,
|
|
shell=True,
|
|
).stdout.decode("utf-8")
|
|
elif btn._pin.number == 24:
|
|
# print("back")
|
|
result = subprocess.run(
|
|
[f"python ./player.py previous"],
|
|
stdout=subprocess.PIPE,
|
|
shell=True,
|
|
).stdout.decode("utf-8")
|
|
elif btn._pin.number == 14:
|
|
# print("playpause")
|
|
result = subprocess.run(
|
|
[f"python ./player.py playpause"],
|
|
stdout=subprocess.PIPE,
|
|
shell=True,
|
|
).stdout.decode("utf-8")
|
|
elif btn._pin.number == 23:
|
|
# print("shuffle")
|
|
result = subprocess.run(
|
|
[f"python ./player.py shuffle"],
|
|
stdout=subprocess.PIPE,
|
|
shell=True,
|
|
).stdout.decode("utf-8")
|
|
|
|
|
|
up_btn = Button(15)
|
|
down_button = Button(24)
|
|
playpause_button = Button(14)
|
|
shuffle_button = Button(23)
|
|
|
|
down_button.when_held = vol_down
|
|
down_button.when_released = released
|
|
|
|
up_btn.when_held = vol_up
|
|
up_btn.when_released = released
|
|
|
|
playpause_button.when_released = released
|
|
shuffle_button.when_released = released
|
|
pause()
|