mtouch

Posted by Underdog Linux on October 30, 2023

mtouch 服务启动touch功能的资源管理器并加载配置。

语法

mtouch [-c configfile] [-d] [-q queuebool] [-r] [-U user] [-v]

运行于

QNX Neutrino

选项

-c configfile

指定 mtouch 资源管理器(驱动程序)的配置文件的位置。 如果未指定 -c 选项,则 mtouch 使用 /etc/system/config/mtouch.conf 作为默认值。

-d 启用调试模式。 这允许您在不运行服务的情况下运行此驱动程序。如果您在详细(verbose)模式下运行,并且想要查看带有触摸驱动程序坐标信息的 slog2info,则使用此选项非常有用。

-q 禁用触摸事件队列。 这意味着当您触摸显示屏时,您不会看到任何触摸事件。 默认情况下,此值设置为 1(已启用)。 若要禁用事件队列,请将其设置为 0(零)。

-r 启用资源管理器,以便可以在不使用Screen API 的情况下访问与触摸事件关联的信息。例如:

mtouch -rd
ls /dev/mtouch/

touch_display0   

与触摸驱动程序关联的此信息(例如touch_display0)显示为 mtouch_event_t 类型的数据结构。这些信息包括:

  • event type
  • timestamp
  • sequence identifier
  • contact identifier
  • x coordinate
  • y coordinate
  • width
  • height
  • orientation
  • pressure
  • contact type
  • selected buttons

有关详细信息,请参阅《Input Events Library Reference》中的mtouch_event

若要检索触摸事件信息,可以打开资源管理器并读取文件描述符。例如:

... 
int fd, nCount;
mtouch_event_t touch_packet;
... 
fd = open("/dev/mtouch/touch_display0", O_RDWR | O_NONBLOCK);
... 
while (1)
{
    nCount = read(fd, &touch_packet, sizeof(touch_packet));
    if (0 >= nCount)
    {
        delay(100);
    }
    else
    {
        printf("Timestamp: %llu  Sequence ID: %u  Contact ID:%d X:%u, Y:%u Event: ",
               touch_packet.timestamp,
               touch_packet.seq_id,
               touch_packet.contact_id,
               touch_packet.x,
               touch_packet.y);

        switch (touch_packet.event_type)
        {
        case INPUT_EVENT_MTOUCH_TOUCH:
            printf("Touch event.\n");
            break;
        case INPUT_EVENT_MTOUCH_MOVE:
            printf("Move event.\n");
            break;
        case INPUT_EVENT_MTOUCH_RELEASE:
            printf("Release event.\n");
            break;
        default:
            printf("Other...\n");
            break;
        }
    }
}
return 0;
...

-V 启用详细模式。 在此模式下,将打印每个事件的坐标,其中包括输入区域的 x、y 坐标和映射到显示器的坐标。 此外,宽度和高度与触摸区域的大小有关,前提是硬件支持它。 例如,1 表示小区域(如小指),而不是较大的区域(如拇指)。

下面是用户在显示屏上的坐标(大约 20(x 值)和 400(y 值))处提供触摸输入的事件的样子:

Nov 09 15:38:16  5  9   200 touch_display[INFO]: x 21 y 400 width 1 height 1
Nov 09 15:38:16  5  9   200 touch_display[INFO]: x 22 y 410 width 1 height 1
Nov 09 15:38:16  5  9   200 touch_display[INFO]: x 19 y 413 width 1 height 1
Nov 09 15:38:16  5  9   200 touch_display[INFO]: x 23 y 402 width 1 height 1
Nov 09 15:38:16  5  9   200 touch_display[INFO]: x 20 y 401 width 1 height 1

描述

mtouch 服务启动 mtouch.conf 文件中指定的触摸驱动程序。 若要运行此服务,必须首先启动Screen。 其他依赖项可能因触摸设备而异。

例子

使用使用基于 USB 控制器的人机接口设备 (HID):

  1. 您需要确保 mtouch 所依赖的共享对象和配置文件包含在您的system image中。例如:
    • libmtouch-hid.so.1
    • scaling.conf
    • mtouch.conf

有关如何确定需要哪些共享对象的更多信息,请参阅《Building Embedded Systems guide》中的 Shared libraries部分。

  1. 在目标系统上,通常需要先启动 USB 驱动程序,然后才能使用触摸。例如:
io-usb-otg -d hcd-dm816x-mg ioport=0x47401c00,irq=19
  1. 启动Screen
screen
  1. 启动touch
mtouch

Calibrating touch
您可以使用几种不同的方法校准屏幕。

Scaling configuration file
缩放配置文件是 mtouch 服务使用的自由格式 ASCII 文本文件。

Touch configuration file
mtouch 部分指定应用平台支持的触摸设备(也称为多点触控设备的 mtouch 设备)的配置。

Touch filters
可以通过指定与每个触摸驱动程序相关的筛选器来指定进一步的配置。




附录

mtouch_event_t

包含INPUT_CLASS_MTOUCH输入事件的通用详细信息的结构

语法

#include <input/event_types.h>
typedef struct mtouch_event  mtouch_event_t;

libinputevents

描述

mtouch_event结构表示类 INPUT_CLASS_MTOUCH 的所有输入事件共有的信息。

每当发生INPUT_CLASS_MTOUCH事件时,输入设备驱动程序都会提供此信息。

mtouch_event

包含INPUT_CLASS_MTOUCH输入事件的通用详细信息的结构

语法

#include <input/>

typedef struct mtouch_event {
    input_event_e event_type;
    uint64_t timestamp;
    uint32_t seq_id;
    uint32_t contact_id;
    int32_t x;
    int32_t y;
    uint32_t width;
    uint32_t height;
    uint32_t orientation;
    uint32_t pressure;
    uint32_t contact_type;
    uint32_t select;
} mtouch_event_t;

input_event_e event_type INPUT_CLASS_MTOUCH事件的事件类型。

uint64_t timestamp INPUT_CLASS_MTOUCH事件发生的时间戳,基于实时时钟。

uint32_t seq_id 事件的序列号;每次发生新的触摸相关事件时,seq_id都会递增

uint32_t contact_id 多个触摸触点的出现顺序。

int32_t x 事件的 x 屏幕位置(以像素为单位)。

int32_t y 事件的 y 屏幕位置(以像素为单位)。

uint32_t width 触摸区域的宽度(以像素为单位)。

uint32_t height 触摸区域的高度(以像素为单位)。

uint32_t orientation 触点的方向。

uint32_t pressure 触摸触点的压力,范围从 0 到 2^32 - 1。

uint32_t contact_type 触点类型。 有效的类型是 contact_type_e

uint32_t select 所选按钮。

libinputevents

描述

mtouch_event结构表示类 INPUT_CLASS_MTOUCH 的所有输入事件共有的信息。 每当发生INPUT_CLASS_MTOUCH事件时,输入设备驱动程序都会提供此信息。

contact_type_e

INPUT_CLASS_MTOUCH事件的触点类型

语法

#include <input/event_types.h>

typedef enum {
    CONTACT_TYPE_FINGER = 0,
    CONTACT_TYPE_STYLUS = 1,
    CONTACT_TYPE_HOVERING = 2,
    CONTACT_TYPE_GLOVE = 3,
    CONTACT_TYPE_LARGE = 4
} contact_type_e;

CONTACT_TYPE_FINGER 手指触摸(默认)。

CONTACT_TYPE_STYLUS 触控笔触摸。

CONTACT_TYPE_HOVERING 悬停手指。

CONTACT_TYPE_GLOVE 手套触摸

CONTACT_TYPE_LARGE 大物体

libinputevents