Forum

Full Version: How to switch from HDMI to composite on XBMC exit
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello!

I pretty newbi on linux, xbian and XBMC. But i'm learning Smile.

My situation: i have raspi connected to composite monitor and HDMI projector. Unfortunatly this video outputs cannot be active both at same time.
Because it's not practical to switch on a projector just for select another music or radio station ob Raspi i use composite monitor for music manipulation and when i want watch video i turn on projector and switch video output on Raspi to HDMI.

I can switch between both with following scripts executing them from ssh session from remote computer...

HDMIon.sh
Terminal

echo "Stop XBMC..."
sudo service xbmc stop

echo "Set resolution for composite output..."
sudo fbset -xres 1920 -yres 1080 -vxres 1920 -vyres 1080

echo "Turn on composite output..."
tvservice --explicit="CEA 16"

sudo service xbmc start

echo "XBMC started on HDMI output"

...and back to composite output...

COMPOSITEon
Terminal

echo "Stop XBMC..."
sudo service xbmc stop

echo "Set resolution for composite output..."
sudo fbset -xres 480 -yres 400 -vxres 480 -vyres 400

echo "Turn on composite output..."
tvservice --sdtv="PAL 16:9"

sleep 3s

sudo service xbmc start

echo "XBMC started on composite output"

I have an idea to simplify this switching this way: when i exit from XBMC, i can test the state of HDMI by execute following command...

xbian@malinca:~# tvservice -s
state: HPD low|HDMI off|PAL mode|composite CP off (0x180001), 720x576 @ 50Hz, interlaced


...with bach script i can test the output of the command and depending on state of HDMI i would start appropriate script to restart XBMC on hdmi or composite output.

This way i could switch from one output to other and viceversa with a selecting XBMC exit (or reboot, or whatever in exit menu) without need for other computer and ssh session.

So please help me with suggestions and your knowledge. How start a script on exit or reboot XBMC or even better how to customize XBMC PowerOff menu to add in list new item like 'Switch VIDEO OUTPUT' (or change the action of existing item) and on selection exit from XBMC, chage video output of Raspi and then automaticaly again start XBMC.

Thanks!
Everything you need is in the following file:
Code:
/etc/init.d/xbmc

However, we update that file without prior notice in subsequent updates.
I do not have an answer for your question but I have another two options for you
Both involved extra devices

Option 1
You would need the HDMI Switcher/Converter
With this you can out the HDMI signal into this device from where you switch between passing HDMI to your projector or RCA into your TV. There may be a device what do both simultaneously

Option 2
You would need an Android or iOS device
If you have any of those you can use remote application such as Yatse, Official XBMC Remote/iOS , Official XBMC Remote/Android, XBMC Constellation, etc
With this applications no screen is needed if you want to play just a music.

Not sure that this would be any help for you but the options are here
Thank you both for your answers. I will try without additional devices. Otherwise the Option1 is probably feasible.
About Option 2 / my family companions said "its alredy too much devices in use" we are confused!
Less is more they say Smile.
I will report if i'll be able to set the 'soft' switch.
This is the solution for me (at least first acceptable version)

Code:
# Test first run
FIRSTRUN=1

....

do_start()
{
    while :
    do
            #-------------------------------------------------------------
        # At first run we don't mess with changing video output
        if [ $FIRSTRUN -eq 0 ];
            then
        if [ $(($(tvservice -s | grep -c "HDMI off"))) -eq 1 ];
        then
            echo "...hdmi is OFF / start XBMCn HDMI output"
            sudo fbset -xres 1920 -yres 1080 -vxres 1920 -vyres 1080
            tvservice --explicit="CEA 16"
        else
            echo "...hdmi is ON / start XBMC on composite output"
            sudo fbset -xres 480 -yres 400 -vxres 480 -vyres 400
            tvservice --sdtv="PAL 16:9"
            fi
           else
                FIRSTRUN=0
       fi
       #--------------------------------------------------------------
       if [ $(($(ps -A | grep xbmc.bin | wc -l))) -eq 0 ]; then
        start-stop-daemon -c xbian -u xbian --start  --pidfile $PIDFILE --exec $DAEMON --test || return 1;
        echo $(chvt 1; start-stop-daemon -c xbian -u xbian -m --start  --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS; RETURN=$?; case $RETURN in 0 ) echo do loop.....; ;; 64 ) echo do power off.....; sudo halt ;; 66 ) echo do reboot.....; sudo reboot; ;; esac)
       fi
    done
}
A few improvements:
Code:
if [ $(($(tvservice -s | grep -c "HDMI off"))) -eq 1 ];
Can be changed to this:
Code:
if [ $(tvservice -s | grep -c "HDMI off") -eq 1 ];

That while loop is totally unnecessary. Just run your script on start and stop. And especially, without a sleep it draws a lot of system resources.

Also notice that we don't add fbset to sudoers anymore in future versions. So, readd it after the next update to Alpha 5.
The same counts for the XBMC init script. That has changed quite a bit, so make sure to make a backup.
Thanks for your hints.
I tried some options without loop but at last this one i posted worked for me.
I'm not familiar with bash scripting (yet).
The loop is there cause i don't want to exit into system console. I just want that XBMC is restarted again every time i select EXIT from the xbmc menu. After exit XBMC it restarts and appears on composite output and after next exit restarts automatically and appear on hdmi output.
I use only mouse (no keyboard) on the Raspi (in my ht room) so i cannot type into console 'xbmc start' or 'xbmc stop'.
It would helped me much (and others) if i could find in documentation some description about how the startup process of the xbian/xbmc goes (what scripts are invoked in what sequence) and the of course the stop sequence.

Anyway guys, you are doing a great job.
Hat off.
XBMC is invoked as last. As least include a sleep instead a full blown loop.
Reference URL's