Android 触控

usb 触摸屏

Posted by LXG on March 10, 2022

触摸设备-AOSP

USB HID 设备

USB HID类是USB设备的一个标准设备类,包括的设备非常多。HID类设备定义它属于人机交互操作的设备,用于控制计算机操作的一些方面,如USB鼠标,USB键盘,USB游戏操纵杆,USB触摸屏。

USB HID设备的一个好处就是操作系统自带了HID类的驱动程序,而用户无需去开发驱动程序,只要使用API调用即可完成通信。

如何修改USB触控方向


diff --git a/frameworks/base/services/input/InputReader.cpp b/frameworks/base/services/input/InputReader.cpp
index 6a21d2a..068eb01 100755
--- a/frameworks/base/services/input/InputReader.cpp
+++ b/frameworks/base/services/input/InputReader.cpp
@@ -51,6 +51,7 @@
 #include <errno.h>
 #include <limits.h>
 #include <math.h>
+#include <cutils/properties.h>
 
 #define INDENT "  "
 #define INDENT2 "    "
@@ -2947,7 +2948,31 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
     bool viewportChanged = mViewport != newViewport;
     if (viewportChanged) {
         mViewport = newViewport;
-
+        //add by lixiaogang start
+        char tmp[PROP_VALUE_MAX];
+        property_get("ro.sf.rotation", tmp, 0);
+        int rotation = atoi(tmp);
+        if (rotation == 270) {
+             switch (mViewport.orientation) {
+                 case DISPLAY_ORIENTATION_0:
+                      ALOGD("mViewport.orientation = DISPLAY_ORIENTATION_0");
+                      mViewport.orientation = DISPLAY_ORIENTATION_180;
+                      break;
+                 case DISPLAY_ORIENTATION_90:
+                      ALOGD("mViewport.orientation = DISPLAY_ORIENTATION_90");
+                      mViewport.orientation = DISPLAY_ORIENTATION_270;
+                      break;
+                 case DISPLAY_ORIENTATION_180:
+                      ALOGD("mViewport.orientation = DISPLAY_ORIENTATION_180");
+                      mViewport.orientation = DISPLAY_ORIENTATION_0;
+                      break;
+                 case DISPLAY_ORIENTATION_270:
+                      ALOGD("mViewport.orientation = DISPLAY_ORIENTATION_270");
+                      mViewport.orientation = DISPLAY_ORIENTATION_90;
+                      break;
+             }
+        }
+        //add by lixiaogang end
         if (mDeviceMode == DEVICE_MODE_DIRECT || mDeviceMode == DEVICE_MODE_POINTER) {
             // Convert rotated viewport to natural surface coordinates.
             int32_t naturalLogicalWidth, naturalLogicalHeight;