Skip to content

Commit

Permalink
add seeed-voicecard manger service
Browse files Browse the repository at this point in the history
  • Loading branch information
Pillar1989 committed Feb 1, 2018
1 parent 8b84b89 commit 73ff8fe
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
84 changes: 84 additions & 0 deletions seeed-voicecard
@@ -0,0 +1,84 @@
#!/bin/bash
#
# Copyright (c) 2018 Baozhu Zuo <zuobaozhu@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

is_1a=$(i2cdetect -y 1 0x1a 0x1a | grep 1a | awk '{print $2}')
is_35=$(i2cdetect -y 1 0x35 0x35 | grep 35 | awk '{print $2}')
is_3b=$(i2cdetect -y 1 0x3b 0x3b | grep 3b | awk '{print $2}')

if [ "x${is_1a}" == "x1a" ] && [ "x${is_35}" == "x" ] ; then
echo "install 2mic"
dtoverlay seeed-2mic-voicecard
sleep 1
hw=$(aplay -l | grep seeed2micvoicec | awk '{print $2}' | sed 's/://')

cp /etc/voicecard/asound_2mic.conf /etc/asound.conf

echo "get old hw number"
old=$(cat /etc/asound.conf | grep hw: | awk 'NR==1 {print $2}' | sed 's/\"//g')

echo "replace new hw:${hw},0"
sed -i -e "s/${old}/hw:${hw},0/g" /etc/asound.conf

cp /etc/voicecard/wm8960_asound.state /var/lib/alsa/asound.state
fi

if [ "x${is_3b}" == "x3b" ] && [ "x${is_35}" == "x" ] ; then
echo "install 4mic"
dtoverlay seeed-4mic-voicecard
sleep 1
hw=$(arecord -l | grep seeed4micvoicec | awk '{print $2}' | sed 's/://')

cp /etc/voicecard/asound_4mic.conf /etc/asound.conf

echo "get slavepcm line number"
line=$(grep -n slavepcm /etc/asound.conf | awk '{print $1}' | sed 's/://')

echo "delete ${line} slavepcm hw number"
sed -i -e "${line}d" /etc/asound.conf

echo "inset slavepcm hw:${hw},0"
sed -i "${line}i slavepcm \"hw:${hw},0\"" /etc/asound.conf

cp /etc/voicecard/ac108_asound.state /var/lib/alsa/asound.state
fi

if [ "x${is_3b}" == "x3b" ] && [ "x${is_35}" == "x35" ] ; then
echo "install 6mic"
dtoverlay seeed-8mic-voicecard
sleep 1
hw=$(aplay -l | grep seeed8micvoicec | awk '{print $2}' | sed 's/://')

cp /etc/voicecard/asound_6mic.conf /etc/asound.conf

old=$(cat /etc/asound.conf | grep hw: | awk 'NR==1 {print $2}' | sed 's/\"//g')

sed -i -e "s/${old}/hw:${hw},0/g" /etc/asound.conf

cp /etc/voicecard/ac101-ok-20180119.state /var/lib/alsa/asound.state
fi

alsactl restore

#Fore 3.5mm ('headphone') jack
amixer cset numid=3 1


12 changes: 12 additions & 0 deletions seeed-voicecard.service
@@ -0,0 +1,12 @@
[Unit]
Description=Seeed Voicecard service
After=alsa-restore.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/seeed-voicecard
User=root

[Install]
WantedBy=sysinit.target

0 comments on commit 73ff8fe

Please sign in to comment.