#!/bin/bash

TOUCHSCREEN_DEVICE="Elo Serial TouchScreen"

HAS_C_DISPLAY=`wc -l /opt/bin/customer_display.sh | cut -d" " -f1`

if [ "$HAS_C_DISPLAY" -ne 1 ]; then
  MAIN_DISPLAY=`xrandr_devices --primary`
  xinput map-to-output "$TOUCHSCREEN_DEVICE" $MAIN_DISPLAY
  xinput_calibrator --output-type xinput >> /tmp/cal.txt
  echo "sleep 3" > /opt/bin/calibrate.sh
  echo "xinput map-to-output \"$TOUCHSCREEN_DEVICE\" $MAIN_DISPLAY" >> /opt/bin/calibrate.sh
  cat /tmp/cal.txt | grep "xinput set-int-prop" >> /opt/bin/calibrate.sh
  chmod 755 /opt/bin/calibrate.sh
  rm -rf /tmp/cal.txt
else
  xinput_calibrator --output-type xinput > /tmp/cal.txt
  echo "sleep 3" > /opt/bin/calibrate.sh
  cat /tmp/cal.txt | grep "xinput set-int-prop" >> /opt/bin/calibrate.sh
  chmod 755 /opt/bin/calibrate.sh
  rm -rf /tmp/cal.txt
fi



