Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@semicolonsnet
Last active November 24, 2020 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save semicolonsnet/2432ab5cf8739036ec5e4fe04a5fe2d4 to your computer and use it in GitHub Desktop.
Save semicolonsnet/2432ab5cf8739036ec5e4fe04a5fe2d4 to your computer and use it in GitHub Desktop.
Python script for pHAT BEAT buttons to control device connected by Shairport-sync via DBUS. See Shairport-sync for instructions on enabling DBUS.
#!/usr/bin/env python
import signal
import os
import phatbeat
print("""
pHAT BEAT: Shairport Buttons
Manipulates playback controls through DBus for Shairport-Sync
Press Control+C to exit
""")
@phatbeat.on(phatbeat.BTN_FASTFWD)
def fast_forward(pin):
os.system("dbus-send --system --print-reply --type=method_call --dest=org.gnome.ShairportSync '/org/gnome/ShairportSync' org.gnome.ShairportSync.RemoteControl.Next")
print("FF Pressed")
@phatbeat.hold(phatbeat.BTN_FASTFWD, hold_time=2)
def hold_fast_forward(pin):
os.system("dbus-send --system --print-reply --type=method_call --dest=org.gnome.ShairportSync '/org/gnome/ShairportSync' org.gnome.ShairportSync.RemoteControl.FastForward")
print("FF Held")
@phatbeat.on(phatbeat.BTN_PLAYPAUSE)
def play_pause(pin):
os.system("dbus-send --system --print-reply --type=method_call --dest=org.gnome.ShairportSync '/org/gnome/ShairportSync' org.gnome.ShairportSync.RemoteControl.PlayPause")
print("PP Pressed")
@phatbeat.hold(phatbeat.BTN_PLAYPAUSE, hold_time=2)
def hold_play_pause(pin):
os.system("dbus-send --system --print-reply --type=method_call --dest=org.gnome.ShairportSync '/org/gnome/ShairportSync' org.gnome.ShairportSync.RemoteControl.ShuffleSongs")
print("PP Held")
@phatbeat.on(phatbeat.BTN_VOLUP)
def volume_up(pin):
os.system("dbus-send --system --print-reply --type=method_call --dest=org.gnome.ShairportSync '/org/gnome/ShairportSync' org.gnome.ShairportSync.RemoteControl.VolumeUp")
print("VU Pressed")
@phatbeat.hold(phatbeat.BTN_VOLUP)
def hold_volume_up(pin):
print("VU Held")
@phatbeat.on(phatbeat.BTN_VOLDN)
def volume_down(pin):
os.system("dbus-send --system --print-reply --type=method_call --dest=org.gnome.ShairportSync '/org/gnome/ShairportSync' org.gnome.ShairportSync.RemoteControl.VolumeDown")
print("VD Pressed")
@phatbeat.hold(phatbeat.BTN_VOLDN)
def hold_volume_down(pin):
print("VD Held")
@phatbeat.on(phatbeat.BTN_REWIND)
def rewind(pin):
os.system("dbus-send --system --print-reply --type=method_call --dest=org.gnome.ShairportSync '/org/gnome/ShairportSync' org.gnome.ShairportSync.RemoteControl.Previous")
print("RW Pressed")
@phatbeat.hold(phatbeat.BTN_REWIND)
def hold_rewind(btn):
os.system("dbus-send --system --print-reply --type=method_call --dest=org.gnome.ShairportSync '/org/gnome/ShairportSync' org.gnome.ShairportSync.RemoteControl.Rewind")
print("RR Held")
@phatbeat.on(phatbeat.BTN_ONOFF)
def onoff(pin):
print("OO Pressed")
@phatbeat.hold(phatbeat.BTN_ONOFF)
def hold_onoff(pin):
os.system("sudo shutdown -h now")
print("OO Held")
signal.pause()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment