image/svg+xml
Brteve's API for EveApps
Version 0.0.1
The reference document for common folder of EveApps project.
 
Loading...
Searching...
No Matches
Gesture.c
Go to the documentation of this file.
1
32#include "Platform.h"
33#include "EVE_CoCmd.h"
34
35#include "Common.h"
36#include "Gesture.h"
37
43static uint8_t sIsSwipe = 0;
44static const int sMinMove = 15;
45
51static int Getvelocity_X() {
52 static uint16_t _delay = 0;
53 static int lastTouchX = 0;
54 static uint32_t prev_time = 0;
55 uint32_t time = EVE_millis();
56 static int distance = 0;
57 static long dragprev = 0;
58 static int velocityX = 0;
59 static int count1Touch = 0;
60
61 if (prev_time != 0) {
62 _delay += (time - prev_time);
63 }
64 prev_time = time;
65
66 if (_delay < 30) {
67 return velocityX;
68 }
69 _delay = 0;
70
71 if (sIsTouch) {
72 if (sIsSwipe == 0) {
73 if (lastTouchX == 0) {
74 lastTouchX = sTouchX;
75 }
76 else {
77 distance = sTouchX - lastTouchX;
78 }
79 if (abs(distance) > sMinMove) { // this is a swipe
80 sIsSwipe = 1;
81 }
82 }
83 }
84 else {
85 distance = 0;
86 lastTouchX = 0;
87 sIsSwipe = 0;
88 }
89
90 if (sIsSwipe == 1) {
91 velocityX = (dragprev - sTouchX) << 4;
92 }
93 else if (!sIsTouch) { // no touch
94 int change = MAX(1, abs(velocityX) >> 5);
95 if (velocityX < 0)
96 velocityX += change;
97 if (velocityX > 0)
98 velocityX -= change;
99 }
100 else {
101 count1Touch++;
102 if (count1Touch == 5) {
103 count1Touch = 0;
104 velocityX = 0; // reset velocity when single touch
105 }
106 }
107
108 dragprev = sTouchX;
109 return velocityX;
110}
111
118 static uint32_t oldtag = 0;
119 uint32_t newTag = 0;
120 uint32_t tagRet = 0;
121
122 newTag = sTag;
123
124 if (newTag == 0 && oldtag != newTag) {
125 tagRet = oldtag;
126 oldtag = 0;
127 }
128 else if (newTag != 0) {
129 oldtag = newTag;
130 }
131 return tagRet;
132}
133
141{
142 static uint8_t Read_tag = 0;
143 static uint8_t temp_tag = 0;
144 static uint8_t ret_tag = 0;
145 static uint8_t sk = 0;
146
147 Read_tag = EVE_Hal_rd8(phost, REG_TOUCH_TAG);
148 ret_tag = 0;
149 if (Read_tag != 0) // Allow if the Key is released
150 {
151 if (temp_tag != Read_tag)
152 {
153 temp_tag = Read_tag;
154 sk = Read_tag; // Load the Read tag to temp variable
155 }
156 }
157 else
158 {
159 if (temp_tag != 0)
160 {
161 ret_tag = temp_tag;
162 temp_tag = 0; //The event will be processed. Clear the tag
163 }
164 sk = 0;
165 }
166 return ret_tag;
167}
168
174{
175 sTag = Gpu_Hal_Rd32(phost, REG_TOUCH_TAG) & 0xFF;
176 sIsTouch = Gpu_Hal_Rd32(phost, REG_TOUCH_RAW_XY) != 0xFFFFFFFF;
179 uint32_t track = Gpu_Hal_Rd32(phost, REG_TRACKER);
180 sGesture.tagTrackTouched = track & 0xFF;
181 sGesture.trackValLine = track >> 16;
182 sGesture.trackValCircle = (track >> 16) * 360 / 65535;
190 return &sGesture;
191}
192
199{
200 return &sGesture;
201}
202
Common functions.
EVE's co-processor commmands.
#define REG_TOUCH_TAG
#define REG_TOUCH_RAW_XY
#define REG_TOUCH_SCREEN_XY
#define REG_TRACKER
EVE_HAL_EXPORT uint8_t EVE_Hal_rd8(EVE_HalContext *phost, uint32_t addr)
Read 8 bits from Coprocessor's memory.
Definition EVE_Hal.c:157
EVE_HAL_EXPORT uint32_t EVE_millis()
Get clock in miliseond.
unsigned short uint16_t
unsigned int uint32_t
unsigned char uint8_t
Gesture_Touch_t * Gesture_Get()
Get gesture data.
Definition Gesture.c:198
static uint16_t sTouchX
Definition Gesture.c:41
static const int sMinMove
Definition Gesture.c:44
static uint32_t sTag
Definition Gesture.c:39
static int Getvelocity_X()
Get horizontal veloxity.
Definition Gesture.c:51
Gesture_Touch_t * Gesture_Renew(Gpu_Hal_Context_t *phost)
Refresh gesture data.
Definition Gesture.c:173
uint8_t Gesture_GetTag(EVE_HalContext *phost)
Get Active tag number.
Definition Gesture.c:140
static uint16_t sTouchY
Definition Gesture.c:42
static uint16_t sIsTouch
Definition Gesture.c:40
static Gesture_Touch_t sGesture
Definition Gesture.c:38
static uint8_t sIsSwipe
Definition Gesture.c:43
static uint32_t GetTagReleased()
Get the Tag number of Released object.
Definition Gesture.c:117
Gesture for touch screen.
#define Gpu_Hal_Rd32
Definition Gpu_Hal.h:206
#define Gpu_Hal_Rd16
Definition Gpu_Hal.h:205
#define MAX(x, y)
Definition Gpu_Hal.h:455
#define Gpu_Hal_Context_t
Definition Gpu_Hal.h:134
uint32_t tagReleased
Definition Gesture.h:40
int velocityX
Definition Gesture.h:47
uint8_t isSwipe
Definition Gesture.h:44
uint32_t tagTrackTouched
Definition Gesture.h:38
uint8_t isTouch
Definition Gesture.h:43
uint32_t trackValLine
Definition Gesture.h:41
uint16_t touchY
Definition Gesture.h:46
uint32_t tagPressed
Definition Gesture.h:39
uint32_t trackValCircle
Definition Gesture.h:42
uint16_t touchX
Definition Gesture.h:45