1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __WEAR_TOUCH_H
18 #define __WEAR_TOUCH_H
19 
20 #include <pthread.h>
21 
22 class WearSwipeDetector {
23 
24 public:
25     enum SwipeDirection { UP, DOWN, RIGHT, LEFT };
26     typedef void (*OnSwipeCallback)(void* cookie, enum SwipeDirection direction);
27 
28     WearSwipeDetector(int low, int high, OnSwipeCallback cb, void* cookie);
29     ~WearSwipeDetector();
30 
31 private:
32     void run();
33     void process(struct input_event *event);
34     void detect(int dx, int dy);
35 
36     pthread_t mThread;
37     static void* touch_thread(void* cookie);
38 
39     int findDevice(const char* path);
40     int openDevice(const char* device);
41 
42     int mLowThreshold;
43     int mHighThreshold;
44 
45     OnSwipeCallback mCallback;
46     void *mCookie;
47 
48     int mX;
49     int mY;
50     int mStartX;
51     int mStartY;
52 
53     int mCurrentSlot;
54     bool mFingerDown;
55     bool mSwiping;
56 };
57 
58 #endif // __WEAR_TOUCH_H
59