Rev 1289 | Rev 1292 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1289 | Rev 1290 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | 1 | ||
| 2 | #include "sns_Touch.h" |
2 | #include "sns_Touch.h" |
| 3 | point touchBuffer[sns_Touch_BUFFERSIZE]; |
3 | point touchBuffer[sns_Touch_BUFFERSIZE]; |
| 4 | uint8_t rxbufidx; |
4 | uint8_t rxbufidx; |
| 5 | uint8_t pushStatus; |
5 | uint8_t pushStatus; |
| - | 6 | ||
| - | 7 | point lastValidPoint; |
|
| 6 | 8 | ||
| 7 | #ifdef sns_Touch_USEEEPROM |
9 | #ifdef sns_Touch_USEEEPROM |
| 8 | #include "sns_Touch_eeprom.h" |
10 | #include "sns_Touch_eeprom.h" |
| 9 | struct eeprom_sns_Touch EEMEM eeprom_sns_Touch = |
11 | struct eeprom_sns_Touch EEMEM eeprom_sns_Touch = |
| 10 | { |
12 | { |
| Line 40... | Line 42... | ||
| 40 | ADC_Init(); |
42 | ADC_Init(); |
| 41 | Timer_SetTimeout(sns_Touch_POLL_TIMER, sns_Touch_POLL_PERIOD , TimerTypeFreeRunning, 0); |
43 | Timer_SetTimeout(sns_Touch_POLL_TIMER, sns_Touch_POLL_PERIOD , TimerTypeFreeRunning, 0); |
| 42 | 44 | ||
| 43 | rxbufidx = 0; |
45 | rxbufidx = 0; |
| 44 | pushStatus = 0; |
46 | pushStatus = 0; |
| - | 47 | lastValidPoint.x=0; |
|
| - | 48 | lastValidPoint.y=0; |
|
| 45 | } |
49 | } |
| 46 | 50 | ||
| 47 | 51 | ||
| 48 | /* |
52 | /* |
| 49 | F1: Klar |
53 | F1: Klar |
| Line 139... | Line 143... | ||
| 139 | } |
143 | } |
| 140 | 144 | ||
| 141 | /* Function 4 represents the sign value of the sum of the x coordinates of all the points that constitute strokes |
145 | /* Function 4 represents the sign value of the sum of the x coordinates of all the points that constitute strokes |
| 142 | minus the x coordinates of the last point */ |
146 | minus the x coordinates of the last point */ |
| 143 | f4_tmp += (int16_t)buffer[i].x - (int16_t)buffer[endIndex].x; |
147 | f4_tmp += (int16_t)buffer[i].x - (int16_t)buffer[endIndex].x; |
| 144 | 148 | ||
| 145 | /* Function 5 checks the sign value of the sum of the x coordinates of all the points that constitute strokes |
149 | /* Function 5 checks the sign value of the sum of the x coordinates of all the points that constitute strokes |
| 146 | minus x coordinates of the first point */ |
150 | minus x coordinates of the first point */ |
| 147 | f5_tmp += (int16_t)buffer[i].x - (int16_t)buffer[startIndex].x; |
151 | f5_tmp += (int16_t)buffer[i].x - (int16_t)buffer[startIndex].x; |
| 148 | } |
152 | } |
| 149 | 153 | ||
| 150 | /* Function 7 indicates the number of intersection points between an input gesture g(x) and all horizontal lines yi, |
154 | /* Function 7 indicates the number of intersection points between an input gesture g(x) and all horizontal lines yi, |
| 151 | where i is between 0 and n, that constitute a gesture*/ |
155 | where i is between 0 and n, that constitute a gesture*/ |
| Line 156... | Line 160... | ||
| 156 | for (uint8_t i = startIndex+1; i < endIndex-1; i++) |
160 | for (uint8_t i = startIndex+1; i < endIndex-1; i++) |
| 157 | { |
161 | { |
| 158 | if (j > buffer[i].y) |
162 | if (j > buffer[i].y) |
| 159 | { |
163 | { |
| 160 | if (f7_sign != '+') |
164 | if (f7_sign != '+') |
| 161 | { |
165 | { |
| 162 | f7_tmp++; |
166 | f7_tmp++; |
| 163 | } |
167 | } |
| 164 | f7_sign = '+'; |
168 | f7_sign = '+'; |
| 165 | } |
169 | } |
| 166 | else { |
170 | else { |
| 167 | if (f7_sign != '-') |
171 | if (f7_sign != '-') |
| 168 | { |
172 | { |
| 169 | f7_tmp++; |
173 | f7_tmp++; |
| 170 | } |
174 | } |
| 171 | f7_sign = '-'; |
175 | f7_sign = '-'; |
| 172 | } |
176 | } |
| 173 | } |
177 | } |
| 174 | if (f7_tmp > functionData.f7) |
178 | if (f7_tmp > functionData.f7) |
| 175 | { |
179 | { |
| 176 | functionData.f7 = f7_tmp; |
180 | functionData.f7 = f7_tmp; |
| 177 | } |
181 | } |
| 178 | } |
182 | } |
| 179 | 183 | ||
| 180 | functionData.f1--; |
184 | functionData.f1--; |
| Line 187... | Line 191... | ||
| 187 | } |
191 | } |
| 188 | 192 | ||
| 189 | /* Function 3 indicates the sign value of area gap between g(x) and f(x) */ |
193 | /* Function 3 indicates the sign value of area gap between g(x) and f(x) */ |
| 190 | functionData.f3 = CAN_MODULE_ENUM_TOUCH_GESTURE_F3_P; |
194 | functionData.f3 = CAN_MODULE_ENUM_TOUCH_GESTURE_F3_P; |
| 191 | if (f3_tmp > 0) |
195 | if (f3_tmp > 0) |
| 192 | { |
196 | { |
| 193 | functionData.f3 = CAN_MODULE_ENUM_TOUCH_GESTURE_F3_M; |
197 | functionData.f3 = CAN_MODULE_ENUM_TOUCH_GESTURE_F3_M; |
| 194 | } |
198 | } |
| 195 | 199 | ||
| 196 | /* Function 9 represents the sign value of the multiplication of x coordinates of the first point and the last point |
200 | /* Function 9 represents the sign value of the multiplication of x coordinates of the first point and the last point |
| 197 | minus the mediate value of x coordinates of all the points */ |
201 | minus the mediate value of x coordinates of all the points */ |
| 198 | f9_tmp = ((buffer[startIndex].x - (xMax+xMin)/2)*(buffer[endIndex].x - (xMax+xMin)/2)); |
202 | f9_tmp = ((buffer[startIndex].x - (xMax+xMin)/2)*(buffer[endIndex].x - (xMax+xMin)/2)); |
| 199 | functionData.f9 = CAN_MODULE_ENUM_TOUCH_GESTURE_F9_M; |
203 | functionData.f9 = CAN_MODULE_ENUM_TOUCH_GESTURE_F9_M; |
| 200 | if (f9_tmp > 0) |
204 | if (f9_tmp > 0) |
| 201 | { |
205 | { |
| 202 | functionData.f9 = CAN_MODULE_ENUM_TOUCH_GESTURE_F9_P; |
206 | functionData.f9 = CAN_MODULE_ENUM_TOUCH_GESTURE_F9_P; |
| 203 | } |
207 | } |
| 204 | 208 | ||
| 205 | /* Function 5 checks the sign value of the sum of the x coordinates of all the points that constitute strokes |
209 | /* Function 5 checks the sign value of the sum of the x coordinates of all the points that constitute strokes |
| 206 | minus x coordinates of the first point */ |
210 | minus x coordinates of the first point */ |
| 207 | functionData.f5 = CAN_MODULE_ENUM_TOUCH_GESTURE_F5_M; |
211 | functionData.f5 = CAN_MODULE_ENUM_TOUCH_GESTURE_F5_M; |
| 208 | if (f5_tmp > 0) |
212 | if (f5_tmp > 0) |
| 209 | { |
213 | { |
| 210 | functionData.f5 = CAN_MODULE_ENUM_TOUCH_GESTURE_F5_P; |
214 | functionData.f5 = CAN_MODULE_ENUM_TOUCH_GESTURE_F5_P; |
| 211 | } |
215 | } |
| 212 | 216 | ||
| 213 | /* Function 4 represents the sign value of the sum of the x coordinates of all the points that constitute strokes |
217 | /* Function 4 represents the sign value of the sum of the x coordinates of all the points that constitute strokes |
| 214 | minus the x coordinates of the last point */ |
218 | minus the x coordinates of the last point */ |
| Line 221... | Line 225... | ||
| 221 | /* 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 */ |
225 | /* 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 */ |
| 222 | functionData.f8 = CAN_MODULE_ENUM_TOUCH_GESTURE_F8_M; |
226 | functionData.f8 = CAN_MODULE_ENUM_TOUCH_GESTURE_F8_M; |
| 223 | if (xMin < min(buffer[startIndex].x,buffer[endIndex].x) || xMax > max(buffer[startIndex].x,buffer[endIndex].x)) |
227 | if (xMin < min(buffer[startIndex].x,buffer[endIndex].x) || xMax > max(buffer[startIndex].x,buffer[endIndex].x)) |
| 224 | { |
228 | { |
| 225 | functionData.f8 = CAN_MODULE_ENUM_TOUCH_GESTURE_F8_P; |
229 | functionData.f8 = CAN_MODULE_ENUM_TOUCH_GESTURE_F8_P; |
| 226 | } |
230 | } |
| 227 | 231 | ||
| 228 | //printf("1%u2%c3%c4%c5%c6%c7%u8%c9%c\n", f1, f2, f3, f4, f5, f6, f7, f8, f9); |
232 | //printf("1%u2%c3%c4%c5%c6%c7%u8%c9%c\n", f1, f2, f3, f4, f5, f6, f7, f8, f9); |
| 229 | 233 | ||
| 230 | return functionData; |
234 | return functionData; |
| 231 | } |
235 | } |
| 232 | 236 | ||
| Line 234... | Line 238... | ||
| 234 | void sns_Touch_Process(void) |
238 | void sns_Touch_Process(void) |
| 235 | { |
239 | { |
| 236 | 240 | ||
| 237 | if (Timer_Expired(sns_Touch_POLL_TIMER)) { |
241 | if (Timer_Expired(sns_Touch_POLL_TIMER)) { |
| 238 | //StdCan_Msg_t txMsg; |
242 | //StdCan_Msg_t txMsg; |
| 239 | gpio_set_in(sns_Touch_XPLUS); |
243 | gpio_set_in(sns_Touch_XPLUS); |
| 240 | gpio_set_pullup(sns_Touch_XPLUS); //turn on pullup for x+ |
244 | gpio_set_pullup(sns_Touch_XPLUS); //turn on pullup for x+ |
| 241 | gpio_set_out(sns_Touch_YPLUS); |
245 | gpio_set_out(sns_Touch_YPLUS); |
| 242 | gpio_set_pin(sns_Touch_YPLUS); //turn on 1 on y+ |
246 | gpio_set_pin(sns_Touch_YPLUS); //turn on 1 on y+ |
| 243 | gpio_set_out(sns_Touch_YMINUS); |
247 | gpio_set_out(sns_Touch_YMINUS); |
| 244 | gpio_clr_pin(sns_Touch_YMINUS); //turn on 0 on y- |
248 | gpio_clr_pin(sns_Touch_YMINUS); //turn on 0 on y- |
| Line 281... | Line 285... | ||
| 281 | adyval = 255-adyval; |
285 | adyval = 255-adyval; |
| 282 | #endif |
286 | #endif |
| 283 | #ifdef sns_Touch_INVERT_X |
287 | #ifdef sns_Touch_INVERT_X |
| 284 | adxval = 255-adxval; |
288 | adxval = 255-adxval; |
| 285 | #endif |
289 | #endif |
| - | 290 | lastValidPoint.x=adxval; |
|
| - | 291 | lastValidPoint.y=adyval; |
|
| 286 | pushStatus = 1; |
292 | pushStatus = 1; |
| 287 | uint8_t xdiff=0; |
293 | uint8_t xdiff=0; |
| 288 | uint8_t ydiff=0; |
294 | uint8_t ydiff=0; |
| 289 | if (rxbufidx > 0) |
295 | if (rxbufidx > 0) |
| 290 | { |
296 | { |
| Line 375... | Line 381... | ||
| 375 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_TOUCH; |
381 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_TOUCH; |
| 376 | txMsg.Header.ModuleId = sns_Touch_ID; |
382 | txMsg.Header.ModuleId = sns_Touch_ID; |
| 377 | txMsg.Header.Command = CAN_MODULE_CMD_TOUCH_RAW; |
383 | txMsg.Header.Command = CAN_MODULE_CMD_TOUCH_RAW; |
| 378 | txMsg.Length = 3; |
384 | txMsg.Length = 3; |
| 379 | txMsg.Data[0] = CAN_MODULE_ENUM_TOUCH_RAW_STATUS_RELEASED; |
385 | txMsg.Data[0] = CAN_MODULE_ENUM_TOUCH_RAW_STATUS_RELEASED; |
| 380 | txMsg.Data[1] = |
386 | txMsg.Data[1] = lastValidPoint.x; |
| 381 | txMsg.Data[2] = |
387 | txMsg.Data[2] = lastValidPoint.y; |
| 382 | 388 | ||
| 383 | StdCan_Put(&txMsg); |
389 | StdCan_Put(&txMsg); |
| 384 | } |
390 | } |
| 385 | } |
391 | } |
| 386 | } |
392 | } |