rgro wrote: 
> Chill...
> 
> Could you please run through a "how-to" step-by-step implementation of
> this from ground zero.

The original steps are documented on the piCorePlayer website :
https://docs.picoreplayer.org/projects/autostart-squeezelite-from-usb-dac/
The process is broadly similar, but I have added a second rule (Step 2)
to kill squeezelite when the DAC is powered off.

1) Follow step 1 in the picoreplayer instructions, to determine the
Vendor and Product ids for your DAC

2) Using whatever tools you are comfortable with, create a file
/etc/udev/rules.d/10-DAC.rules, with the following content.  Replace
'xxxx' with the Vendor and Product ids you determined in step 1.

Code:
--------------------
    SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="xxxx", 
ATTR{idProduct}=="xxxx", RUN+="/home/tc/SQLITE-control.sh restart $kernel"
  SUBSYSTEM=="usb", ACTION=="remove", RUN+="/home/tc/SQLITE-control.sh stop 
$kernel"
  
--------------------


3) Do step 5 from the picoreplayer instructions to make sure that this
rules file survives a reboot.

4) Create a file SQLITE-control.sh in your home directory (/home/tc/)
and paste the following text into it.    Replace 'xxxx' in the 'find'
section with the Vendor and Product ids you determined in step 1.  Once
you have saved this file, make it executable with 'chmod +x
SQLITE-control.sh' from the command line.

Code:
--------------------
    #!/bin/sh
  
  # Script to be used by udev rules that detect when a USB DAC is connected or 
disconnected,
  # in order to start or stop Squeezelite
  # $1 is the script option: 'restart', 'stop' or 'find'
  # $2 is the kernel name ($kernel) that is generated by the udev event
  #    It is used to match a 'removed' USB device against the device assigned 
when the DAC was inserted
  # The 'find' option is used at boot to detect which device the DAC is 
connected to, 
  # in the case that the DAC is up before squeezelite attempts to start.
  
  # The associated udev rules are:
  # SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="xxxx", 
ATTR{idProduct}=="xxxx", RUN+="/home/tc/SQLITE-control.sh restart $kernel"
  # SUBSYSTEM=="usb", ACTION=="remove", RUN+="/home/tc/SQLITE-control.sh stop 
$kernel"
  
  case $1 in
        restart ) # restart squeezelite when DAC is inserted/powered up
                # output the device '$kernel' name to a text file, so that it 
can be used to check against USB 'remove' events
                kername=$2
                echo $kername > /tmp/DACdevice.txt
                echo "DAC detected on $kername" >> /var/log/pcp_DAC.log
                /home/tc/restartSQLITE.sh &
                ;;
        stop ) # stop squeezelite when DAC is removed/powered down
                # compare $kernel device name to the one created by this script 
when the DAC was inserted/powered up
                startname=$(cat /tmp/DACdevice.txt)
                stopname="$2"
                # stop squeezelite if names match
                if [ $stopname == $startname ]; then
                        echo "$stopname removed" >> /var/log/pcp_DAC.log
                        sudo /usr/local/etc/init.d/squeezelite stop >> 
/var/log/pcp_DAC.log
                fi
                ;;
        find ) # create the file with the kernel name
                idVendor="08bb"
                idProduct="2704"
                echo "Searching for DAC with idVendor=$idVendor and 
idProduct=$idProduct in dmesg" >> /var/log/pcp_DAC.log
                dacdev=$(dmesg | grep -m 1 "idVendor=$idVendor, 
idProduct=$idProduct" | awk -F usb {'print $2'} | awk -F : {'print $1'})
                echo $dacdev > /tmp/DACdevice.txt
                if [ -z $dacdev ]; then
                        echo "DAC not detected" >> /var/log/pcp_DAC.log
                else
                        echo "DAC detected on $dacdev" >> /var/log/pcp_DAC.log
                fi
                ;;
  esac
  
--------------------


5) Create a file restartSQLITE.sh in your home directory (/home/tc/) and
paste the following text into it.   Once you have saved this file, make
it executable with 'chmod +x restartSQLITE.sh' from the command line.

Code:
--------------------
    #!/bin/sh
  
  attempts=5 # number of tries
  count=$attempts 
  while [ "$(sudo /usr/local/etc/init.d/squeezelite status)" == "Squeezelite 
not running." ]; do
        if [ $((count--)) -le 0 ]; then
                echo  "Squeezelite failed to initialize within $attempts 
attempts." >> /var/log/pcp_DAC.log
                exit 1 
        fi
        echo  "Attempting to start squeezelite" >> /var/log/pcp_DAC.log
        sudo /usr/local/etc/init.d/squeezelite restart >> /var/log/pcp_DAC.log
        sleep 1 # time interval (seconds) between tries
  done
  
--------------------


6) Add a User Command (at the bottom of the 'Tweaks' page in the pCP
browser interface).

Code:
--------------------
    /home/tc/SQLITE-control.sh find
--------------------


7) Backup and reboot: pcp br

After a reboot, you can see what the scripts are doing by looking at the
DAC log file in the pCP browser interface (Main Page -> Diagnostics ->
Logs).
If the DAC is powered up when the RPi is booted, you should see a
message of the form:

Code:
--------------------
    Searching for DAC with idVendor=xxxx and idProduct=xxxx in dmesg
  DAC detected on  1-1.3.1
  
--------------------

If it wasn't powered on at boot, the message will just say 'DAC not
detected'

After that you should see messages each time the DAC is powered on or
off (you'll need to press the 'Show' button each time you want to
refresh it).

I'm sure I'll have missed a step in the instructions, so give it a try
and ask is something goes wrong.


------------------------------------------------------------------------
chill's Profile: http://forums.slimdevices.com/member.php?userid=10839
View this thread: http://forums.slimdevices.com/showthread.php?t=113661

_______________________________________________
unix mailing list
unix@lists.slimdevices.com
http://lists.slimdevices.com/mailman/listinfo/unix

Reply via email to