i have managed to use a rotary encoder to change volume and play/pause, was inspired by this here:
hardware-play-pause-button-t3665-10.html
and got some help from Bob:
https://github.com/bobrathbone/piradio
I am using the original rotary_class.py from Bob.
I am using this encoder and these pins (attachment):
https://www.conrad.at/de/encoder-5-vdc- ... 53405.html
I used this codes here to start:
- Code: Select all
pacman -Syy
pacman -S python2
pip install RPi.GPIO
That's the script for controlling runeaudio (mpd):
- Code: Select all
#!/usr/bin/env python
#
# Raspberry Pi Rotary Test Encoder Class
# $Id: rotary_switch.py,v 1.4 2014/01/31 14:06:26 bob Exp $
#
# Author : Bob Rathbone
# Site : http://www.bobrathbone.com
#
# Adjusted to be used as single hardwarecontroller for rune audio and Hifiberry Amp2 by Petrus Gartler
# Date : 2017/12/2
#
# This class uses standard rotary encoder with push switch
#
import sys
import time
import sys,os
from rotary_class import RotaryEncoder
# Switch definitions
ROT_A = 24
ROT_B = 25
ROT_BUTTON = 23
# Execute system command
def execCommand(cmd):
p = os.popen(cmd)
return p.readline().rstrip('\n')
# This is the event callback routine to handle knob events
def volume_knob_event(event):
handle_event(event,"Volume knob")
return
# This is the event callback routine to handle events
def handle_event(event, name):
if event == RotaryEncoder.CLOCKWISE:
# print name, "Clockwise event =", RotaryEncoder.CLOCKWISE
execCommand("mpc volume +5"), RotaryEncoder.CLOCKWISE
elif event == RotaryEncoder.ANTICLOCKWISE:
# print name, "Anticlockwise event =", RotaryEncoder.ANTICLOCKWISE
execCommand("mpc volume -10"), RotaryEncoder.CLOCKWISE
elif event == RotaryEncoder.BUTTONDOWN:
# print name, "Button down event =", RotaryEncoder.BUTTONDOWN
execCommand("mpc toggle"), RotaryEncoder.BUTTONDOWN
# elif event == RotaryEncoder.BUTTONUP:
# print name, "Button up event =", RotaryEncoder.BUTTONUP
return
# Define knob
volumeknob = RotaryEncoder(ROT_A,ROT_B,ROT_BUTTON,volume_knob_event,2)
# Wait for events
while True:
time.sleep(0.5)
# End of program
Now i am trying to make an on/of switch but unfortunately i somehow messed around the poweroff command and can't even shutdown rune using the webinterface or terminal.
I am afraid, i deleted a file called poweroff-target. Is that something i shouldn't have done?
I hope someone can get me out without reinstalling the whole thing.
Cheers,
Pe