android recovery 模式下获取触摸屏(usb)的坐标

 

--- a/recovery/minui/events.cpp
+++ b/recovery/minui/events.cpp
@@ -68,18 +68,25 @@ int ev_init(ev_callback input_cb, void* data) {
             unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)];

 //            fprintf(stderr,"/dev/input/%s\n", de->d_name);
             if (strncmp(de->d_name, "event", 5)) continue;
             int fd = openat(dirfd(dir), de->d_name, O_RDONLY);
             if (fd == -1) continue;

             // Read the evbits of the input device.
-            if (ioctl(fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits) == -1) {
+//            if (ioctl(fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits) == -1) {
+//                close(fd);
+//                continue;
+//            }
+
+            if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(ev_bits)), ev_bits) == -1) {
                 close(fd);
                 continue;
             }

             // We assume that only EV_KEY, EV_REL, and EV_SW event types are ever needed.
-            if (!test_bit(EV_KEY, ev_bits) && !test_bit(EV_REL, ev_bits) && !test_bit(EV_SW, ev_bits)) {
+//            if (!test_bit(EV_KEY, ev_bits) && !test_bit(EV_REL, ev_bits) && !test_bit(EV_SW, ev_bits)) {
+            if (!test_bit(ABS_MT_POSITION_X, ev_bits) && !test_bit(ABS_MT_POSITION_Y, ev_bits)) {
                 close(fd);
                 continue;
             }
@@ -211,17 +218,18 @@ void ev_iterate_available_keys(std::function<void(int)> f) {
         memset(key_bits, 0, sizeof(key_bits));

         // Does this device even have keys?
-        if (ioctl(ev_fdinfo[i].fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits) == -1) {
-            continue;
-        }
-        if (!test_bit(EV_KEY, ev_bits)) {
+        if (ioctl(ev_fdinfo[i].fd, EVIOCGBIT(EV_ABS, sizeof(ev_bits)), ev_bits) == -1) {
             continue;
         }

-        int rc = ioctl(ev_fdinfo[i].fd, EVIOCGBIT(EV_KEY, KEY_MAX), key_bits);
-        if (rc == -1) {
-            continue;
-        }
+//        if (!test_bit(EV_KEY, ev_bits)) {
+//            continue;
+//        }
+
+//        int rc = ioctl(ev_fdinfo[i].fd, EVIOCGBIT(EV_KEY, KEY_MAX), key_bits);
+//        if (rc == -1) {
+//            continue;
+//        }

for (int key_code = 0; key_code <= KEY_MAX; ++key_code) {
             if (test_bit(key_code, key_bits)) {
 

 void RecoveryUI::Init() {
     ev_init(InputCallback, this);

     ev_iterate_available_keys(std::bind(&RecoveryUI::OnKeyDetected, this, std::placeholders::_1));
@@ -95,31 +101,41 @@ int RecoveryUI::OnInputEvent(int fd, uint32_t epevents) {
     }

     if (ev.type == EV_SYN) {
-        return 0;
-    } else if (ev.type == EV_REL) {
-        if (ev.code == REL_Y) {
-            // accumulate the up or down motion reported by
-            // the trackball.  When it exceeds a threshold
-            // (positive or negative), fake an up/down
-            // key event.
-            rel_sum += ev.value;
-            if (rel_sum > 3) {
-                ProcessKey(KEY_DOWN, 1);   // press down key
-                ProcessKey(KEY_DOWN, 0);   // and release it
-                rel_sum = 0;
-            } else if (rel_sum < -3) {
-                ProcessKey(KEY_UP, 1);     // press up key
-                ProcessKey(KEY_UP, 0);     // and release it
-                rel_sum = 0;
+        if (ev.code == SYN_REPORT) {
+           if (mFingerDown && !mSwiping) {
+//                mStartX = mX;
+//                mStartY = mY;
+                mSwiping = true;
+            } else if (!mFingerDown && mSwiping) {
+                mSwiping = false;
+                EnqueueKey(ABS_MT_SLOT);
+            }
+        }
+    } else if (ev.type == EV_ABS) {
+//        if (ev.code == ABS_MT_SLOT) {
+            
+        switch (ev.code) {
+               case ABS_MT_POSITION_X:
+                    mFingerDown = true;
+//                  mX = event->value;

+               break;
+
+               case ABS_MT_POSITION_Y:
+                   mFingerDown = true;
+//                   mY = event->value;
+               break;
+
+               case ABS_MT_TRACKING_ID:
+                    if (ev.value < 0)
+                        mFingerDown = false;
+                   break;
             }
         }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值