Android USB TP方向修改

搜集的一些关于Android USB TP的方向修改的代码,X to Y , X反转 , Y反转,双触屏配置,双屏异触等。

cpp 复制代码
diff --git a/kernel/drivers/hid/hid-multitouch.c b/kernel/drivers/hid/hid-multitouch.c
old mode 100644new mode 100755
index 9de379c1b3..b8456b1e50
--- a/kernel/drivers/hid/hid-multitouch.c
+++ b/kernel/drivers/hid/hid-multitouch.c
@@ -98,7 +98,23 @@ struct mt_fields {
    unsigned usages[HID_MAX_FIELDS];
    unsigned int length;
};
-
+#define GTP_SWAP(x, y)                 do{\
+                                         typeof(x) z = x;\
+                                         x = y;\
+                                         y = z;\
+                                       }while (0)
+                              
+#define MAINmGtpChange_X2Y   1 
+#define MIANmGtp_X_Reverse    1
+#define MAINNmGtp_Y_Reverse      0 
+static int  MAINX_max=0;
+static int  MAINY_max=0;
+                              
+#define AUXmGtpChange_X2Y    1 
+#define AUXmGtp_X_Reverse    1
+#define AUXNmGtp_Y_Reverse   0 
+static int  AUXX_max=0;
+static int  AUXY_max=0;
struct mt_device {
    struct mt_slot curdata; /* placeholder of incoming data */
    struct mt_class mtclass;    /* our mt device class */
@@ -461,6 +477,14 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
    case HID_UP_GENDESK:
        switch (usage->hid) {
        case HID_GD_X:
+       if (hdev->vendor==0x0457 && hdev->product==0x0819)
+       {
+           MAINX_max =     field->logical_maximum;
+       }
+       else if (hdev->vendor==0x222a && hdev->product ==0x0001)
+       {
+           AUXX_max =  field->logical_maximum;
+       }
            if (prev_usage && (prev_usage->hid == usage->hid)) {
                hid_map_usage(hi, usage, bit, max,
                    EV_ABS, ABS_MT_TOOL_X);
@@ -476,6 +500,14 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
            mt_store_field(usage, td, hi);
            return 1;
        case HID_GD_Y:
+       if (hdev->vendor==0x0457 && hdev->product==0x0819)
+       {
+           MAINY_max =     field->logical_maximum;
+       }
+       else if (hdev->vendor==0x222a && hdev->product ==0x0001)
+       {
+           AUXY_max =  field->logical_maximum;
+       }
            if (prev_usage && (prev_usage->hid == usage->hid)) {
                hid_map_usage(hi, usage, bit, max,
                    EV_ABS, ABS_MT_TOOL_Y);
@@ -613,8 +645,10 @@ static int mt_compute_slot(struct mt_device *td, struct input_dev *input)
  * this function is called when a whole contact has been processed,
  * so that it can assign it to a slot and store the data there
  */
-static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
+static void mt_complete_slot(struct mt_device *td, struct input_dev *input,struct hid_device *hid_device)
{
+   
+   
    if ((td->mtclass.quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) &&
        td->num_received >= td->num_expected)
        return;
@@ -649,7 +683,33 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
            int major = max(s->w, s->h) >> 1;
            int minor = min(s->w, s->h) >> 1;
-           input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
+if (hid_device->vendor==0x0457 && hid_device->product==0x0819)
+{
+   #if MAINmGtpChange_X2Y
+       GTP_SWAP(s->x, s->y);
+   #endif
+       if(MIANmGtp_X_Reverse){
+           s->x = MAINX_max -s->x;+       }
+
+       if(MAINNmGtp_Y_Reverse){
+           s->y = MAINY_max - s->y;
+       }
+}
+else if (hid_device->vendor==0x222a && hid_device->product==0x0001)
+{
+   #if AUXmGtpChange_X2Y
+       GTP_SWAP(s->x, s->y);
+   #endif
+       if(AUXmGtp_X_Reverse){
+           s->x = AUXX_max -s->x;
+       }
+
+       if(AUXNmGtp_Y_Reverse){
+           s->y = AUXY_max - s->y;
+       }
+}
          input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
            input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
            input_event(input, EV_ABS, ABS_MT_TOOL_X, s->cx);
            input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy);
@@ -752,7 +812,7 @@ static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field,
        if (usage->usage_index + 1 == field->report_count) {
            /* we only take into account the last report. */
            if (usage->hid == td->last_slot_field)
-               mt_complete_slot(td, field->hidinput->input);
+               mt_complete_slot(td, field->hidinput->input,hid);
        }
    }


diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index 9de379c1b3fd..0c08b397792f 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -164,6 +164,8 @@ static void mt_post_parse(struct mt_device *td);
 #define MT_USB_DEVICE(v, p)    HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
 #define MT_BT_DEVICE(v, p)     HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
 
+static int vendor_id,vendor_temp,vendor_logical_max;
+

@@ -415,6 +417,7 @@ static void set_abs(struct input_dev *input, unsigned int code,
        int fuzz = snratio ? (fmax - fmin) / snratio : 0;
        input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
        input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
+       vendor_logical_max = fmax;
 }
 
 static void mt_store_field(struct hid_usage *usage, struct mt_device *td,
@@ -640,6 +643,13 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
                active = (s->touch_state || s->inrange_state) &&
                                                        s->confidence_state;
 
+        		/*Identifier: bus=0x0003, vendor=0x222a, product=0x0001, version=0x0110 */
+               if(vendor_id == 0x222a){
+                       vendor_temp = s->x;
+                       s->x = vendor_logical_max - s->y;
+                       s->y = vendor_temp;
+               }
+
                input_mt_slot(input, slotnum);
                input_mt_report_slot_state(input, MT_TOOL_FINGER, active);
                if (active) {
@@ -764,6 +774,7 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
        struct hid_field *field;
        unsigned count;
        int r, n;
+       vendor_id = hid->vendor;
 
        /*
         * Includes multi-packet support where subsequent

或者修改上层 framework/native/services/inputflinger/InputReader.cpp

cpp 复制代码
diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp
index c1a36ff79..851b98027 100644
--- a/services/inputflinger/InputReader.cpp
+++ b/services/inputflinger/InputReader.cpp
@@ -3814,6 +3814,29 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
      bool viewportChanged = mViewport != newViewport;
      if (viewportChanged) {
          mViewport = newViewport;
          
+        char buffer_orientation[PROP_VALUE_MAX];
+        memset(buffer_orientation, 0, sizeof(buffer_orientation));
+        property_get("persist.sys.panel.flip", buffer_orientation, "270");
+        int cmpRet = atoi(buffer_orientation);
+        ALOGE("persist.sys.hwrotation~~~~~~~~~~~~~~~~~~~~~~~~~ = %d",cmpRet);
+        ALOGE("fy-1:mViewport.orientation----------------------- = %d",mViewport.orientation);
+        if (cmpRet == 0)
+        {
+            mViewport.orientation = mViewport.orientation + DISPLAY_ORIENTATION_0;
+        }
+        else if(cmpRet == 90)
+        {
+            mViewport.orientation = mViewport.orientation  + DISPLAY_ORIENTATION_90;
+        }
+        else if(cmpRet == 180)
+        {
+            mViewport.orientation = mViewport.orientation + DISPLAY_ORIENTATION_180;
+        }
+        else if(cmpRet == 270)
+        {
+            mViewport.orientation = mViewport.orientation + DISPLAY_ORIENTATION_270;
+        }
+        ALOGE("fy-2:mViewport.orientation----------------------- = %d",mViewport.orientation);

          if (mDeviceMode == DEVICE_MODE_DIRECT || mDeviceMode == DEVICE_MODE_POINTER) {
              // Convert rotated viewport to natural surface coordinates.
相关推荐
奔跑吧邓邓子11 分钟前
大数据利器Hadoop:从基础到实战,一篇文章掌握大数据处理精髓!
大数据·hadoop·分布式
说私域1 小时前
基于定制开发与2+1链动模式的商城小程序搭建策略
大数据·小程序
ChinaDragonDreamer2 小时前
Kotlin:2.0.20 的新特性
android·开发语言·kotlin
hengzhepa2 小时前
ElasticSearch备考 -- Async search
大数据·学习·elasticsearch·搜索引擎·es
GZ_TOGOGO3 小时前
【2024最新】华为HCIE认证考试流程
大数据·人工智能·网络协议·网络安全·华为
网络研究院4 小时前
Android 安卓内存安全漏洞数量大幅下降的原因
android·安全·编程·安卓·内存·漏洞·技术
凉亭下4 小时前
android navigation 用法详细使用
android
狼头长啸李树身5 小时前
眼儿媚·秋雨绵绵窗暗暗
大数据·网络·服务发现·媒体
Json_181790144805 小时前
商品详情接口使用方法和对接流程如下
大数据·json
Data 3176 小时前
Hive数仓操作(十七)
大数据·数据库·数据仓库·hive·hadoop