1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 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()
|