Skip to content

Commit

Permalink
Automatic installation of the hifiberry module and software volume co…
Browse files Browse the repository at this point in the history
…ntrol
  • Loading branch information
deckerego committed Jan 14, 2017
1 parent 94f9aa6 commit ba67fba
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 37 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ Installation

I'm assuming that you are starting with the Raspian Minimal Linux distribution. NOOBS or the like also works, but Raspian Minimal is small enough to fit on a 2GB microSD card. To install the hack-clock distribution on top of it:

1. Make sure your Raspberry Pi is up to date with the latest packages & firmware.
2. Enable I2C as described in Adafruit's tutorial at https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c
1. Make sure your Raspberry Pi is up to date with the latest packages & firmware with `sudo apt-get update; sudo apt-get dist-upgrade`
2. Enable I2C by executing `sudo raspi-config` as described in Adafruit's tutorial: https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c
3. Add the necessary Python and GStreamer dependencies using `sudo apt-get install wiringpi python-setuptools python-pip python-dev python-dateutil python-smbus gstreamer0.10-x gstreamer-tools gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-bad python-gst0.10`
4. Install hack-clock via `dpkg -i http://hackclock.deckerego.net/downloads/python-hackclock_2.0-beta-1_all.deb`
5. Install hack-clock's Python dependencies using `sudo pip install -r /usr/share/doc/hack-clock/requirements.txt`
6. Tweak `/etc/hack-clock.conf` and `/etc/default/hack-clock` to fit your needs (GPIO pins, correct weather station, etc.)
7. Start the app by executing `sudo service hack-clock start`
5. Tweak `/etc/hack-clock.conf` and `/etc/default/hack-clock` to fit your needs (GPIO pins, correct weather station, etc.)
6. Reboot your Pi or start the app by executing `sudo service hack-clock start`


Usage
Expand Down
53 changes: 25 additions & 28 deletions debian/python-hackclock.postinst
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
#!/bin/bash

BOOT_CONFIG=/boot/config.txt
MOD_CONFIG=/etc/modules

# Fix ownership in home directory after installing
chown -R pi:pi /home/pi/hack-clock

# Also modify /boot/config.txt
# Turn off audio and add dtoverlay=hifiberry-dac
# As well as dtoverlay=i2s-mmap
CONFIG=/boot/config.txt
# Install those Python modules that only exist via pip
echo "Installing missing Python modules..."
pip install -r /usr/share/doc/hack-clock/requirements.txt

if [ -e $CONFIG ] && grep -q "^dtoverlay=hifiberry-dac$" $CONFIG; then
echo "dtoverlay already active"
# Set the hifiberry-dac i2s module
echo "Installing I2S audio..."
if [ -e $BOOT_CONFIG ] && grep -q "^dtoverlay=hifiberry-dac$" $BOOT_CONFIG; then
echo "hifiberry already installed"
else
echo "dtoverlay=hifiberry-dac" | sudo tee -a $CONFIG
ASK_TO_REBOOT=true
echo "dtoverlay=hifiberry-dac" | sudo tee -a $BOOT_CONFIG
fi

if [ -e $CONFIG ] && grep -q -E "^dtparam=audio=on$" $CONFIG; then
bcm2835off="no"
newline
echo "Disabling default sound driver"
sudo sed -i "s|^dtparam=audio=on$|#dtparam=audio=on|" $CONFIG &> /dev/null
if [ -e $LOADMOD ] && grep -q "^snd-bcm2835" $LOADMOD; then
sudo sed -i "s|^snd-bcm2835|#snd-bcm2835|" $LOADMOD &> /dev/null
fi
ASK_TO_REBOOT=true
elif [ -e $LOADMOD ] && grep -q "^snd-bcm2835" $LOADMOD; then
bcm2835off="no"
newline
echo "Disabling default sound module"
sudo sed -i "s|^snd-bcm2835|#snd-bcm2835|" $LOADMOD &> /dev/null
ASK_TO_REBOOT=true
# Enable (optional) i2s-mmap to get rid of popping and set volumes
if [ -e $BOOT_CONFIG ] && grep -q "^dtoverlay=i2s-mmap$" $BOOT_CONFIG; then
echo "i2s-mmap already installed"
else
newline
echo "Default sound driver currently not loaded"
bcm2835off="yes"
echo "dtoverlay=i2s-mmap" | sudo tee -a $BOOT_CONFIG
fi

speaker-test -l5 -c2 -t wav
# Make sure old audio is disabled
if [ -e $BOOT_CONFIG ] && grep -q -E "^dtparam=audio=on$" $BOOT_CONFIG; then
echo "Commenting out dtparam=audio=on in $BOOT_CONFIG"
sudo sed -i "s|^dtparam=audio=on$|#dtparam=audio=on|" $BOOT_CONFIG &> /dev/null
elif [ -e $MOD_CONFIG ] && grep -q "^snd-bcm2835" $MOD_CONFIG; then
echo "Commenting out snd-bcm2835 in $MOD_CONFIG"
sudo sed -i "s|^snd-bcm2835|#snd-bcm2835|" $MOD_CONFIG &> /dev/null
fi

amixer set PCM -- 85%
echo "Please reboot your Raspberry Pi!"
35 changes: 31 additions & 4 deletions etc/asound.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
pcm.!default {
type hw card 0
pcm.hifiberry {
type hw card 0
}
ctl.!default {
type hw card 0

pcm.!default {
type plug
slave.pcm "softvol"
}

pcm.dmixer {
type dmix
ipc_key 1024
slave {
pcm "hifiberry"
channels 2
}
}

ctl.dmixer {
type hw
card 0
}

pcm.softvol {
type softvol
slave {
pcm "dmixer"
}
control {
name "Master"
card 0
}
}
3 changes: 3 additions & 0 deletions etc/default/hack-clock
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ BUTTON_BCM_PIN=(23 24)

# The pins (using the Broadcom numbering scheme) to be used for switches (output)
SWITCH_BCM_PIN=(25)

# Volume level to feed to ALSA SoftVol
MASTER_VOLUME='75%'
5 changes: 5 additions & 0 deletions etc/init.d/hack-clock
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ SCRIPTNAME=/etc/init.d/$NAME
# and status_of_proc is working.
. /lib/lsb/init-functions

set_volume()
{
amixer set Master -- "$MASTER_VOLUME"
}

#
# Some dependencies can only be provided by PIP, check them
#
Expand Down

0 comments on commit ba67fba

Please sign in to comment.