简体   繁体   English

Android:以编程方式检测设备是否已连接硬件触摸屏

[英]Android: Programmatically detect if device has hardware touchscreen connected

I need to write a script to detect if the physical touchscreen is connected to my Android device at boot time. 我需要编写一个脚本来检测物理触摸屏是否在启动时连接到我的Android设备。 I tried to list the content of the folder /dev/input via adb and I obtain the following output: 我试图通过adb列出文件夹/dev/input的内容,并获得以下输出:

root@q88:/dev/input # ls
event0
event1
event2
event3
event4
mice

If I am not mistaken, event0 identifies the touchscreen, but it is visible in both case the touchscreen is connected or not. 如果我没有弄错的话, event0识别触摸屏,但在触摸屏连接与否的情况下都可以看到。
Is there a way to detect if the touchscreen is connected to the device? 有没有办法检测触摸屏是否连接到设备?

Thanks in advance. 提前致谢。

You can read /proc/bus/input/devices to get details of your existing input devices . 您可以读取/proc/bus/input/devices获取现有输入设备的详细信息

Depending on your hardware's name, you could do something like that and check if there is any output: 根据您的硬件名称,您可以执行类似的操作并检查是否有任何输出:

cat /proc/bus/input/devices | grep "Name=" | grep "Touch"

This is the full output of /proc/bus/input/devices : 这是/proc/bus/input/devices的完整输出:

I: Bus=0011 Vendor=0002 Product=0008 Version=2222
N: Name="AlpsPS/2 ALPS DualPoint TouchPad"
P: Phys=isa0060/serio1/input0
S: Sysfs=/class/input/input2
H: Handlers=mouse1 event2 ts1
B: EV=f
B: KEY=420 0 70000 0 0 0 0 0 0 0 0
B: REL=3
B: ABS=1000003

[...] (blank line, next device)

The B in front stands for bitmap, N, P, S, U, H are simply first letter in corresponding name value and I is for ID. 前面的B代表位图,N,P,S,U,H只是相应名称值的第一个字母,而I代表ID。 In ordered fashion: 有序的方式:

  • I → @id: id of the device (struct input_id) I →@ id:设备的id(struct input_id)
    • Bus → id.bustype Bus →id.bustype
    • Vendor → id.vendor Vendor →id.vendor
    • Product → id.product Product →id.product
    • Version → id.version Version →id.version
  • N → name of the device N →设备名称
  • P → physical path to the device in the system hierarchy P →系统层次结构中设备的物理路径
  • S → sysfs path S →sysfs路径
  • U → unique identification code for the device (if device has it) U →设备的唯一识别码(如果设备有)
  • H → list of input handles associated with the device H →与设备关联的输入句柄列表
  • B → bitmaps B →位图
    • PROP → device properties and quirks PROP →设备属性和怪癖
    • EV → types of events supported by the device EV →设备支持的事件类型
    • KEY → keys/buttons this device has KEY →此设备具有的按键/按钮
    • MSC → miscellaneous events supported by the device MSC →设备支持的杂项事件
    • LED → leds present on the device LED →LED存在于设备上
    • REL → relative address REL →相对地址
    • ABS → absolute address ABS →绝对地址

To test if the device is actually attached, you can try simulating events and see if you get any errors: 要测试设备是否实际连接,您可以尝试模拟事件并查看是否有任何错误:

input tap [x] [y]

Android comes with an input command-line tool that can simulate miscellaneous input events. Android附带一个输入命令行工具,可以模拟各种输入事件。

  • input → The command line tool to send events input →用于发送事件的命令行工具
    • tap → the action 点按→动作
    • [x] → X coordinate on the screen [x]→屏幕上的X坐标
    • [y] → Y coordinate on the screen [y]→屏幕上的Y坐标

Find a driver name for the touch controller of your device. 查找设备的触摸控制器的驱动程序名称。 Then check its sysfs location. 然后检查其sysfs位置。 There will be few files mapped to the internal variables which were populated with data read from the physical touchscreen device during its initialization. 将几乎没有文件映射到内部变量,这些内部变量填充了在初始化期间从物理触摸屏设备读取的数据。 For example most touchscreen controllers have updateable firmware and provide a way to query its current version. 例如,大多数触摸屏控制器具有可更新的固件并提供查询其当前版本的方式。

One of my devices uses atmel_mxt_ts touchscreen controller and its sysfs location is /sys/bus/i2c/drivers/atmel_mxt_ts/1-004a/ . 我的一个设备使用atmel_mxt_ts触摸屏控制器,其sysfs位置是/sys/bus/i2c/drivers/atmel_mxt_ts/1-004a/ There is a fw_version file in that folder. 该文件夹中有一个fw_version文件。 If the physical touchscreen is connected that file would contain the current firmware label. 如果物理触摸屏已连接,则该文件将包含当前固件标签。 The empty file would mean that there is no touchscreen. 空文件意味着没有触摸屏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM