24th Jan, 2014, 07:48 PM
Hi XBian-friends,
here's is an instruction/script by me how you can get your RPi to change resolution automatically when starting/stopping the VNC-Server.
Why it is needed?
It isn't! - But you get a way better performance with lower resolutions if you want to do something in XBMC via VNC.
Of course, you can do it even manually, but automating things is just more comfortable.
Any disadvantage?
As XBMC seems to need a restart after changing the RPi's resolution, XBMC will be restarted whenever you start or stop your
VNC-Server. This can be a disadvantage e.g. if you want to connect via VNC, but the server isn't started yet and XBMC is
currently scraping or something. But for me, it's not a real disadvantage. If someone knows how to bypass this, just shout!
How to:
All you have to do is creating following 3 files:
/etc/default/vnc-autores
DON'T FORGET TO CONFIGURE THIS FILE FOR YOUR NEEDS!
/etc/init/vnc-autores-controller.conf
/usr/local/bin/vnc-autores
and make the last one executable via:
Alternatively you can download the files...
[attachment=299]
That's it.
If you now start the vnc-server service and the automode of vnc-autores is enabled, it will change the resolution before starting and switch it back after stopping.
At any time you can also disable/enable the automode without manually editing the config file by calling:
cheers
josch
here's is an instruction/script by me how you can get your RPi to change resolution automatically when starting/stopping the VNC-Server.
Why it is needed?
It isn't! - But you get a way better performance with lower resolutions if you want to do something in XBMC via VNC.
Of course, you can do it even manually, but automating things is just more comfortable.
Any disadvantage?
As XBMC seems to need a restart after changing the RPi's resolution, XBMC will be restarted whenever you start or stop your
VNC-Server. This can be a disadvantage e.g. if you want to connect via VNC, but the server isn't started yet and XBMC is
currently scraping or something. But for me, it's not a real disadvantage. If someone knows how to bypass this, just shout!
How to:
All you have to do is creating following 3 files:
/etc/default/vnc-autores
Code:
### /etc/default/vnc-autores
# Configuration file for /usr/bin/local/vnc-autores
###
# Enable auto mode? ('vnc-autores auto' will be called when starting/stopping vnc-server)
# 0: no
# 1: yes
AUTOMODE=1
# GROUP and MODE for VNC use
# Get all supported modes by calling: tvservice -m DMT && tvservice -m CEA
VNCGROUP=DMT
VNCMODE=4
# DON'T EDIT ANYTHING BELOW HERE!
# (reserved for temporary vars)
/etc/init/vnc-autores-controller.conf
Code:
### /etc/init/vnc-autores-controller.conf
# Controller service for /usr/local/bin/vnc-autores
###
task
start on (starting vnc-server or stopped vnc-server)
script
exec /usr/local/bin/vnc-autores
exit 0
end script
/usr/local/bin/vnc-autores
Code:
#! /bin/bash
### /usr/local/bin/vnc-autores
# This script get called by /etc/init/vnc-autores-controller.conf when
# starting/stopping vnc-server service to adjust screen resolution.
###
# set name and config file
NAME=vnc-autores
CONFIGFILE=/etc/default/$NAME
# check for sudo
if [ "$UID" -ne 0 ]; then
echo "$NAME: requires root privileges (run with sudo)" >&2
exit 1
fi
# check config file
if [ -r $CONFIGFILE ]; then
. $CONFIGFILE
if ! [[ $AUTOMODE =~ ^0$|^1$ ]] || ! [[ $VNCGROUP =~ ^DMT$|^CEA$ ]] || ! [[ $VNCMODE =~ ^[0-9]+$ ]]; then
logger -s -t "ERROR" "$NAME: invalid configuration file ($CONFIGFILE)"
exit 2
fi
else
logger -s -t "ERROR" "$NAME: no configuration file found ($CONFIGFILE)"
exit 2
fi
# check for enable/disable arguments
case "$1" in
enable)
sed -i "s@AUTOMODE=0@AUTOMODE=1@" $CONFIGFILE
echo "$NAME: enabled" >&1
exit 0
;;
disable)
sed -i "s@AUTOMODE=1@AUTOMODE=0@" $CONFIGFILE
echo "$NAME: disabled" >&1
exit 0
;;
esac
# check if autores is disabled
if [ $AUTOMODE != 1 ]; then
echo "$NAME: automode is disabled, run 'vnc-autores enable' first" >&1
exit 0
fi
# get current tvservice state
STATE=$(tvservice -s)
GROUP=$(echo "$STATE" | egrep -o 'DMT|CEA')
MODE=$(echo "$STATE" | egrep -o '\([0-9]+\)'); MODE=${MODE:1:-1}
# function for restarting xbmc
restart_xbmc(){
# wait for finishing pre/post-start status
while [[ $(service xbmc status) == *-start* ]]; do
sleep 2
done
service xbmc restart > /dev/null
}
# function for going into VNC mode
go_vnc(){
if [ "$GROUP $MODE" != "$VNCGROUP $VNCMODE" ]
then
# save current tvservice state
echo "TVGROUP=$GROUP" >> $CONFIGFILE
echo "TVMODE=$MODE" >> $CONFIGFILE
# switch to VNC mode
tvservice -e "$VNCGROUP $VNCMODE" > /dev/null
restart_xbmc
echo "$NAME: switched to VNC mode" >&1
else
echo "$NAME: already in VNC mode" >&1
fi
}
# function for going into TV mode
go_tv(){
if [ "$GROUP $MODE" == "$VNCGROUP $VNCMODE" ]
then
# check if former TV settings are setted/valid
if [[ $TVGROUP =~ ^DMT|CEA$ ]] && [[ $TVMODE =~ ^[0-9]+$ ]]
then
# switch to former TV settings
sed -i '/TVGROUP=/,$d' $CONFIGFILE
tvservice -e "$TVGROUP $TVMODE" > /dev/null
else
# switch to preferred TV settings
echo "$NAME: no former TV settings found, using preferred" >&1
tvservice -p > /dev/null
fi
restart_xbmc
echo "$NAME: switched to TV mode" >&1
else
echo "$NAME: already in TV mode" >&1
fi
}
# determine mode to go
VNCSTATE=$(service vnc-server status)
if [[ "$VNCSTATE" == *starting* ]]; then
go_vnc
else
go_tv
fi
exit 0
and make the last one executable via:
Terminal
sudo chmod +x /usr/local/bin/vnc-autores
Alternatively you can download the files...
[attachment=299]
That's it.
If you now start the vnc-server service and the automode of vnc-autores is enabled, it will change the resolution before starting and switch it back after stopping.
At any time you can also disable/enable the automode without manually editing the config file by calling:
Terminal
sudo vnc-autores {disable|enable}
cheers
josch