›SensorTile实现无线触摸屏 蓝牙HID
[复制链接]
本帖最后由 kangear 于 2018-7-20 23:04 编辑
基于@littleshrimp 的HID帖子实现的,最近一直查看相关资料,总算整明白了。基于SensorTile实现了无线触摸屏,目前自动从左上角点击滑动到右下角。
1. 目前实现的是单点触摸,后续会实现多点触摸;
2. 参考文档比较多,@littleshrimp 版主的 空中飞鼠 帖子,微软的描述符文章,Android文章https://source.android.com/devices/input/touch-devices
最终实现了,不容易,真不容易。先发一个图得瑟一下,后续再整理详细的文章,我对Android底层开发熟悉一些,有相关问题可以咨询的。
个人技术博客: https://blog.csdn.net/kangear
补充:
HID => linux kernel input子系统 => Android input子系统
就单点触控而言,倒着看Android里对触摸屏的要求,如下图所示:上报键ABS_X 和 ABS_Y以及BTN_TOUCH,另外还需要一个配置文件指定该设备类型为触摸屏。
(一个设备上传了哪些键值可以通过adb shell getevent -i查看)
对应到Linux内核(以3.4内核为准)里,HID的描述符就需要包含User Page为DIGITIZER,包含TIPSWITCH
这里 的这个描述符稍微精简一下就可以了。最终如下:
0x05, 0x0d, // USAGE_PAGE (Digitizers)
0x09, 0x04, // USAGE (Touch Screen)
0xa1, 0x01, // COLLECTION (Application)
0x85, 0x01, // REPORT_ID (Touch) (REPORTID_TOUCH is 1)
0x09, 0x20, // USAGE (Stylus)
0xa1, 0x00, // COLLECTION (Physical)
0x09, 0x42, // USAGE (Tip Switch)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x03, // REPORT_COUNT (3)
0x81, 0x03, // INPUT (Cnst,Ary,Abs)
/*
0x09, 0x32, // USAGE (In Range)
0x09, 0x47, // USAGE (Confidence)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x0a, // REPORT_COUNT (10)
0x81, 0x03, // INPUT (Cnst,Ary,Abs)
*/
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM (32767)
0x75, 0x10, // REPORT_SIZE (16)
0x95, 0x01, // REPORT_COUNT (1)
0xa4, // PUSH
0x55, 0x0d, // UNIT_EXPONENT (-3)
0x65, 0x00, // UNIT (None)
0x09, 0x30, // USAGE (X)
0x35, 0x00, // PHYSICAL_MINIMUM (0)
0x46, 0x00, 0x00, // PHYSICAL_MAXIMUM (0)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x09, 0x31, // USAGE (Y)
0x46, 0x00, 0x00, // PHYSICAL_MAXIMUM (0)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xb4, // POP
/*
0x05, 0x0d, // USAGE PAGE (Digitizers)
0x09, 0x48, // USAGE (Width)
0x09, 0x49, // USAGE (Height)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x03, // INPUT (Cnst,Ary,Abs)
*/
0xc0, // END_COLLECTION
0xc0, // END_COLLECTION 复制代码
然后在while循环里,模拟发出一个触摸滑动的事件
static int8_t ipRepVal[REPORT_IP_LEN_0] = {0};
/*
static int8_t cnt = 0;
if(cnt == 0) {
ipRepVal[1] = MOUSE_OFFSET_X;
ipRepVal[2] = MOUSE_OFFSET_Y;
cnt++;
} else {
ipRepVal[1] = -MOUSE_OFFSET_X;
ipRepVal[2] = -MOUSE_OFFSET_Y;
cnt--;
}
*/
ipRepVal[1] = 0x01; // down
if (abs_hor < 32760) {
abs_hor += 20;
abs_ver += 20;
} else {
ipRepVal[1] = 0x00; // up
}
ipRepVal[0] = 0x01; // Report ID
ipRepVal[2] = abs_hor%256;
ipRepVal[3] = abs_hor/256;
ipRepVal[4] = abs_ver%256;
ipRepVal[5] = abs_ver/256;
HidDevice_Update_Input_Report(0,0,REPORT_IP_LEN_0,ipRepVal);
if (ipRepVal[1] == 0x00) {
abs_hor = 0;
abs_ver = 0;
} 复制代码
Android系统中的放一个配置文件,路径:/system/usr/idc/HID.idc
# Copyright (C) 2010 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# [url=http://www.apache.org/licenses/LICENSE-2.0]http://www.apache.org/licenses/LICENSE-2.0[/url]
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Input Device Calibration File for the touch screen.
#
# Basic Parameters
touch.deviceType = touchScreen
#touch.orientationAware = 1
# Size
# Based on empirical measurements, we estimate the size of the contact
# using size = sqrt(area) * 43 + 0.
#touch.size.calibration = area
#touch.size.scale = 6
#touch.size.bias = 0
#touch.size.isSummed = 0
# Pressure
# Driver reports signal strength as pressure.
#
# A normal thumb touch typically registers about 80 signal strength
# units although we don't expect these values to be accurate.
#touch.pressure.calibration = amplitude
#touch.pressure.scale = 0.0125
#
# Orientation
#touch.orientation.calibration = none
复制代码
这样连接到该设备后就可以如下图自动从左上角滑动到右下角了。这里有git diff文件可以详细查看: