Skip to content

Commit

Permalink
fixed formatting warnings (#872)
Browse files Browse the repository at this point in the history
* save used git commit hash to version file (see #828)

* added first idea

* Get rid of debconf: falling back to frontend: Readline messages while installing

* Adapt for stretch dockerfile

* Added functions for logging

* Enable Logging during the installation

* Added config file information into logging

* Updated comments

* fixed flake8 warnings

* read current commit from Github

* Consolidate install scripts (#871)

* Remove duplicate chown/chmod

* Align stretch install scripts

* Remove stretch-install-spotify.sh script

* Add info about pkg installation (#879)

* Add info about pkg installation 

Fix for #818

* Update README.md

* added missing sudo

* Update Detect rfidoff function in gpio-buttons.py (#869)

* Update Detect rfidoff function in gpio-buttons.py

Adapted the RFID-Off function to the new gpio-buttons code structure. Works fine with the hardware hack for the USB-rfid reader described here:
#62

The rfidoff event is triggered when the used gpio is pulled down.

* Added Missing "Channel" to rfidoff Action

* add empty header context to spotify requests, fixes title and cover download (#884)

Co-authored-by: fhaertig <felix.haertig@ecube.de>

* Add info how to post logging info (#882)

* fixed flake8 warnings

Co-authored-by: Kiri <kiri@sockiri01.bbn.verigy.net>
Co-authored-by: Groovylein <kiriakos.antoniadis.kiri@gmail.com>
Co-authored-by: Micz Flor <micz.flor@web.de>
Co-authored-by: Fred G <fredg02@hotmail.com>
Co-authored-by: MalteHST <40899451+MalteHST@users.noreply.github.com>
Co-authored-by: lovethisshit <2253904+lovethisshit@users.noreply.github.com>
Co-authored-by: fhaertig <felix.haertig@ecube.de>
  • Loading branch information
8 people authored Apr 11, 2020
1 parent 0027f43 commit b030ab9
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions misc/sampleconfigs/gpio-buttons.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ from time import sleep
# 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.


# 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.
Expand All @@ -41,39 +42,59 @@ def checkGpioStaysInState(holdingTime, gpioChannel, gpioHoldingState):
while(holdingTime >= (time.perf_counter() - startTime)):
# Return if state does not match holding state
if(gpioHoldingState != GPIO.input(gpioChannel)):
return False
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 vol0_action(channel):
check_call("./scripts/playout_controls.sh -c=mute", shell=True)


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 prev_action(channel):
check_call("./scripts/playout_controls.sh -c=playerprev", shell=True)


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


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


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


def recordplaylatest_action(channel):
check_call("./scripts/playout_controls.sh -c=recordplaylatest", shell=True)
def rfidoff_action(channel):
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
# 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):
if checkGpioStaysInState(shutdownHoldTime, btn_shut, GPIO.LOW) is True:
# Blink LED
for x in range(0, 10):
GPIO.output(led_power, x & 1)
Expand All @@ -82,7 +103,8 @@ def shutdown_handler(channel):
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
Expand All @@ -91,6 +113,7 @@ def volU_handler(channel):
while checkGpioStaysInState(volumeHoldTime, btn_volU, GPIO.LOW):
volU_action(channel)


# 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
Expand All @@ -99,6 +122,7 @@ def volD_handler(channel):
while checkGpioStaysInState(volumeHoldTime, btn_volD, GPIO.LOW):
volD_action(channel)


# Define the used pins of the raspberry board
btn_shut = 3
btn_vol0 = 13
Expand All @@ -109,27 +133,27 @@ btn_prev = 20
btn_halt = 21
led_power = 12
# btn_rfidoff =
#reco =
#play =
# 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
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_DOWN)
GPIO.setup(led_power , GPIO.OUT)
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_DOWN)
GPIO.setup(led_power, GPIO.OUT)


# Set standard events for the buttons. Callback functions define the actions of the events (THey are defined above)
Expand Down

0 comments on commit b030ab9

Please sign in to comment.