Skip to content

Commit

Permalink
Merge pull request #15 from deckerego/i2s_audio
Browse files Browse the repository at this point in the history
I2S Audio Support
  • Loading branch information
deckerego authored Jan 14, 2017
2 parents f47b0ba + ba67fba commit 30803be
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 6 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
34 changes: 34 additions & 0 deletions debian/python-hackclock.postinst
Original file line number Diff line number Diff line change
@@ -1,3 +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

# Install those Python modules that only exist via pip
echo "Installing missing Python modules..."
pip install -r /usr/share/doc/hack-clock/requirements.txt

# 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 $BOOT_CONFIG
fi

# 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
echo "dtoverlay=i2s-mmap" | sudo tee -a $BOOT_CONFIG
fi

# 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

echo "Please reboot your Raspberry Pi!"
33 changes: 33 additions & 0 deletions etc/asound.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
pcm.hifiberry {
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def all_files(newroot, oldroot):
return fdtuples

base_data_files = [
('/etc', ['etc/hack-clock.conf']),
('/etc', ['etc/hack-clock.conf', 'etc/asound.conf']),
('/etc/init.d', ['etc/init.d/hack-clock']),
('/etc/default', ['etc/default/hack-clock']),
('/usr/share/doc/hack-clock', ['README.md', 'LICENSE', 'MANIFEST', 'requirements.txt'])
Expand Down

0 comments on commit 30803be

Please sign in to comment.