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


◆ Contents
===========
  Introduction
  Note
  File Structure
  How to install
  How to uninstall
  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.

  ■ It does not support screen rotation or operation in a multi-display
     environment. If you wish to use it, please make appropriate changes to the
     source code, etc.

◆ 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)
    Tpcal_gtk3.c          ... touch panel calibration utility (gkt3)
    Tpcal.c               ... touch panel calibration utility (xorg)
    Tpmouse.c             ... touch panel utility
    tpctl.service.in      ... Tpmouse startup daemon configuration (systemd)
    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_restart.service ... systemd power event hook configuration file
    Tpcal.desktop.in      ... Desktop entry file for Tpcal

    /icon                 ... icon

◆ 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". When "make" is executed, the device file
    settings and the contents of tpmouse.reg are also changed depending on the
    distribution and model.

  * Check whether the serial device connected to the touch panel corresponds to
    one of the serial devices under /dev/ using the I/O address, etc. You need
    to change the settings to suit your execution environment. After
    installation, edit the configuration file (tpmouse.reg) in the installation
    destination(/opt/contec/tpbkUtility or other) as appropriate. After editing,
    please restart the daemon(tpctl) to reflect the settings.

  * After installation, Tpcal (for calibration) will be registered as a desktop
    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, a Tpmouse.reg file will be created
        and saved 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 complete, press the [exit] button or enter the
        [esc] key to exit without saving. Press the [save] button or enter the
        [Enter] key to save the results and exit. If you want to cancel the
        calibration, please enter the [esc] key.
        * Screen rotation and multi-screen operation are not supported.
        * It is not supported when using Tpmouse for mouse input.

  * When using Tpcal, it is necessary to have Tpmouse started.

◆ 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 (Serial port) to connect the touch panel.
               * The initial value is /dev/ttyS2.

        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
