#!/bin/sh

# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2016-present Team LibreELEC (https://libreelec.tv)

# find touchscreen device by name (substring) using evtest program

#  $ evtest
#  No device specified, trying to scan all of /dev/input/event*
#  Available devices:
#  /dev/input/event0:	Video Bus
#  /dev/input/event1:	Goodix Capacitive TouchScreen
#  Select the device event number [0-1]: 

TOUCHSCREEN_NAME="Goodix Capacitive TouchScreen"

TSLIB_TSDEVICE=$(echo 999 | evtest 2>&1 >/dev/null | awk -F':' -v TS_NAME="$TOUCHSCREEN_NAME" '$0 ~ TS_NAME {print $1; exit}')
export TSLIB_TSDEVICE

export TSLIB_PLUGINDIR=$ADDON_DIR/lib
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_CALIBFILE=/storage/.kodi/userdata/addon_data/service.touchscreen/pointercal
export TSLIB_CONFFILE=/storage/.kodi/userdata/addon_data/service.touchscreen/ts.conf

# sometimes needed
#export TSLIB_RES_X=800
#export TSLIB_RES_Y=480
