Daiki Kato / MothionEventConverter
Revision:
1:5bfc165e8f08
Parent:
0:c41d29f1e0fb
diff -r c41d29f1e0fb -r 5bfc165e8f08 MotionEventConverter.cpp
--- a/MotionEventConverter.cpp	Tue Jun 28 13:06:53 2016 +0000
+++ b/MotionEventConverter.cpp	Wed Jun 29 05:33:35 2016 +0000
@@ -18,19 +18,23 @@
 
 #define MULTI_TOUCH_NUM         (2)
 
-void MotionEventConverter::Process(TouchKey * p_touch, int (*cb_func)(MotionEvent event)) {
+MotionEventConverter::MotionEventConverter() : sem_touch_int(0) {
+}
+
+void MotionEventConverter::touch_process(TouchKey * p_touch) {
     memset(touch_pos, 0, sizeof(touch_pos));
     memset(touch_pos_last, 0, sizeof(touch_pos_last));
     time_cnt = 0;
     touch_num = 0;
     touch_num_last = 0;
 
-    p_touch->Init();
+    p_touch->SetCallback(this, &MotionEventConverter::touch_int_callback);
+    p_touch->Reset();
     t.reset();
     t.start();
 
     while (1) {
-        p_touch->WaitInt();
+        sem_touch_int.wait();
         // Get Coordinates
         touch_num = p_touch->GetCoordinates(MotionEvent::TOUCH_NUM_MAX, &touch_pos[0]);
         time_cnt = t.read_ms();
@@ -39,11 +43,11 @@
             // Two points are pressed at the same time
             event.setPosData(0, touch_pos[0].x, touch_pos[0].y);
             event.setActionInfo((0 << MotionEvent::ACTION_POINTER_INDEX_SHIFT) | ACTION_DOWN, time_cnt);
-            cb_func(event);
+            _callback.call(event);
 
             event.setPosData(1, touch_pos[1].x, touch_pos[1].y);
             event.setActionInfo((1 << MotionEvent::ACTION_POINTER_INDEX_SHIFT) | ACTION_POINTER_DOWN, time_cnt);
-            cb_func(event);
+            _callback.call(event);
         } else if ((touch_num_last == 0) && (touch_num == 1)) {
             // It was pressed only one point
             if (touch_pos[0].valid != false) {
@@ -53,7 +57,7 @@
             }
             event.setPosData(pidx, touch_pos[pidx].x, touch_pos[pidx].y);
             event.setActionInfo((0 << MotionEvent::ACTION_POINTER_INDEX_SHIFT) | ACTION_DOWN, time_cnt);
-            cb_func(event);
+            _callback.call(event);
         } else if ((touch_num_last == 1) && (touch_num == 2)) {
             // The second point is pressed
             event.setPosData(0, touch_pos[0].x, touch_pos[0].y);
@@ -64,18 +68,18 @@
                 pidx = 1;
             }
             event.setActionInfo((pidx << MotionEvent::ACTION_POINTER_INDEX_SHIFT) | ACTION_POINTER_DOWN, time_cnt);
-            cb_func(event);
+            _callback.call(event);
         } else if ((touch_num_last >= MULTI_TOUCH_NUM) && (touch_num == 0)) {
             // Two points are released at the same time
             event.setPosData(0, touch_pos_last[0].x, touch_pos_last[0].y);
             event.setPosData(1, touch_pos_last[1].x, touch_pos_last[1].y);
             event.setActionInfo((1 << MotionEvent::ACTION_POINTER_INDEX_SHIFT) | ACTION_POINTER_UP, time_cnt);
-            cb_func(event);
+            _callback.call(event);
 
             event.clearPointerCount();
             event.setPosData(0, touch_pos_last[0].x, touch_pos_last[0].y);
             event.setActionInfo((0 << MotionEvent::ACTION_POINTER_INDEX_SHIFT) | ACTION_UP, time_cnt);
-            cb_func(event);
+            _callback.call(event);
         } else if ((touch_num_last == 1) && (touch_num == 0)) {
             // The last of one point is released
             if (touch_pos[0].valid != touch_pos_last[0].valid) {
@@ -85,7 +89,7 @@
             }
             event.setPosData(pidx, touch_pos_last[pidx].x, touch_pos_last[pidx].y);
             event.setActionInfo((0 << MotionEvent::ACTION_POINTER_INDEX_SHIFT) | ACTION_UP, time_cnt);
-            cb_func(event);
+            _callback.call(event);
         } else if ((touch_num_last >= MULTI_TOUCH_NUM) && (touch_num == 1)) {
             // The second point is released
             pidx = 0;
@@ -101,7 +105,7 @@
                 pidx = 1;
             }
             event.setActionInfo((pidx << MotionEvent::ACTION_POINTER_INDEX_SHIFT) | ACTION_POINTER_UP, time_cnt);
-            cb_func(event);
+            _callback.call(event);
         } else if (touch_num != 0) {
             // Check whether the position has moved
             bool moved = false;
@@ -119,7 +123,7 @@
                     pidx = 0;
                 }
                 event.setActionInfo((pidx << MotionEvent::ACTION_POINTER_INDEX_SHIFT) | ACTION_MOVE, time_cnt);
-                cb_func(event);
+                _callback.call(event);
             }
         } else {
             // do nothing
@@ -130,4 +134,9 @@
     }
 }
 
+void MotionEventConverter::touch_int_callback(void) {
+    sem_touch_int.release();
+}
 
+
+