================================================================================
=                        Linux Touch Panel Utility Sample                      =
=                               Tp_Utils sample                                =
=                                                                              =
=                                                             TPBK(LNX)        =
=                                                             CONTEC Co.,Ltd.  =
================================================================================


◆ Contents
===========
  Introduction
  Note
  File Structure
  How to install
  How to install
  Execution
  Format of setting file
  Touch panel utility

◆ Introduction
======================
  This Readme file describes the simple operation sample program for using the
  touch panel function installed in our product in the Linux environment.
  Please use this sample program as a reference when developing your
  application.

◆ Note
======================
  ■ It is necessary to execute the sample program with root authority.

  ■ For the various commands described in this utility, do not enter any
    commands other than those described in the explanation. You may experience
    unexpected behavior or malfunctions.

  ■ When installing this sample utility, it may be necessary to make
    appropriate changes to programs, scripts, etc. in accordance with the
    operating environment.

◆ File Structure
======================
  The file of this utility (TpUtil) has the following configuration.

  ./Tp_Utils              ... Touch panel utility sample
    Makefile              ... Makefile for compiling and installing
                              (make | make install | make uninstall |
                              make service_start | make service_stop |
                              make clean)
    TpUtilsman_j.txt      ... Touch panel utility usage comment file (Ja)
    TpUtilsman_e.txt      ... Touch panel utility usage comment file (En)
    Saver.c               ... Source file of screen saver to turn off backlight
    Tpcal.c               ... Source file for touch panel calibration utility
    Tpmouse.c             ... Source file of touch panel utility
    tpctl.service         ... Tpmouse startup daemon configuration (systemd)
    tpctld.conf           ... Tpmouse startup daemon configuration (upstart)
    tpctl.sh              ... Tpmouse start script
    tpmouse.config        ... Tpmouse setting file
                             (touch input ON/OFF, beep setting, etc.)
    tpmouse.reg           ... Configuration file specified when Tpmouse starts
                             (Calibration setting, device setting)
    tpctl_detect.service  ... For script activation for dynamic support of
                             screen rotation(systemd)
    tpctl_detect.conf     ... For script activation for dynamic support of
                             screen rotation(upstart)
    tpctl_detect.sh       ... Script for dynamic correction of touch input at
                             screen rotation (sample)
    50tpctl               ... pm-utils power event hook configuration file
    tpctl_restart.service ... systemd power event hook configuration file
    tpctl_servicectl.sh   ... Service start / stop script
    getdist.sh            ... Distribution Information Confirmation Script
    Tpcal.desktop         ... Desktop entry file for Tpcal
    servicechk.sh         ... systemctl/initctl confirmation script

    /icon                 ... icon

  * When the screen is rotated by the tpctl_detect.service (systemd) and
  tpctl_detect.conf (upstart) and tpctl_detect.sh scripts (monitoring of
  xorg.x.log and reassignment to touch input screen using xinput command)
  We are responding in a simplified manner when connecting an external display.
  Depending on the environment to be configured, such as distribution or
  version, it may not work properly or there may be problems. Please change or
  correct the configuration as necessary.
  When fixing the display environment, it may not be necessary.

◆ How to install
======================
  When installing Tp_Utils separately.
  When make is executed, three executable files Tpmouse and Tpcal are created.
  Running make install will install the files on your system.
  When "make service_start" is executed, "Tpmouse" is executed, automatic
  startup settings, etc. are performed.

  * The setting of touch panel connection device in each source file in
  "tpmouse.reg" is "/dev/ttyS4". At make, device files are set according to the
  distribution and model. The contents of tpmouse.reg are also changed.

  * Check the I/O address etc. which serial device connected to the touch panel
  corresponds to the serial device under "/dev/", and change it to one suitable
  for the execution environment if necessary. After "make" and before
  "make install", you can change the configuration file by editing
  "tpmouse.reg". After executing "make install", edit "tpmouse.reg" under the
  installation location (/opt/contec/tpbkUtility). If you want to apply the
  settings after editing, please apply the settings by re-executing the daemon.

  * In tpctl_detect.sh (script for dynamic correction of touch input area
  against changes in screen state), the target display for correction of touch
  input area is set as "eDP1". Check the connection status of the display using
  the xrandr command, etc., and then change the contents of the script
  appropriately before proceeding with the installation process. Registered as
  a tpctl_detect service.

  * When installed, Tpcal (for calibration) is registered as an application.

◆ How to uninstall
======================
  When deleting the executable file, execute the "make clean" command under the
  "./Tp_Utils" directory to delete the executable file generated by the "make"
  command.
  Set stop of running daemon installed and stop of automatic start by executing
  "make service_stop".
  Running "make uninstall" will delete the files installed on the system.

◆ Execution
======================
  ■ Execution method of each program (Description of executable file)

  * [Configuration file] can be omitted.
    Each program must be run with root privileges.
  * Various implementations are performed on the premise of operation
    in the X Window environment.

    >Tpmouse [configuration file]
        If the configuration file is omitted, it starts with the default value.

    >Tpcal [configuration file]
        If the configuration file is omitted, the Tpmouse.reg file is created
        in the current directory at runtime.
        Please follow the instructions displayed.

        When executed, the calibration screen is displayed on the full screen.
        Touch the center of the displayed "+" in order (total 4 points).
        When calibration is complete, the "+" symbol is displayed to move to
        the touched position for confirmation of the calibration result.
        After calibration is completed
        Touch the inside of the [exit] frame or enter the [esc] key
        to exit without recording the result.
        Touch the inside of the [save] frame or enter the [Enter] key
        to save the result and exit.
        If you decide to cancel, enter the [esc] key to finish.

    >Saver
        It can be used equivalent to the normal screen saver for X Window.
        Please refer to the general XWindow documentation for how to use
        the screen saver for XWindow.

  * When using Tpcal, it is necessary to have Tpmouse started.
  * You can not run Tpmouse and Saver simultaneously.
  * Please calibrate as needed when rotating the screen.
  * When correcting touch panel input dynamically for screen rotation,
  please refer to tpctl_detec.sh.
  Also, in /var/log/Xorg.*.log log monitoring in some environments such as
  CentOS 6, the script may not function because the log output may not be
   performed at the time of the partial screen rotation operation.

  ■ How to use touch panel utility
    After starting Tpmouse, you need to start Tpcal in order to create a
    configuration file that contains calibration data of coordinate position
    only at the first use.
    The configuration file name to be created is the file name specified when
    Tpcal was started, and if the file name is omitted, it becomes Tpmouse.reg
    in the current directory.
    For the contents of setting file, please refer to the section of
    "Format of setting file".

◆ Format of setting file
======================
    The setting file describes the following items in the form of
    [item]=[setting value].
    If space is available or written in a different format, normal operation may
    not be possible.

        Port  Describes the device (Sial port) to connect the touch panel.
               * The initial value is /dev/ttyS4.

        Dx[0] The calibration value is stored.
        Dx[1] Tpcal writes. Do not change it manually.
        Dx[2]
        Dx[3]
        Dy[0]
        Dy[1]
        Dy[2]
        Dy[3]
        JX    Set the range of image stabilization.
        JY    The default is 30.

◆ Touch panel utility
======================

  Receive operation：
  Tpmouse receives coordinate data from the touch panel body from the serial
  port, corrects it with the set calibration value, and then issues a mouse
  event as mouse coordinates.

  Transmission operation：
  Settings for the touch panel itself, such as backlight on/off and brightness
  adjustment, can be made by sending a command to Tpmouse. You can also use the
  Tp API to send commands to Tpmouse and change the touch panel settings.
  It also supports commands that control Tpmouse behavior, such as setting
  calibration values.
  In either case, send a command to TCP port 5000 (decimal).

   * If you perform an operation that requires a high load, such as when a large
  number of accesses are made simultaneously to a port, access to the port may
  fail. It can also cause unexpected behavior.
  * If a command other than the commands described in the following Tpmouse
  command descriptions and touch panel commands is described, unintended
  operations or problems may occur.

  ■ Description of Tpmouse command
    (Format is all described in ASCII code)

    - Data transmission to touch panel body ("O" command)
      Use this command to send data to the touch panel via Tpmouse.

          Format：O[data size][data]\n

      In [data], specify the command for the touch panel with ASCII code.
      Please refer to the commentary described separately for the command
      contents of the touch panel. One byte of data can be sent at one time.
      It is necessary to repeat to send multiple data.
      The [data] part is echoed back as a return value.
      In case of error, err is returned as a return value.

        Sample command) Beep once.
            $ echo "O01b3\n" | nc localhost 5000

    - Calibration start ("K" command)
       Stop outputting mouse coordinates, including calibration values,
      and output received coordinates. Used during calibration.

        Format：K\n

      There is no return value.

    - Calibration end ("S" command)
      End output of received coordinates and return to normal mouse coordinate
      output.

        Format：S\n

      There is no return value.

    - Update calibration data ("C" command)
      Replace calibration values ​​with data in the command.
      Normally, calibration data is read from the setting file,
      but it is possible to change the setting value with this command.

          Format：C Dx[0] Dx[1] Dx[2] Dx[3] Dy[0] Dy[1] Dy[2] Dy[3]\n

        [0] to [3] are floating point notation strings of "%f" indicating
        calibration values.

    - End connection ("E" command)
      Closes the current connection and returns to the Listen state.

          Format：E\n

      On success, "E\n" is echoed back as the return value.

    - Tpmouse end ("Q" command)
      Quit Tpmouse.

          Format：Q\n

      On success, "Q\n" is echoed back as the return value.

    - Switch mouse input mode (right and left click) ("M0" command)
      Switch between right/left click on touch input.
      It will switch each time you enter a command.

          Format：M0\n

      If successful, "M\n" is echoed back as the return value.

    - Switch mouse input mode (right click) ("M1" command)
      Switch the touch input to right click.
      If it is already right click mode, it will remain as it is.

          Format：M1\n

      If successful, "M\n" is echoed back as the return value.

    - Switch mouse input mode (left click) (M2 command)
      Switch the touch input to left click.
      If it is already in left click mode, it will remain as it is.

          Format：M2\n

      If successful, "M\n" is echoed back as the return value.


  ■ Description of touch panel commands
    This section describes touch panel commands that can be sent using the
    Tpmouse data send command. The touch panel itself receives commands from the
    serial port. When receiving directly from the serial port, you will receive
    the command in hexadecimal as shown below, but if you want to send the
    command through Tpmouse, you need to send the following command to Tpmouse
    with ASCII code. If there is an interval of 10[ms] or more between
    characters in each command, it may be treated as an invalid command.
    In addition, some models may not have the function itself.
    (Format is all described in hexadecimal)

    - OPEN
      Enables touch panel input and allows other commands to be accepted.
      Normally, when Tpmouse starts, there is no need to issue this command,
      but if the display is turned off during this process, please issue one.

          Format: 0x86 0x4f 0x50 0x45 0x4e

    - Touch panel mode setting
      Switch between Drag & Drop mode and Make & Break mode.
      If the 2nd byte data is 0x00 in mode and Drag & Drop mode 0x02,
      it will be in Make & Break mode.
      (Make & Break mode is only entered where you first pressed and released.)
      The default is Drag & Drop mode.

          Format: 0x83 0x00 (for Drag&Drop)

    - Backlight ON
      Turn on the backlight of the LCD screen.

          Format: 0xa1

    - Backlight OFF
      Turn off the backlight of the LCD screen.

          Format: 0xa2

    - Brightness Up
      Increase the brightness of the backlight.
      It does not change if it reaches the maximum value.

          Format: 0xa5

    - Brightness Down
      Decrease the brightness of the backlight.
      It does not change if it reaches the minimum value.

          Format: 0xa6

    - Beep
      Beep once.

          Format: 0xb3

    - Beep effective mode
      Beep on the first Make on the touch panel.

          Format: 0xb0

    - Beep invalid mode
      Make sure that no beep sounds when operating the touch panel.

          Format: 0xb1
