Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast Forward and Rewind via GPIO-Buttons #578

Open
rpkZarathustra opened this issue Sep 13, 2019 · 9 comments

Comments

@rpkZarathustra
Copy link

@rpkZarathustra rpkZarathustra commented Sep 13, 2019

How about fast forward and rewind like in the web-interface but with GPIO-buttons. In case of large sound files this could be handy.

Or maybe it ist possible that a long or a short push of the SKIP-buttons is read as fast forward/rewind or skip.

@iwishitwassummer

This comment has been minimized.

Copy link

@iwishitwassummer iwishitwassummer commented Sep 26, 2019

Hi @rpkZarathustra
I did this and it comes in totally handy (couldn't stand the beeping noise of the RFID reader).
I used those buttons. You need to solder as described here in section 5.

code should be added to gpio-buttons.py, please check pins and enter yours (I'm actually using splitti's oled script for this, hence the jukebox variable):

`jukebox4kidsPath = "/home/pi/RPi-Jukebox-RFID"
def def_seekahead():
check_call(jukebox4kidsPath+"/scripts/playout_controls.sh -c=playerseek -v=+20", shell=True)

def def_seekback():
check_call(jukebox4kidsPath+"/scripts/playout_controls.sh -c=playerseek -v=-20", shell=True)
seekA = Button(16,pull_up=False,hold_time=0.3,hold_repeat=True)
seekB = Button(19,pull_up=False,hold_time=0.3,hold_repeat=True)

seekA.when_pressed = def_seekahead
seekA.when_held = def_seekahead
seekB.when_pressed = def_seekback
seekB.when_held = def_seekback`

This works as I expected, short press +/- 20 sec and if hold is seeks ahead/backwards as long as it's hold

(see also here)

@MiczFlor

This comment has been minimized.

Copy link
Owner

@MiczFlor MiczFlor commented Sep 28, 2019

Hi @iwishitwassummer
thumbs up. Could you create a pull request against the develop branch?

@iwishitwassummer

This comment has been minimized.

Copy link

@iwishitwassummer iwishitwassummer commented Sep 29, 2019

@MiczFlor I'll try, but I'm a newbie to working with code in github

@MiczFlor

This comment has been minimized.

Copy link
Owner

@MiczFlor MiczFlor commented Sep 29, 2019

Alternatively, you could post the complete file here in the thread and I will merge it in.

@carver79

This comment has been minimized.

Copy link

@carver79 carver79 commented Oct 17, 2019

@iwishitwassummer
Could you post your gpio-buttons.py?
Eversince i try to "merge" your code with mine (also Splitti), i cant activate the GPIO-Buttons. Just to compare and search the bug in my copy-paste-coding.

Or anybody else who implemented this - thx in advance

@iwishitwassummer

This comment has been minimized.

Copy link

@iwishitwassummer iwishitwassummer commented Oct 18, 2019

Apologies for the late reply
Is placed in ~/oled_phoniebox/scripts/gpio-buttons

#!/usr/bin/python3
from gpiozero import Button`
from signal import pause
from subprocess import check_call
from time import sleep
# This script will block any I2S DAC e.g. from Hifiberry, Justboom, ES9023, PCM5102A
# due to the assignment of GPIO 19 and 21 to a buttons

# 2018-10-31
# Added the function on holding volume + - buttons to change the volume in 0.3s interval
#
# 2018-10-15
# this script has the `pull_up=True` for all pins. See the following link for additional info:
# https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/259#issuecomment-430007446
#
# 2017-12-12
# This script was copied from the following RPi forum post:
# https://forum-raspberrypi.de/forum/thread/13144-projekt-jukebox4kids-jukebox-fuer-kinder/?postID=312257#post312257
# I have not yet had the time to test is, so I placed it in the misc folder.
# If anybody has ideas or tests or experience regarding this solution, please create pull requests or contact me.

jukebox4kidsPath = "/home/pi/RPi-Jukebox-RFID"

def def_shutdown():
    check_call(jukebox4kidsPath+"/scripts/playout_controls.sh -c=shutdown", shell=True)

def def_volU():
    check_call(jukebox4kidsPath+"/scripts/playout_controls.sh -c=volumeup", shell=True)

def def_volD():
    check_call(jukebox4kidsPath+"/scripts/playout_controls.sh -c=volumedown", shell=True)

def def_vol0():
    check_call(jukebox4kidsPath+"/scripts/playout_controls.sh -c=mute", shell=True)

def def_next():
#  for x in range(0, 19):
#    if next.is_pressed == True :
#      sleep(0.1)
#    else:
      check_call(jukebox4kidsPath+"/scripts/playout_controls.sh -c=playernext", shell=True)
#      break

def def_contrastup():
  if prev.is_pressed == True :
    check_call("/usr/bin/touch /tmp/o4p_overview.temp", shell=True)
  else:
    check_call("/usr/bin/python3 /home/pi/oled_phoniebox/scripts/contrast/contrast_up.py", shell=True)

def def_contrastdown():
  if next.is_pressed == True :
    check_call("/usr/bin/touch /tmp/o4p_overview.temp", shell=True)
  else:
    check_call("/usr/bin/python3 /home/pi/oled_phoniebox/scripts/contrast/contrast_down.py", shell=True)

def def_prev():
#  for x in range(0, 19):
#    if prev.is_pressed == True :
#      sleep(0.1)
#    else:
      check_call(jukebox4kidsPath+"/scripts/playout_controls.sh -c=playerprev", shell=True)
#      break

def def_halt():
    check_call(jukebox4kidsPath+"/scripts/playout_controls.sh -c=playerpause", shell=True)


def def_seekahead():
    check_call(jukebox4kidsPath+"/scripts/playout_controls.sh -c=playerseek -v=+20", shell=True)

def def_seekback():
    check_call(jukebox4kidsPath+"/scripts/playout_controls.sh -c=playerseek -v=-20", shell=True)


#shut = Button(3, hold_time=2)
#vol0 = Button(13,pull_up=True)
#volU = Button(16,pull_up=True,hold_time=0.3,hold_repeat=True)
#volD = Button(19,pull_up=True,hold_time=0.3,hold_repeat=True)
next = Button(26,pull_up=False,hold_time=0.1,hold_repeat=False)
prev = Button(20,pull_up=False,hold_time=0.1,hold_repeat=False)
#prev = Button(20,pull_up=False)
#next = Button(26,pull_up=False)
halt = Button(21,pull_up=False)
# vorspulen/zurueckspulen ACHTUNG sind dieselben pins wie Volume im classic mode der Phoniebox
seekA = Button(16,pull_up=False,hold_time=0.3,hold_repeat=True)
seekB = Button(19,pull_up=False,hold_time=0.3,hold_repeat=True)


#shut.when_held = def_shutdown
#vol0.when_pressed = def_vol0
#volU.when_pressed = def_volU
#When the Volume Up button was held for more than 0.3 seconds every 0.3 seconds he will call a ra$
#volU.when_held = def_volU
#volD.when_pressed = def_volD
#When the Volume Down button was held for more than 0.3 seconds every 0.3 seconds he will lower t$
#volD.when_held = def_volD
seekA.when_pressed = def_seekahead
seekA.when_held = def_seekahead
seekB.when_pressed = def_seekback
seekB.when_held = def_seekback
next.when_pressed = def_next
#next.when_held = def_contrastup
prev.when_pressed = def_prev
#prev.when_held = def_contrastdown
halt.when_pressed = def_halt

pause()
@carver79

This comment has been minimized.

Copy link

@carver79 carver79 commented Oct 19, 2019

Thx - i dont have any coding skills, but every volume is commented out.
how do you change volume?

@iwishitwassummer

This comment has been minimized.

Copy link

@iwishitwassummer iwishitwassummer commented Oct 19, 2019

@donhomie

This comment has been minimized.

Copy link

@donhomie donhomie commented Nov 28, 2019

Thanks for the code, just managed to get it to work! In case anyone is having trouble getting this to work: try using pull_up=True, so e.g.:

seekA = Button(16,pull_up=False,hold_time=0.3,hold_repeat=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.