-
Notifications
You must be signed in to change notification settings - Fork 400
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
Full integration of PirateAudioHAT #1112
Draft
s-martin
wants to merge
12
commits into
develop
Choose a base branch
from
Fix-audiohat-gpio
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b0817b5
Changes for 2.1 update
s-martin dbf5ace
Fix description
s-martin 47fe811
* Added GPIO control settings, when using Classic edition
s-martin a29ec89
fix bug
s-martin 81d5381
add separate Hifiberry installer script
s-martin 5095249
Merge pull request #1125 from MiczFlor/develop
s-martin 7e393fb
added README.md
s-martin a178c9a
Merge branch 'develop' into Fix-audiohat-gpio
s-martin 4e1f682
fix typo
s-martin e46f90c
differentiate between Miniamp and AMP2
s-martin 591336a
Merge branch 'develop' into Fix-audiohat-gpio
s-martin 71b5257
Merge remote-tracking branch 'remotes/upstream/develop' into Fix-audi…
s-martin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# How to setup a Hifiberry sound card | ||
|
||
These instructions are for Hifiberyy soundcards: | ||
|
||
<https://www.hifiberry.com/shop/#boards> | ||
|
||
More details and troubleshooting can be found here: <https://github.com/MiczFlor/RPi-Jukebox-RFID/wiki/HiFiBerry-Soundcard-Details>. | ||
|
||
## Automatic Script | ||
|
||
Please use `setup_Hifiberry.sh` script to set it up to work with Phoniebox. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/usr/bin/env bash | ||
|
||
HOME_DIR="/home/pi" | ||
JUKEBOX_HOME_DIR="${HOME_DIR}/RPi-Jukebox-RFID" | ||
|
||
TYPE=$1 | ||
|
||
if [[ -n "$TYPE" ]]; then | ||
echo "Configuring Hifiberry ${TYPE} sound card" | ||
else | ||
echo "Error: please pass miniamp or amp2 to script." | ||
exit -1 | ||
fi | ||
|
||
question() { | ||
local question=$1 | ||
read -p "${question} (y/n)? " choice | ||
case "$choice" in | ||
y|Y ) ;; | ||
n|N ) exit 0;; | ||
* ) echo "Error: invalid" ; question ${question};; | ||
esac | ||
} | ||
|
||
printf "Please make sure that the Hifiberry is connected...\n" | ||
question "Continue" | ||
|
||
printf "Adding settings to /boot/config.txt...\n" | ||
if [[ ! -f /boot/config.txt.bak ]]; then | ||
sudo cp /boot/config.txt /boot/config.txt.bak | ||
fi | ||
|
||
if ! sudo grep -qe "dtoverlay=hifiberry-dac" /boot/config.txt; then | ||
echo "dtoverlay=hifiberry-dac" | sudo tee -a /boot/config.txt > /dev/null | ||
fi | ||
|
||
printf "Adding settings to /etc/asound.conf...\n" | ||
# Create backup of /etc/asound.conf if it already exists | ||
if [[ -f /etc/asound.conf && ! -f /etc/asound.conf.bak ]]; then | ||
sudo cp /etc/asound.conf /etc/asound.conf.bak | ||
fi | ||
|
||
# Do not add, but replace content if file already exists | ||
sudo tee /etc/asound.conf << EOF > /dev/null | ||
pcm.hifiberry { | ||
type softvol | ||
slave.pcm "plughw:CARD=sndrpihifiberry,DEV=0" | ||
control.name "Master" | ||
control.card 1 | ||
} | ||
pcm.!default { | ||
type plug | ||
slave.pcm "hifiberry" | ||
} | ||
ctl.!default { | ||
type hw | ||
card 1 | ||
} | ||
EOF | ||
|
||
# Create backup of /etc/mpd.conf if it already exists | ||
if [[ -f /etc/mpd.conf && ! -f /etc/mpd.conf.bak ]]; then | ||
sudo cp /etc/mpd.conf /etc/mpd.conf.bak | ||
fi | ||
|
||
printf "Add hifiberry as audio_output in /etc/mpd.conf...\n" | ||
# Only add, if it does not exist already | ||
if ! sudo grep -qe "HiFiBerry DAC+ Lite" /etc/mpd.conf; then | ||
sudo sed -i "/# An example of an ALSA output:/ r /dev/stdin" /etc/mpd.conf <<'EOG' | ||
audio_output { | ||
enabled "yes" | ||
type "alsa" | ||
name "HiFiBerry DAC+ Lite" | ||
device "hifiberry" | ||
auto_resample "no" | ||
auto_channels "no" | ||
auto_format "no" | ||
dop "no" | ||
} | ||
EOG | ||
else | ||
printf "/etc/mpd.conf is already configured. Skipping...\n" | ||
fi | ||
|
||
printf "Set mixer_control name in /etc/mpd.conf...\n" | ||
mixer_control_name="Master" # for miniamp | ||
|
||
if [ "${TYPE}" == "amp2" ]; then | ||
# see https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/1198#issuecomment-750757106 | ||
mixer_control_name="Digital" | ||
fi | ||
|
||
sudo sed -i -E "s/^(\s*mixer_control\s*\")[^\"]*(\"\s*# optional)/\1\\${mixer_control_name}\2/" /etc/mpd.conf | ||
|
||
printf "You should reboot later to apply the settings.\n" |
This file contains 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
13 changes: 13 additions & 0 deletions
13
components/audio/PirateAudioHAT/phoniebox-pirateaudio-display.service.sample
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=Phoniebox Pirate Audio Display Service | ||
After=network.target phoniebox-rfid-reader.service | ||
|
||
[Service] | ||
User=pi | ||
Group=pi | ||
Restart=always | ||
WorkingDirectory=/home/pi/RPi-Jukebox-RFID | ||
ExecStart=/home/pi/RPi-Jukebox-RFID/components/audio/PirateAudioHAT/pirate_audio_display.py | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from PIL import Image | ||
from PIL import ImageDraw | ||
from PIL import ImageFont | ||
from mpd import MPDClient | ||
import time | ||
|
||
import ST7789 | ||
|
||
|
||
MESSAGE = "Hello World! How are you today?" | ||
|
||
# Create ST7789 LCD display class. | ||
disp = ST7789.ST7789( | ||
port=0, | ||
cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CSB_BACK or BG_SPI_CS_FRONT | ||
dc=9, | ||
backlight=19, # 18 for back BG slot, 19 for front BG slot. | ||
spi_speed_hz=80 * 1000 * 1000 | ||
) | ||
|
||
# Initialize display. | ||
disp.begin() | ||
|
||
WIDTH = disp.width | ||
HEIGHT = disp.height | ||
|
||
|
||
img = Image.new('RGB', (WIDTH, HEIGHT), color=(0, 0, 0)) | ||
|
||
draw = ImageDraw.Draw(img) | ||
|
||
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 30) | ||
|
||
size_x, size_y = draw.textsize(MESSAGE, font) | ||
|
||
text_x = disp.width | ||
text_y = (80 - size_y) // 2 | ||
|
||
t_start = time.time() | ||
|
||
while True: | ||
x = (time.time() - t_start) * 100 | ||
x %= (size_x + disp.width) | ||
draw.rectangle((0, 0, disp.width, 80), (0, 0, 0)) | ||
draw.text((int(text_x - x), text_y), MESSAGE, font=font, fill=(255, 255, 255)) | ||
disp.display(img) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# PirateAudioHAT related for spotify edition | ||
# You need to install these with `sudo python3 -m pip install --upgrade --force-reinstall -q -r requirements-mopidy.txt` | ||
|
||
Mopidy-PiDi | ||
mopidy-raspberry-gpio | ||
pidi-display-pil | ||
pidi-display-st7789 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
# PirateAudioHAT related requirements | ||
# PirateAudioHAT related requirements (for classic edition) | ||
# You need to install these with `sudo python3 -m pip install --upgrade --force-reinstall -q -r requirements.txt` | ||
|
||
Mopidy-PiDi | ||
pidi-display-pil | ||
pidi-display-st7789 | ||
mopidy-raspberry-gpio | ||
st7789 |
This file contains 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
34 changes: 34 additions & 0 deletions
34
misc/sampleconfigs/gpio_settings.ini.pirate-audio-hat.sample
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[DEFAULT] | ||
enabled: True | ||
|
||
[PlayPause] | ||
enabled: True | ||
Type: Button | ||
Pin: 5 | ||
pull_up: True | ||
bouncetime: 250 | ||
functionCall: functionCallPlayerPause | ||
|
||
[VolumeUp] | ||
enabled: True | ||
Type: Button | ||
Pin: 20 | ||
pull_up: True | ||
bouncetime: 250 | ||
functionCall: functionCallVolU | ||
|
||
[VolumeDown] | ||
enabled: True | ||
Type: Button | ||
Pin: 6 | ||
pull_up: True | ||
bouncetime: 250 | ||
functionCall: functionCallVolD | ||
|
||
[NextSong] | ||
enabled: True | ||
Type: Button | ||
Pin: 16 | ||
pull_up: True | ||
bouncetime: 250 | ||
functionCall: functionCallPlayerNext |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need also to add pin 24, see pimoroni/pirate-audio#63 (comment)