Rev 1295 | Rev 1307 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1295 | Rev 1296 | ||
|---|---|---|---|
| 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 | point lastValidPoint; |
| - | 7 | ||
| 8 | 8 | ||
| 9 | #ifdef sns_Touch_USEEEPROM |
9 | #ifdef sns_Touch_USEEEPROM |
| 10 | #include "sns_Touch_eeprom.h" |
10 | #include "sns_Touch_eeprom.h" |
| 11 | struct eeprom_sns_Touch EEMEM eeprom_sns_Touch = |
11 | struct eeprom_sns_Touch EEMEM eeprom_sns_Touch = |
| 12 | { |
12 | { |
| Line 33... | Line 33... | ||
| 33 | eeprom_write_word_crc(EEDATA.y, 0x1234, WITHOUT_CRC); |
33 | eeprom_write_word_crc(EEDATA.y, 0x1234, WITHOUT_CRC); |
| 34 | EEDATA_UPDATE_CRC; |
34 | EEDATA_UPDATE_CRC; |
| 35 | } |
35 | } |
| 36 | #endif |
36 | #endif |
| 37 | ///TODO: Initialize hardware etc here |
37 | ///TODO: Initialize hardware etc here |
| 38 | 38 | ||
| 39 | // to use PCINt lib, call this function: (the callback function look as a timer callback function) |
39 | // to use PCINt lib, call this function: (the callback function look as a timer callback function) |
| 40 | // Pcint_SetCallbackPin(sns_Touch_PCINT, EXP_C , &sns_Touch_pcint_callback); |
40 | // Pcint_SetCallbackPin(sns_Touch_PCINT, EXP_C , &sns_Touch_pcint_callback); |
| 41 | 41 | ||
| 42 | ADC_Init(); |
42 | ADC_Init(); |
| 43 | 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); |
| 44 | 44 | ||
| 45 | rxbufidx = 0; |
45 | rxbufidx = 0; |
| 46 | pushStatus = 0; |
46 | pushStatus = 0; |
| 47 | lastValidPoint.x=0; |
47 | lastValidPoint.x=0; |
| 48 | lastValidPoint.y=0; |
48 | lastValidPoint.y=0; |
| 49 | } |
49 | } |
| 50 | - | ||
| 51 | - | ||
| 52 | /* |
- | |
| 53 | F1: Klar |
- | |
| 54 | F2: Klar |
- | |
| 55 | F3: Klar |
- | |
| 56 | F4: Klar |
- | |
| 57 | F5: Klar |
- | |
| 58 | F6: Klar |
- | |
| 59 | F7: Klar |
- | |
| 60 | F8: Klar? (kontrollera funktion) |
- | |
| 61 | F9: Klar |
- | |
| 62 | */ |
- | |
| 63 | - | ||
| 64 | /* |
- | |
| 65 | Touch gesture parser |
- | |
| 66 | Implementation of 'A new gesture recognition algorithm and segmentation |
- | |
| 67 | method of Korean scripts for gesture-allowed ink editor' by Mi Gyung Cho |
- | |
| 68 | - | ||
| 69 | Call function parseBuffer with a buffer containing x/y coordinates, the buffer start and end. |
- | |
| 70 | Returns function results that describe the gesture in 24bits |
- | |
| 71 | - | ||
| 72 | Written by Linus Lundin, Jonas Andersson and Anders Runeson, 2009 |
- | |
| 73 | - | ||
| 74 | To fix: |
- | |
| 75 | Break out to a driver file |
- | |
| 76 | */ |
- | |
| 77 | gesture parseBuffer(point *buffer, uint8_t startIndex, uint8_t endIndex) |
- | |
| 78 | { |
- | |
| 79 | int16_t f1_k = 0, f3_tmp = 0, f4_tmp = 0, f5_tmp = 0; |
- | |
| 80 | uint8_t f7_tmp = 0, f7_sign = 0, f1_sign = 0, f3_yref = 0, xMin, xMax, yMin, yMax, f9_tmp; |
- | |
| 81 | gesture functionData; |
- | |
| 82 | functionData.f1=0; |
- | |
| 83 | functionData.f7=0; |
- | |
| 84 | #define F8_OFFSET 15 |
- | |
| 85 | - | ||
| 86 | /* Function 6 indicates the sign value of the y coordinates of the last point minus y coordinates of the first point */ |
- | |
| 87 | functionData.f6 = CAN_MODULE_ENUM_TOUCH_GESTURE_F6_M; |
- | |
| 88 | if ((int16_t)buffer[endIndex].y - (int16_t)buffer[startIndex].y > 0) |
- | |
| 89 | { |
- | |
| 90 | functionData.f6 = CAN_MODULE_ENUM_TOUCH_GESTURE_F6_P; |
- | |
| 91 | } |
- | |
| 92 | - | ||
| 93 | xMin = buffer[startIndex].x; |
- | |
| 94 | xMax = buffer[startIndex].x; |
- | |
| 95 | yMin = buffer[startIndex].y; |
- | |
| 96 | yMax = buffer[startIndex].y; |
- | |
| 97 | f3_yref = (buffer[startIndex].y + buffer[endIndex].y)/2; |
- | |
| 98 | f1_k = ((buffer[endIndex].y-buffer[startIndex].y)<<4)/(buffer[endIndex].x-buffer[startIndex].x); |
- | |
| 99 | f1_sign = CAN_MODULE_ENUM_TOUCH_GESTURE_F2_U; |
- | |
| 100 | - | ||
| 101 | for (uint8_t i = startIndex+1; i < endIndex-1; i++) |
- | |
| 102 | { |
- | |
| 103 | /* Function 1 indicates the number of intersection points between an input gesture g(x) and the straight line f(x) |
- | |
| 104 | which connects the first and last point of the gesture */ |
- | |
| 105 | if (((f1_k*(buffer[i].x-buffer[0].x))>>4) + buffer[0].y < buffer[i].y) |
- | |
| 106 | { |
- | |
| 107 | if (f1_sign != CAN_MODULE_ENUM_TOUCH_GESTURE_F2_P) |
- | |
| 108 | { |
- | |
| 109 | functionData.f1++; |
- | |
| 110 | } |
- | |
| 111 | f1_sign = CAN_MODULE_ENUM_TOUCH_GESTURE_F2_P; |
- | |
| 112 | } |
- | |
| 113 | else |
- | |
| 114 | { |
- | |
| 115 | if (f1_sign != CAN_MODULE_ENUM_TOUCH_GESTURE_F2_M) |
- | |
| 116 | { |
- | |
| 117 | functionData.f1++; |
- | |
| 118 | } |
- | |
| 119 | f1_sign = CAN_MODULE_ENUM_TOUCH_GESTURE_F2_M; |
- | |
| 120 | } |
- | |
| 121 | - | ||
| 122 | /* Function 3 indicates the sign value of area gap between g(x) and f(x) */ |
- | |
| 123 | if (buffer[i].x > min(buffer[startIndex].x, buffer[endIndex].x) && buffer[i].x < max(buffer[startIndex].x, buffer[endIndex].x)) |
- | |
| 124 | { |
- | |
| 125 | f3_tmp += f3_yref - (buffer[i].y + buffer[i-1].y)/2; |
- | |
| 126 | } |
- | |
| 127 | - | ||
| 128 | /* find min and max of x and y */ |
- | |
| 129 | if (xMin > buffer[i].x) |
- | |
| 130 | { |
- | |
| 131 | xMin = buffer[i].x; |
- | |
| 132 | } |
- | |
| 133 | if (xMax < buffer[i].x) |
- | |
| 134 | { |
- | |
| 135 | xMax = buffer[i].x; |
- | |
| 136 | } |
- | |
| 137 | if (yMin > buffer[i].y) |
- | |
| 138 | { |
- | |
| 139 | yMin = buffer[i].y; |
- | |
| 140 | } |
- | |
| 141 | if (yMax < buffer[i].y) |
- | |
| 142 | { |
- | |
| 143 | yMax = buffer[i].y; |
- | |
| 144 | } |
- | |
| 145 | - | ||
| 146 | /* Function 4 represents the sign value of the sum of the x coordinates of all the points that constitute strokes |
- | |
| 147 | minus the x coordinates of the last point */ |
- | |
| 148 | f4_tmp += (int16_t)buffer[i].x - (int16_t)buffer[endIndex].x; |
- | |
| 149 | - | ||
| 150 | /* Function 5 checks the sign value of the sum of the x coordinates of all the points that constitute strokes |
- | |
| 151 | minus x coordinates of the first point */ |
- | |
| 152 | f5_tmp += (int16_t)buffer[i].x - (int16_t)buffer[startIndex].x; |
- | |
| 153 | } |
- | |
| 154 | - | ||
| 155 | /* Function 7 indicates the number of intersection points between an input gesture g(x) and all horizontal lines yi, |
- | |
| 156 | where i is between 0 and n, that constitute a gesture*/ |
- | |
| 157 | for (uint8_t j = yMin; j < yMax-1; j++) |
- | |
| 158 | { |
- | |
| 159 | f7_tmp = 0xff; |
- | |
| 160 | f7_sign = 0; |
- | |
| 161 | for (uint8_t i = startIndex+1; i < endIndex-1; i++) |
- | |
| 162 | { |
- | |
| 163 | if (j > buffer[i].y) |
- | |
| 164 | { |
- | |
| 165 | if (f7_sign != '+') |
- | |
| 166 | { |
- | |
| 167 | f7_tmp++; |
- | |
| 168 | } |
- | |
| 169 | f7_sign = '+'; |
- | |
| 170 | } |
- | |
| 171 | else { |
- | |
| 172 | if (f7_sign != '-') |
- | |
| 173 | { |
- | |
| 174 | f7_tmp++; |
- | |
| 175 | } |
- | |
| 176 | f7_sign = '-'; |
- | |
| 177 | } |
- | |
| 178 | } |
- | |
| 179 | if (f7_tmp > functionData.f7) |
- | |
| 180 | { |
- | |
| 181 | functionData.f7 = f7_tmp; |
- | |
| 182 | } |
- | |
| 183 | } |
- | |
| 184 | - | ||
| 185 | functionData.f1--; |
- | |
| 186 | /* Function 2 checks if the y coordinates of the points which exist between the intersection point and the last point are |
- | |
| 187 | greater than the y coordinates of the intersection point */ |
- | |
| 188 | functionData.f2 = f1_sign; |
- | |
| 189 | if (functionData.f1 == 0) |
- | |
| 190 | { |
- | |
| 191 | functionData.f2 = CAN_MODULE_ENUM_TOUCH_GESTURE_F2_U; |
- | |
| 192 | } |
- | |
| 193 | - | ||
| 194 | /* Function 3 indicates the sign value of area gap between g(x) and f(x) */ |
- | |
| 195 | functionData.f3 = CAN_MODULE_ENUM_TOUCH_GESTURE_F3_P; |
- | |
| 196 | if (f3_tmp > 0) |
- | |
| 197 | { |
- | |
| 198 | functionData.f3 = CAN_MODULE_ENUM_TOUCH_GESTURE_F3_M; |
- | |
| 199 | } |
- | |
| 200 | - | ||
| 201 | /* Function 9 represents the sign value of the multiplication of x coordinates of the first point and the last point |
- | |
| 202 | minus the mediate value of x coordinates of all the points */ |
- | |
| 203 | //f9_tmp = ((buffer[startIndex].x - (xMax+xMin)/2)*(buffer[endIndex].x - (xMax+xMin)/2)); |
- | |
| 204 | f9_tmp = ((buffer[startIndex].x - (xMax+xMin)/2 > 0) ^ (buffer[endIndex].x - (xMax+xMin)/2 > 0)); |
- | |
| 205 | functionData.f9 = CAN_MODULE_ENUM_TOUCH_GESTURE_F9_M; |
- | |
| 206 | if (!f9_tmp) |
- | |
| 207 | { |
- | |
| 208 | functionData.f9 = CAN_MODULE_ENUM_TOUCH_GESTURE_F9_P; |
- | |
| 209 | } |
- | |
| 210 | - | ||
| 211 | /* Function 5 checks the sign value of the sum of the x coordinates of all the points that constitute strokes |
- | |
| 212 | minus x coordinates of the first point */ |
- | |
| 213 | functionData.f5 = CAN_MODULE_ENUM_TOUCH_GESTURE_F5_M; |
- | |
| 214 | if (f5_tmp > 0) |
- | |
| 215 | { |
- | |
| 216 | functionData.f5 = CAN_MODULE_ENUM_TOUCH_GESTURE_F5_P; |
- | |
| 217 | } |
- | |
| 218 | - | ||
| 219 | /* Function 4 represents the sign value of the sum of the x coordinates of all the points that constitute strokes |
- | |
| 220 | minus the x coordinates of the last point */ |
- | |
| 221 | functionData.f4 = CAN_MODULE_ENUM_TOUCH_GESTURE_F4_M; |
- | |
| 222 | if (f4_tmp > 0) |
- | |
| 223 | { |
- | |
| 224 | functionData.f4 = CAN_MODULE_ENUM_TOUCH_GESTURE_F4_P; |
- | |
| 225 | } |
- | |
| 226 | - | ||
| 227 | /* 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 */ |
- | |
| 228 | functionData.f8 = CAN_MODULE_ENUM_TOUCH_GESTURE_F8_P; |
- | |
| 229 | if (xMin+F8_OFFSET < min(buffer[startIndex].x,buffer[endIndex].x) || xMax > max(buffer[startIndex].x,buffer[endIndex].x)+F8_OFFSET) |
- | |
| 230 | { |
- | |
| 231 | functionData.f8 = CAN_MODULE_ENUM_TOUCH_GESTURE_F8_M; |
- | |
| 232 | } |
- | |
| 233 | - | ||
| 234 | //printf("1%u2%c3%c4%c5%c6%c7%u8%c9%c\n", f1, f2, f3, f4, f5, f6, f7, f8, f9); |
- | |
| 235 | - | ||
| 236 | return functionData; |
- | |
| 237 | } |
- | |
| 238 | - | ||
| 239 | 50 | ||
| 240 | void sns_Touch_Process(void) |
51 | void sns_Touch_Process(void) |
| 241 | { |
52 | { |
| 242 | 53 | ||
| 243 | if (Timer_Expired(sns_Touch_POLL_TIMER)) { |
54 | if (Timer_Expired(sns_Touch_POLL_TIMER)) { |