Created
February 15, 2019 15:52
-
-
Save kampfgnu/6eb9f6b70abf8001d83130598018b6df to your computer and use it in GitHub Desktop.
listen for gamepad events and do some stuff for my home audio setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -------------------------------------------------------------------------- | |
# | |
# -------------------------------------------------------------------------- | |
#import evdev | |
from evdev import InputDevice, categorize, ecodes | |
from subprocess import call | |
#creates object 'gamepad' to store the data | |
#you can call it whatever you like | |
gamepad = InputDevice('/dev/input/event0') | |
#button code variables (change to suit your device) | |
alsabtn = 290 | |
teufelbtn = 289 | |
restartbtn = 296 | |
#prints out device info at start | |
print(gamepad) | |
#loop and filter by event code and print the mapped label | |
for event in gamepad.read_loop(): | |
if event.type == ecodes.EV_KEY: | |
#print("key" + str(event.code)) | |
if event.value == 1: | |
if event.code == alsabtn: | |
print("start alsa") | |
call(['sudo', 'cp', '/etc/default/snapclient.alsa', '/etc/default/snapclient']) | |
call(['sudo', 'systemctl', 'restart', 'snapclient']) | |
elif event.code == teufelbtn: | |
print("start teufel") | |
call(['sudo', 'cp', '/etc/default/snapclient.teufel', '/etc/default/snapclient']) | |
call(['sudo', 'systemctl', 'restart', 'snapclient']) | |
elif event.code == restartbtn: | |
print("stop/start mopidy and snapserver") | |
call(['sudo', 'systemctl', 'stop', 'mopidy']) | |
call(['sudo', 'systemctl', 'stop', 'snapserver']) | |
call(['sudo', 'truncate', '-s 0', '/var/log/mopidy/mopidy.log']) | |
call(['sudo', 'truncate', '-s 0', '/var/log/daemon.log']) | |
call(['sudo', 'truncate', '-s 0', '/var/log/syslog']) | |
call(['sudo', 'systemctl', 'start', 'snapserver']) | |
call(['sudo', 'systemctl', 'start', 'mopidy']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment