#!/bin/sh
. /etc/init.d/cross-common

#
# END USER: Replace this with your own application. Take care using correct Qt flags.
#
APPLICATION_PATH="/opt/ApplicationPath"
APPLICATION="ApplicationName"

# Set touch-area (Needed by VC-Qt5 applications)
#if [ $(env | grep HOSTNAME | tr -d 'HOSTNAME=') == 'vc-linux' ]; then
if [ $(cat /etc/ccsnb.conf | grep UNITTYPE | tr -d 'UNITTYPE=C000\-' | grep -o '...') -eq 135 ]; then

	if [ ! -f /usr/local/etc/evdevtouch_parameters.cfg ]
	then
		   export QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS=invertx:inverty:x_min=34:x_max=980:y_min=66:y_max=939
	else
		   export QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS=`cat /usr/local/etc/evdevtouch_parameters.cfg`
	fi
fi

# These are required to activate tslib for Qt5 applications
source /etc/profile

# Remove screensaver mode
# Commands are taken from the following website: http://www.armadeus.com/wiki/index.php?title=Framebuffer (_"http://www.armadeus.com/wiki/index.php?title=Framebuffer_")
echo 0 > /sys/class/graphics/fb0/blank
echo -e '\033[9;0]' > /dev/tty1 # '\033[9;X]' X = how many minutes until timeout, 0 = never 

#
# END USER: To enable VNC, change following value from 0 to 1
#
# There will be performance penalty when VNC is enabled even if VNC
# connection is not open.
#
USE_VNC=0
####

RESOLUTION=$(get_display_resolution)
DEFAULT_RESOLUTION="1024x768"

case "$1" in
  start)
       if [ -z $RESOLUTION ] ; then
	   RESOLUTION=$DEFAULT_RESOLUTION
       fi
       if check_feature DISPLAY || check_feature EXTDISPLAY; then
	   if [ $USE_VNC -ne 0 ]; then
	       ( $APPLICATION_PATH/$APPLICATION -platform eglfs -plugin tslib \
		   -display "Multi: transformed: VNC::size=${RESOLUTION}:depth=32:0" &> /dev/null & )
	   else
	       ( $APPLICATION_PATH/$APPLICATION -platform eglfs -plugin tslib &> /dev/null & )
	   fi
	else
	   # Display less unit supports only VNC
	   if [ $USE_VNC -ne 0 ]; then
	       ( $APPLICATION_PATH/$APPLICATION -platform eglfs -plugin tslib \
		   -display "VNC::size=${RESOLUTION}:depth=32:0" &> /dev/null & )
	   fi
	fi
	;;
  stop)
  	killall $APPLICATION
	;;
  *)
	echo $"Usage: $0 {start|stop}"
	exit 1
esac

exit $?


