Rev 1276 | Rev 1280 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1276 | Rev 1279 | ||
|---|---|---|---|
| Line 56... | Line 56... | ||
| 56 | F9: |
56 | F9: |
| 57 | 57 | ||
| 58 | */ |
58 | */ |
| 59 | 59 | ||
| 60 | 60 | ||
| - | 61 | /* |
|
| - | 62 | To fix: |
|
| - | 63 | Input parameter for buffer |
|
| - | 64 | Output returnvalues |
|
| - | 65 | Break out to a driver file |
|
| 61 | 66 | */ |
|
| 62 | uint8_t parseBuffer(uint8_t startIndex, uint8_t endIndex) |
67 | uint8_t parseBuffer(uint8_t startIndex, uint8_t endIndex) |
| 63 | { |
68 | { |
| 64 | int16_t f1_k = 0, |
69 | int16_t f1_k = 0, f3_tmp = 0, f4_tmp = 0, f5_tmp = 0, f9_tmp = 0; |
| 65 | uint8_t f7_tmp = 0, f7_sign = 0, f1_sign = 0 ,f3_yref = 0, f1 = 0,f2 = 0,f3 = 0,f4 = 0,f5 = 0,f6 = 0,f7 = 0,f8 = 0,f9 = 0, xMin, xMax, yMin, yMax; |
70 | uint8_t f7_tmp = 0, f7_sign = 0, f1_sign = 0, f3_yref = 0, f1 = 0, f2 = 0, f3 = 0, f4 = 0, f5 = 0, f6 = 0, f7 = 0, f8 = 0, f9 = 0, xMin, xMax, yMin, yMax; |
| 66 | 71 | ||
| - | 72 | /* Function 6 indicates the sign value of the y coordinates of the last point minus y coordinates of the first point */ |
|
| 67 | if ((int16_t)touchBuffer[endIndex].y - (int16_t)touchBuffer[startIndex].y > 0) |
73 | if ((int16_t)touchBuffer[endIndex].y - (int16_t)touchBuffer[startIndex].y > 0) |
| - | 74 | { |
|
| - | 75 | f6 = CAN_MODULE_ENUM_TOUCH_GESTURE_F6_PLUS; |
|
| 68 |
|
76 | } |
| 69 | else |
77 | else |
| - | 78 | { |
|
| - | 79 | f6 = CAN_MODULE_ENUM_TOUCH_GESTURE_F6_MINUS; |
|
| 70 |
|
80 | } |
| 71 | 81 | ||
| 72 | xMin = touchBuffer[startIndex].x; |
82 | xMin = touchBuffer[startIndex].x; |
| 73 | xMax = touchBuffer[startIndex].x; |
83 | xMax = touchBuffer[startIndex].x; |
| 74 | yMin = touchBuffer[startIndex].y; |
84 | yMin = touchBuffer[startIndex].y; |
| 75 | yMax = touchBuffer[startIndex].y; |
85 | yMax = touchBuffer[startIndex].y; |
| 76 | f3_yref = (touchBuffer[startIndex].y + touchBuffer[endIndex].y)/2; |
86 | f3_yref = (touchBuffer[startIndex].y + touchBuffer[endIndex].y)/2; |
| 77 | f1_k = ((touchBuffer[endIndex].y-touchBuffer[startIndex].y)<<4)/(touchBuffer[endIndex].x-touchBuffer[startIndex].x); |
87 | f1_k = ((touchBuffer[endIndex].y-touchBuffer[startIndex].y)<<4)/(touchBuffer[endIndex].x-touchBuffer[startIndex].x); |
| 78 | f1_sign = |
88 | f1_sign = CAN_MODULE_ENUM_TOUCH_GESTURE_F2_UNDEFINED; |
| 79 | 89 | ||
| 80 | for (uint8_t i = startIndex+1; i < endIndex-1; i++) |
90 | for (uint8_t i = startIndex+1; i < endIndex-1; i++) |
| 81 | { |
91 | { |
| - | 92 | /* Function 1 indicates the number of intersection points between an input gesture g(x) and the straight line f(x) |
|
| - | 93 | which connects the first and last point of the gesture */ |
|
| 82 | if (((f1_k*(touchBuffer[i].x-touchBuffer[0].x))>>4) + touchBuffer[0].y < touchBuffer[i].y) |
94 | if (((f1_k*(touchBuffer[i].x-touchBuffer[0].x))>>4) + touchBuffer[0].y < touchBuffer[i].y) |
| - | 95 | { |
|
| 83 | if (f1_sign != |
96 | if (f1_sign != CAN_MODULE_ENUM_TOUCH_GESTURE_F2_PLUS) |
| - | 97 | { |
|
| 84 | f1++; |
98 | f1++; |
| 85 |
|
99 | } |
| - | 100 | f1_sign = CAN_MODULE_ENUM_TOUCH_GESTURE_F2_PLUS; |
|
| 86 | } |
101 | } |
| 87 | else |
102 | else |
| - | 103 | { |
|
| 88 | if (f1_sign != |
104 | if (f1_sign != CAN_MODULE_ENUM_TOUCH_GESTURE_F2_MINUS) |
| - | 105 | { |
|
| 89 | f1++; |
106 | f1++; |
| 90 |
|
107 | } |
| - | 108 | f1_sign = CAN_MODULE_ENUM_TOUCH_GESTURE_F2_MINUS; |
|
| 91 | } |
109 | } |
| 92 | 110 | ||
| - | 111 | /* Function 3 indicates the sign value of area gap between g(x) and f(x) */ |
|
| 93 | if (touchBuffer[i].x > min(touchBuffer[startIndex].x, touchBuffer[endIndex].x) && touchBuffer[i].x < max(touchBuffer[startIndex].x, touchBuffer[endIndex].x)) |
112 | if (touchBuffer[i].x > min(touchBuffer[startIndex].x, touchBuffer[endIndex].x) && touchBuffer[i].x < max(touchBuffer[startIndex].x, touchBuffer[endIndex].x)) |
| 94 | { |
113 | { |
| 95 | f3_tmp += f3_yref - (touchBuffer[i].y + touchBuffer[i-1].y)/2; |
114 | f3_tmp += f3_yref - (touchBuffer[i].y + touchBuffer[i-1].y)/2; |
| 96 | } |
115 | } |
| - | 116 | ||
| - | 117 | /* find min an max of x and y */ |
|
| 97 | if (xMin > touchBuffer[i].x) |
118 | if (xMin > touchBuffer[i].x) |
| - | 119 | { |
|
| 98 | xMin = touchBuffer[i].x; |
120 | xMin = touchBuffer[i].x; |
| - | 121 | } |
|
| 99 | if (xMax < touchBuffer[i].x) |
122 | if (xMax < touchBuffer[i].x) |
| - | 123 | { |
|
| 100 | xMax = touchBuffer[i].x; |
124 | xMax = touchBuffer[i].x; |
| - | 125 | } |
|
| 101 | if (yMin > touchBuffer[i].y) |
126 | if (yMin > touchBuffer[i].y) |
| - | 127 | { |
|
| 102 | yMin = touchBuffer[i].y; |
128 | yMin = touchBuffer[i].y; |
| - | 129 | } |
|
| 103 | if (yMax < touchBuffer[i].y) |
130 | if (yMax < touchBuffer[i].y) |
| - | 131 | { |
|
| 104 | yMax = touchBuffer[i].y; |
132 | yMax = touchBuffer[i].y; |
| - | 133 | } |
|
| - | 134 | ||
| - | 135 | /* Function 4 represents the sign value of the sum of the x coordinates of all the points that constitute strokes |
|
| - | 136 | minus the x coordinates of the last point */ |
|
| 105 | f4_tmp += (int16_t)touchBuffer[i].x - (int16_t)touchBuffer[endIndex].x; |
137 | f4_tmp += (int16_t)touchBuffer[i].x - (int16_t)touchBuffer[endIndex].x; |
| - | 138 | ||
| - | 139 | /* Function 5 checks the sign value of the sum of the x coordinates of all the points that constitute strokes |
|
| - | 140 | minus x coordinates of the first point */ |
|
| 106 | f5_tmp += (int16_t)touchBuffer[i].x - (int16_t)touchBuffer[startIndex].x; |
141 | f5_tmp += (int16_t)touchBuffer[i].x - (int16_t)touchBuffer[startIndex].x; |
| 107 | } |
142 | } |
| 108 | 143 | ||
| - | 144 | /* Function 7 indicates the number of intersection points between an input gesture g(x) and all horizontal lines yi, |
|
| - | 145 | where i is between 0 and n, that constitute a gesture*/ |
|
| 109 | for (uint8_t j = yMin; j < yMax-1; j++) |
146 | for (uint8_t j = yMin; j < yMax-1; j++) |
| 110 | { |
147 | { |
| 111 | f7_tmp = 0xff; |
148 | f7_tmp = 0xff; |
| 112 | f7_sign = 0; |
149 | f7_sign = 0; |
| 113 | for (uint8_t i = startIndex+1; i < endIndex-1; i++) |
150 | for (uint8_t i = startIndex+1; i < endIndex-1; i++) |
| 114 | { |
151 | { |
| 115 | if (j > touchBuffer[i].y) |
152 | if (j > touchBuffer[i].y) |
| - | 153 | { |
|
| 116 | if (f7_sign != '+') |
154 | if (f7_sign != '+') |
| - | 155 | { |
|
| 117 | f7_tmp++; |
156 | f7_tmp++; |
| - | 157 | } |
|
| 118 | f7_sign = '+'; |
158 | f7_sign = '+'; |
| 119 | } |
159 | } |
| 120 | else { |
160 | else { |
| 121 | if (f7_sign != '-') |
161 | if (f7_sign != '-') |
| - | 162 | { |
|
| 122 | f7_tmp++; |
163 | f7_tmp++; |
| - | 164 | } |
|
| 123 | f7_sign = '-'; |
165 | f7_sign = '-'; |
| 124 | } |
166 | } |
| 125 | } |
167 | } |
| 126 | if (f7_tmp > f7) |
168 | if (f7_tmp > f7) |
| - | 169 | { |
|
| 127 | f7 = f7_tmp; |
170 | f7 = f7_tmp; |
| - | 171 | } |
|
| 128 | } |
172 | } |
| 129 | 173 | ||
| 130 | f1--; |
174 | f1--; |
| - | 175 | /* Function 2 checks if the y coordinates of the points which exist between the intersection point and the last point are |
|
| - | 176 | greater than the y coordinates of the intersection point */ |
|
| 131 | f2 = f1_sign; |
177 | f2 = f1_sign; |
| 132 | if (f1 == 0) |
178 | if (f1 == 0) |
| - | 179 | { |
|
| 133 | f2 = 2; |
180 | f2 = 2; |
| - | 181 | } |
|
| 134 | 182 | ||
| - | 183 | /* Function 3 indicates the sign value of area gap between g(x) and f(x) */ |
|
| - | 184 | f3 = CAN_MODULE_ENUM_TOUCH_GESTURE_F3_PLUS; |
|
| 135 | if (f3_tmp > 0) |
185 | if (f3_tmp > 0) |
| 136 |
|
186 | { |
| - | 187 | f3 = CAN_MODULE_ENUM_TOUCH_GESTURE_F3_MINUS; |
|
| 137 |
|
188 | } |
| 138 | f3 = 1; |
- | |
| 139 | 189 | ||
| 140 |
|
190 | /* Function 9 represents the sign value of the multiplication of x coordinates of the first point and the last point |
| - | 191 | minus the mediate value of x coordinates of all the points */ |
|
| 141 |
|
192 | f9_tmp = ((touchBuffer[startIndex].x - (xMax+xMin)/2)*(touchBuffer[endIndex].x - (xMax+xMin)/2)); |
| 142 |
|
193 | f9 = CAN_MODULE_ENUM_TOUCH_GESTURE_F9_MINUS; |
| 143 | if ( |
194 | if (f9_tmp > 0) |
| 144 |
|
195 | { |
| - | 196 | f9 = CAN_MODULE_ENUM_TOUCH_GESTURE_F9_PLUS; |
|
| 145 |
|
197 | } |
| 146 |
|
198 | |
| - | 199 | /* Function 5 checks the sign value of the sum of the x coordinates of all the points that constitute strokes |
|
| - | 200 | minus x coordinates of the first point */ |
|
| - | 201 | f5 = CAN_MODULE_ENUM_TOUCH_GESTURE_F5_MINUS; |
|
| 147 | if (f5_tmp > 0) |
202 | if (f5_tmp > 0) |
| 148 |
|
203 | { |
| - | 204 | f5 = CAN_MODULE_ENUM_TOUCH_GESTURE_F5_PLUS; |
|
| 149 |
|
205 | } |
| 150 |
|
206 | |
| - | 207 | /* Function 4 represents the sign value of the sum of the x coordinates of all the points that constitute strokes |
|
| - | 208 | minus the x coordinates of the last point */ |
|
| - | 209 | f4 = CAN_MODULE_ENUM_TOUCH_GESTURE_F4_MINUS; |
|
| 151 | if (f4_tmp > 0) |
210 | if (f4_tmp > 0) |
| 152 |
|
211 | { |
| - | 212 | f4 = CAN_MODULE_ENUM_TOUCH_GESTURE_F4_PLUS; |
|
| 153 |
|
213 | } |
| 154 |
|
214 | |
| - | 215 | /* Function 8 checks whether or not x coordinates of all the points except for the first point and the last point is between x0 and xn */ |
|
| - | 216 | f8 = CAN_MODULE_ENUM_TOUCH_GESTURE_F8_MINUS; |
|
| 155 | if (xMin < min(touchBuffer[startIndex].x,touchBuffer[endIndex].x) || xMax > max(touchBuffer[startIndex].x,touchBuffer[endIndex].x)) |
217 | if (xMin < min(touchBuffer[startIndex].x,touchBuffer[endIndex].x) || xMax > max(touchBuffer[startIndex].x,touchBuffer[endIndex].x)) |
| 156 |
|
218 | { |
| - | 219 | f8 = CAN_MODULE_ENUM_TOUCH_GESTURE_F8_PLUS; |
|
| 157 |
|
220 | } |
| 158 | f8 = 1; |
- | |
| 159 | 221 | ||
| 160 | //printf("1%u2%c3%c4%c5%c6%c7%u8%c9%c\n", f1, f2, f3, f4, f5, f6, f7, f8, f9); |
222 | //printf("1%u2%c3%c4%c5%c6%c7%u8%c9%c\n", f1, f2, f3, f4, f5, f6, f7, f8, f9); |
| 161 | 223 | ||
| 162 | StdCan_Msg_t txMsg; |
224 | StdCan_Msg_t txMsg; |
| 163 | StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); |
225 | StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); |
| Line 235... | Line 297... | ||
| 235 | rxbufidx=0; |
297 | rxbufidx=0; |
| 236 | } |
298 | } |
| 237 | } |
299 | } |
| 238 | //printf("Y: %d X: %d\n", adyval, adxval); |
300 | //printf("Y: %d X: %d\n", adyval, adxval); |
| 239 | } |
301 | } |
| 240 | else if (rxbufidx > |
302 | else if (rxbufidx > 3) |
| 241 | { |
303 | { |
| 242 | //printf("Released %d\n", rxbufidx); |
304 | //printf("Released %d\n", rxbufidx); |
| 243 |
|
305 | parseBuffer(0, rxbufidx-1); |
| 244 | /*for (uint8_t i = 0; i < rxbufidx; i++) |
306 | /*for (uint8_t i = 0; i < rxbufidx; i++) |
| 245 | { |
307 | { |
| 246 | printf("%3d ", touchBuffer[i].x); |
308 | printf("%3d ", touchBuffer[i].x); |
| 247 | } |
309 | } |
| 248 | printf("\n"); |
310 | printf("\n"); |