#!/bin/sh
echo "xinput --set-prop \"eGalaxTouch Virtual Device for Single\" 113 0" > /tmp/.xinitrc
# touchscreen controller
touch_dev=`cat /tmp/hw.config | grep touchscreen`
if test $touch_dev = "touchscreen=egalax1"
then
        echo "eGalax Inc. touchscreen Found. Loading Configuration."
##      cat /home/pi/hwconf/egalax1_cal >  /usr/share/X11/xorg.conf.d/01-input.conf
##      cat /home/pi/hwconf/egalax1_cal >  /usr/share/X11/xorg.conf.d/99-calibration.conf
fi
if test $touch_dev = "touchscreen=ilitek-tp"
then
##         echo "eGalax Inc. touchscreen Found. Loading Configuration." > /dev/kmsg
        cat /home/pi/hwconf/ilitek-tp_cal >  /usr/share/X11/xorg.conf.d/01-input.conf
        cat /home/pi/hwconf/ilitek-tp_cal >  /usr/share/X11/xorg.conf.d/99-calibration.conf
fi

if test $touch_dev = "touchscreen=egalax2"
then
        # configuration of STP-RAP45U2U-S series touch controller
##         echo "eGalax Inc. USB TouchController Found. Loading Configuration." > /dev/kmsg
        cat /tmp/eGTouch*.log | grep "Type:4WP1, Model:ETR4000 , Version:2.19, IAP:1" > /tmp/hw.subconfig
        if test -s /tmp/hw.subconfig
        then
        cat /tmp/hw.subconfig > /tmp/egalax2.type
        echo "xinput --set-prop \"eGalax Inc. USB TouchController Pen\" 113 0" >> /tmp/.xinitrc
        echo "xinput --set-prop \"eGalax Inc. USB TouchController\" 113 1" >> /tmp/.xinitrc
        else
        echo "xinput --set-prop \"eGalaxTouch Virtual Device for Single\" 113 1" > /tmp/.xinitrc
        echo "xinput --set-prop \"eGalax Inc. USB TouchController Pen\" 113 0" >> /tmp/.xinitrc
        echo "xinput --set-prop \"eGalax Inc. USB TouchController\" 113 0" >> /tmp/.xinitrc
        fi
        echo "## not used by egalax2" > /usr/share/X11/xorg.conf.d/01-input.conf
        echo "## not used by egalax2" > /usr/share/X11/xorg.conf.d/99-calibration.conf
fi

cat /home/pi/.xinitrc >> /tmp/.xinitrc
