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 File Reference

Gesture for touch screen. More...

#include "Platform.h"
#include "EVE_CoCmd.h"
#include "Common.h"
#include "Gesture.h"

Go to the source code of this file.

Functions

static int Getvelocity_X ()
 Get horizontal veloxity.
 
static uint32_t GetTagReleased ()
 Get the Tag number of Released object.
 
uint8_t Gesture_GetTag (EVE_HalContext *phost)
 Get Active tag number.
 
Gesture_Touch_tGesture_Renew (Gpu_Hal_Context_t *phost)
 Refresh gesture data.
 
Gesture_Touch_tGesture_Get ()
 Get gesture data.
 

Variables

static Gesture_Touch_t sGesture
 
static uint32_t sTag
 
static uint16_t sIsTouch
 
static uint16_t sTouchX
 
static uint16_t sTouchY
 
static uint8_t sIsSwipe = 0
 
static const int sMinMove = 15
 

Detailed Description

Gesture for touch screen.

Author
Tuan Nguyen tuan..nosp@m.nguy.nosp@m.en@br.nosp@m.tchi.nosp@m.p.com
Date
2019

MIT License

Copyright (c) [2019] [Bridgetek Pte Ltd (BRTChip)]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file Gesture.c.

Function Documentation

◆ Gesture_Get()

Gesture_Touch_t * Gesture_Get ( )

Get gesture data.

Returns
Gesture_Touch_t*

Definition at line 198 of file Gesture.c.

199{
200 return &sGesture;
201}
static Gesture_Touch_t sGesture
Definition Gesture.c:38

◆ Gesture_GetTag()

uint8_t Gesture_GetTag ( EVE_HalContext phost)

Get Active tag number.

Parameters
phostPointer to Hal context
Returns
uint8_t Tag number

Definition at line 140 of file Gesture.c.

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}
#define REG_TOUCH_TAG
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
unsigned char uint8_t

◆ Gesture_Renew()

Gesture_Touch_t * Gesture_Renew ( Gpu_Hal_Context_t phost)

Refresh gesture data.

Definition at line 173 of file Gesture.c.

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}
#define REG_TOUCH_RAW_XY
#define REG_TOUCH_SCREEN_XY
#define REG_TRACKER
unsigned int uint32_t
static uint16_t sTouchX
Definition Gesture.c:41
static uint32_t sTag
Definition Gesture.c:39
static int Getvelocity_X()
Get horizontal veloxity.
Definition Gesture.c:51
static uint16_t sTouchY
Definition Gesture.c:42
static uint16_t sIsTouch
Definition Gesture.c:40
static uint8_t sIsSwipe
Definition Gesture.c:43
static uint32_t GetTagReleased()
Get the Tag number of Released object.
Definition Gesture.c:117
#define Gpu_Hal_Rd32
Definition Gpu_Hal.h:206
#define Gpu_Hal_Rd16
Definition Gpu_Hal.h:205
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

◆ GetTagReleased()

static uint32_t GetTagReleased ( )
static

Get the Tag number of Released object.

Returns
uint8_t Tag number

Definition at line 117 of file Gesture.c.

117 {
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}

◆ Getvelocity_X()

static int Getvelocity_X ( )
static

Get horizontal veloxity.

Returns
int horizontal veloxity value

Definition at line 51 of file Gesture.c.

51 {
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}
EVE_HAL_EXPORT uint32_t EVE_millis()
Get clock in miliseond.
unsigned short uint16_t
static const int sMinMove
Definition Gesture.c:44
#define MAX(x, y)
Definition Gpu_Hal.h:455

Variable Documentation

◆ sGesture

Gesture_Touch_t sGesture
static

Definition at line 38 of file Gesture.c.

◆ sIsSwipe

uint8_t sIsSwipe = 0
static

Definition at line 43 of file Gesture.c.

◆ sIsTouch

uint16_t sIsTouch
static

Definition at line 40 of file Gesture.c.

◆ sMinMove

const int sMinMove = 15
static

Definition at line 44 of file Gesture.c.

◆ sTag

uint32_t sTag
static

Definition at line 39 of file Gesture.c.

◆ sTouchX

uint16_t sTouchX
static

Definition at line 41 of file Gesture.c.

◆ sTouchY

uint16_t sTouchY
static

Definition at line 42 of file Gesture.c.