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

Simple powered up led #387

Merged
merged 41 commits into from
Feb 8, 2020
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a53a4a9
Changed amazon links to stores other than amazon
Nov 29, 2018
420e414
Set up
Nov 30, 2018
2d3c2d1
Adopted shopping list
Dec 7, 2018
5c8fc12
Added status led
Dec 7, 2018
5926ee3
Updated install script to general gpio service removal
Dec 9, 2018
3ebaccc
Fixed: GPIO service calling wrong script
Dec 9, 2018
09951e1
Fixed old service removal
Dec 9, 2018
2025b9c
Updated shopping list
Dec 10, 2018
f11a22b
Merge branch 'shopping_list_personlisation'
Dec 10, 2018
29e46e2
Led blinks during shutdown
Dec 10, 2018
c853cd8
Merge branch 'simple_powered_up_led'
Dec 10, 2018
d4ec46b
Merge remote-tracking branch 'upstream/master'
Dec 10, 2018
f69c6f0
Led blinks and stays on after shutdown button pushed
Dec 11, 2018
0e6fc41
Merge branch 'simple_powered_up_led'
Dec 11, 2018
4bd0880
Merge remote-tracking branch 'upstream/master'
Dec 14, 2018
b751c77
Imported changes from upstream and made comments
Dec 14, 2018
eedaeb7
Merge branch 'simple_powered_up_led'
Dec 14, 2018
16d2997
Aligned with upstream master
Dec 14, 2018
9770955
Merge branch 'master' into simple_powered_up_led
Dec 15, 2018
82cf063
Merge remote-tracking branch 'upstream/master' into simple_powered_up…
Jan 10, 2019
d0bf4ef
Reverted renaming of gpio-buttons.py to gpio.py
Jan 10, 2019
9aae284
Changed GPIO to 7
Jan 10, 2019
6c7799e
Comments
Jan 11, 2019
27d0af1
Merge remote-tracking branch 'upstream/master' into simple_powered_up…
Feb 7, 2019
2c4fa26
Began to switch to RPi.GPIO
Feb 7, 2019
4838b6c
Merge remote-tracking branch 'upstream/master' into simple_powered_up…
Mar 24, 2019
e4707c7
Added a shutdown function
Mar 24, 2019
a265213
Code cleanup and adding of handlers for holding down buttons
May 10, 2019
3aeb444
Power LED blinks and volume buttons can be held
May 14, 2019
713fed5
Fixed wrong LED variable name used
May 15, 2019
af46a6b
Channel parameter added to GPIO callbacks
May 15, 2019
7857bf9
Test bugs fixed
May 16, 2019
cefbd5c
Works with new Onelineinstaller
splitti Jan 17, 2020
8503922
Tested for fresh installations
splitti Jan 17, 2020
79b13fd
Merge pull request #729 from splitti/patch-11
MiczFlor Jan 18, 2020
cf7a370
Merge pull request #730 from splitti/patch-12
MiczFlor Jan 18, 2020
74d8690
Make it python3 ready
splitti Jan 9, 2020
b9a7de6
Merge remote-tracking branch 'upstream/master' into simple_powered_up…
topas-rec Jan 28, 2020
cc58dad
Merge remote-tracking branch 'upstream/develop' into
topas-rec Jan 28, 2020
0e5ab5e
Merge remote-tracking branch 'upstream/develop' into simple_powered_u…
topas-rec Feb 6, 2020
b0619ab
Merge remote-tracking branch 'upstream/develop' into simple_powered_u…
topas-rec Feb 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 110 additions & 60 deletions misc/sampleconfigs/gpio-buttons.py.sample
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/python3
from gpiozero import Button
import RPi.GPIO as GPIO
from signal import pause
from subprocess import check_call
import time
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
Expand All @@ -12,6 +14,10 @@ from subprocess import check_call
# or hidden magnetic switch or hacking the rfid reader as suggested here:
# https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/62
#
# 2019-05-14
# * Rewrite using RPi.GPIO for Raspberry pi zero compatibility.
# * Added power LED functionality
#
# 2018-10-31
# Added the function on holding volume + - buttons to change the volume in 0.3s interval
#
Expand All @@ -25,76 +31,120 @@ from subprocess import check_call
# 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.


def def_shutdown():
# This function takes a holding time (fractional seconds), a channel, a GPIO state and an action reference (function).
# It checks if the GPIO is in the state since the function was called. If the state
# changes it return False. If the time is over the function returns True.
def checkGpioStaysInState(holdingTime, gpioChannel, gpioHoldingState):
# Get a reference start time (https://docs.python.org/3/library/time.html#time.perf_counter)
startTime = time.perf_counter()
# Continously check if time is not over
while(holdingTime >= (time.perf_counter() - startTime)):
# Return if state does not match holding state
if(gpioHoldingState != GPIO.input(gpioChannel)):
return False
# Else: Wait
return True

# Actions that call other processes of the phoniebox (Channel Parameter needed by RPi.GPIO)
def shutdown_action(channel):
check_call("./scripts/playout_controls.sh -c=shutdown", shell=True)


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


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


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


def def_next():
def volD_action(channel):
check_call("./scripts/playout_controls.sh -c=volumedown", shell=True)
def volU_action(channel):
check_call("./scripts/playout_controls.sh -c=volumeup", shell=True)
def next_action(channel):
check_call("./scripts/playout_controls.sh -c=playernext", shell=True)


def def_prev():
def prev_action(channel):
check_call("./scripts/playout_controls.sh -c=playerprev", shell=True)


def def_rfidoff():
check_call("./scripts/playout_controls.sh -c=playerpauseforce", shell=True)


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


def def_recordstart():
def recordstart_action(channel):
check_call("./scripts/playout_controls.sh -c=recordstart", shell=True)


def def_recordstop():
def recordstop_action(channel):
check_call("./scripts/playout_controls.sh -c=recordstop", shell=True)


def def_recordplaylatest():
def recordplaylatest_action(channel):
check_call("./scripts/playout_controls.sh -c=recordplaylatest", shell=True)
def rfidoff_action():
check_call("./scripts/playout_controls.sh -c=playerpauseforce", shell=True)

# Handlers that handle special behavior of the push of a button
# When the shutdown button was held for more than 2 seconds LED flashed and afterwards
def shutdown_handler(channel):
# Detect holding of button
if True == checkGpioStaysInState(shutdownHoldTime, btn_shut, GPIO.LOW):
# Blink LED
for x in range(0, 10):
GPIO.output(led_power, x & 1)
sleep(PledBlinkTime)
# Keep LED on until power off
GPIO.output(led_power, GPIO.HIGH)
# Shutdown afterwards
shutdown_action(channel)

# When the Volume Down button was held for more than 0.3 seconds every 0.3 seconds he will lower t$
def volU_handler(channel):
# Rise volume as requested
volU_action(channel)
# Detect holding of button
while checkGpioStaysInState(volumeHoldTime, btn_volU, GPIO.LOW):
volU_action(channel)

btn_shut = Button(3, hold_time=2)
btn_vol0 = Button(13, pull_up=True)
btn_volU = Button(16, pull_up=True, hold_time=0.3, hold_repeat=True)
btn_volD = Button(19, pull_up=True, hold_time=0.3, hold_repeat=True)
btn_next = Button(26, pull_up=True)
btn_prev = Button(20, pull_up=True)
btn_halt = Button(21, pull_up=True)
# When the Volume Up button was held for more than 0.3 seconds every 0.3 seconds he will call a ra$
def volD_handler(channel):
# Rise volume as requested
volD_action(channel)
# Detect holding of button
while checkGpioStaysInState(volumeHoldTime, btn_volD, GPIO.LOW):
volD_action(channel)

# Define the used pins of the raspberry board
btn_shut = 3
btn_vol0 = 13
btn_volU = 16
btn_volD = 19
btn_next = 26
btn_prev = 20
btn_halt = 21
led_power = 12
#reco =
#play =

# Set GPIO numbering to BCM instead of board numbering
GPIO.setmode(GPIO.BCM)
# Bounce tolerance time for buttons
bouncetime = 500
volumeHoldTime = 0.3 # Seconds
shutdownHoldTime = 2 # Seconds
PledBlinkTime = 0.3 # Seconds

# Set up GPIO pins and the power led
GPIO.setup(btn_shut , GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(btn_vol0 , GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(btn_volU , GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(btn_volD , GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(btn_next , GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(btn_prev , GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(btn_halt , GPIO.IN, pull_up_down=GPIO.PUD_UP)
#GPIO.setup(btn_rfidoff, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(led_power , GPIO.OUT)
# btn_rfidoff = Button(12,pull_up=True)
# btn_reco = Button(6, pull_up=True) # Choose GPIO to fit your hardware
# btn_play = Button(12,pull_up=True) # Choose GPIO to fit your hardware

btn_shut.when_held = def_shutdown
btn_vol0.when_pressed = def_vol0
btn_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$
btn_volU.when_held = def_volU
btn_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$
btn_volD.when_held = def_volD
btn_next.when_pressed = def_next
btn_prev.when_pressed = def_prev
btn_halt.when_pressed = def_halt
# btn_rfidoff.when_pressed = def_rfidoff
# btn_reco.when_pressed = def_recordstart
# btn_reco.when_released = def_recordstop
# btn_play.when_pressed = def_recordplaylatest
# Set standard events for the buttons. Callback functions define the actions of the events (THey are defined above)
GPIO.add_event_detect(btn_shut, GPIO.FALLING, callback=shutdown_handler, bouncetime=bouncetime)
GPIO.add_event_detect(btn_vol0, GPIO.FALLING, callback=vol0_action, bouncetime=bouncetime)
GPIO.add_event_detect(btn_volU, GPIO.FALLING, callback=volU_handler, bouncetime=bouncetime)
GPIO.add_event_detect(btn_volD, GPIO.FALLING, callback=volD_handler, bouncetime=bouncetime)
GPIO.add_event_detect(btn_next, GPIO.FALLING, callback=next_action, bouncetime=bouncetime)
GPIO.add_event_detect(btn_prev, GPIO.FALLING, callback=prev_action, bouncetime=bouncetime)
GPIO.add_event_detect(btn_halt, GPIO.FALLING, callback=halt_action, bouncetime=bouncetime)
#reco.when_pressed = recordstart_action
#reco.when_released = recordstop_action
#play.when_pressed = recordplaylatest_action
#GPIO.add_event_detect(btn_rfidoff, GPIO.FALLING, callback=rfidoff_action, bouncetime=bouncetime)

# Switch on power led after boot to indicate state "on" for phoniebox
GPIO.output(led_power, GPIO.HIGH)

pause()