Subversion Repositories HomeAutomation

Rev

Rev 1285 | Rev 1287 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1285 Rev 1286
Line 59... Line 59...
59
*/
59
*/
60
 
60
 
61
 
61
 
62
/*
62
/*
63
To fix:
63
To fix:
64
Input parameter for buffer
-
 
65
Output returnvalues
-
 
66
Break out to a driver file
64
Break out to a driver file
67
*/
65
*/
68
uint8_t parseBuffer(uint8_t startIndex, uint8_t endIndex)
66
gesture parseBuffer(point *buffer, uint8_t startIndex, uint8_t endIndex)
69
{
67
{
70
    int16_t f1_k = 0, f3_tmp = 0, f4_tmp = 0, f5_tmp = 0, f9_tmp = 0;
68
    int16_t f1_k = 0, f3_tmp = 0, f4_tmp = 0, f5_tmp = 0, f9_tmp = 0;
71
    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;
69
    uint8_t f7_tmp = 0, f7_sign = 0, f1_sign = 0, f3_yref = 0, xMin, xMax, yMin, yMax;
-
 
70
    gesture functionData;
-
 
71
    functionData.f1=0;
-
 
72
    functionData.f7=0;
72
   
73
   
73
    /* Function 6 indicates the sign value of the y coordinates of the last point minus y coordinates of the first point */
74
    /* Function 6 indicates the sign value of the y coordinates of the last point minus y coordinates of the first point */
-
 
75
    functionData.f6 = CAN_MODULE_ENUM_TOUCH_GESTURE_F6_M;
74
    if ((int16_t)touchBuffer[endIndex].y - (int16_t)touchBuffer[startIndex].y > 0)
76
    if ((int16_t)buffer[endIndex].y - (int16_t)buffer[startIndex].y > 0)
75
    {
77
    {
76
        f6 = CAN_MODULE_ENUM_TOUCH_GESTURE_F6_P;
78
        functionData.f6 = CAN_MODULE_ENUM_TOUCH_GESTURE_F6_P;
77
    }
79
    }
78
    else
-
 
79
    {
-
 
80
        f6 = CAN_MODULE_ENUM_TOUCH_GESTURE_F6_M;
-
 
81
    }
-
 
82
   
80
   
83
    xMin = touchBuffer[startIndex].x;
81
    xMin = buffer[startIndex].x;
84
    xMax = touchBuffer[startIndex].x;
82
    xMax = buffer[startIndex].x;
85
    yMin = touchBuffer[startIndex].y;
83
    yMin = buffer[startIndex].y;
86
    yMax = touchBuffer[startIndex].y;
84
    yMax = buffer[startIndex].y;
87
    f3_yref = (touchBuffer[startIndex].y + touchBuffer[endIndex].y)/2;
85
    f3_yref = (buffer[startIndex].y + buffer[endIndex].y)/2;
88
    f1_k = ((touchBuffer[endIndex].y-touchBuffer[startIndex].y)<<4)/(touchBuffer[endIndex].x-touchBuffer[startIndex].x);
86
    f1_k = ((buffer[endIndex].y-buffer[startIndex].y)<<4)/(buffer[endIndex].x-buffer[startIndex].x);
89
    f1_sign = CAN_MODULE_ENUM_TOUCH_GESTURE_F2_U;
87
    f1_sign = CAN_MODULE_ENUM_TOUCH_GESTURE_F2_U;
90
 
88
 
91
    for (uint8_t i = startIndex+1; i < endIndex-1; i++)
89
    for (uint8_t i = startIndex+1; i < endIndex-1; i++)
92
    {
90
    {
93
        /* Function 1 indicates the number of intersection points between an input gesture g(x) and the straight line f(x)
91
        /* Function 1 indicates the number of intersection points between an input gesture g(x) and the straight line f(x)
94
        which connects the first and last point of the gesture */
92
        which connects the first and last point of the gesture */
95
        if (((f1_k*(touchBuffer[i].x-touchBuffer[0].x))>>4) + touchBuffer[0].y < touchBuffer[i].y)
93
        if (((f1_k*(buffer[i].x-buffer[0].x))>>4) + buffer[0].y < buffer[i].y)
96
        {
94
        {
97
            if (f1_sign != CAN_MODULE_ENUM_TOUCH_GESTURE_F2_P)
95
            if (f1_sign != CAN_MODULE_ENUM_TOUCH_GESTURE_F2_P)
98
            {
96
            {
99
                f1++;
97
                functionData.f1++;
100
            }
98
            }
101
            f1_sign = CAN_MODULE_ENUM_TOUCH_GESTURE_F2_P;
99
            f1_sign = CAN_MODULE_ENUM_TOUCH_GESTURE_F2_P;
102
        }
100
        }
103
        else
101
        else
104
        {
102
        {
105
            if (f1_sign != CAN_MODULE_ENUM_TOUCH_GESTURE_F2_M)
103
            if (f1_sign != CAN_MODULE_ENUM_TOUCH_GESTURE_F2_M)
106
            {
104
            {
107
                f1++;
105
                functionData.f1++;
108
            }
106
            }
109
            f1_sign = CAN_MODULE_ENUM_TOUCH_GESTURE_F2_M;
107
            f1_sign = CAN_MODULE_ENUM_TOUCH_GESTURE_F2_M;
110
        }
108
        }
111
       
109
       
112
        /* Function 3 indicates the sign value of area gap between g(x) and f(x) */
110
        /* Function 3 indicates the sign value of area gap between g(x) and f(x) */
113
        if (touchBuffer[i].x > min(touchBuffer[startIndex].x, touchBuffer[endIndex].x) && touchBuffer[i].x < max(touchBuffer[startIndex].x, touchBuffer[endIndex].x))
111
        if (buffer[i].x > min(buffer[startIndex].x, buffer[endIndex].x) && buffer[i].x < max(buffer[startIndex].x, buffer[endIndex].x))
114
        {
112
        {
115
            f3_tmp += f3_yref - (touchBuffer[i].y + touchBuffer[i-1].y)/2;
113
            f3_tmp += f3_yref - (buffer[i].y + buffer[i-1].y)/2;
-
 
114
        }
-
 
115
       
-
 
116
        /* find min an max of x and y */
-
 
117
        if (xMin > buffer[i].x)
-
 
118
        {
-
 
119
            xMin = buffer[i].x;
116
        }
120
        }
117
       
-
 
118
        /* find min an max of x and y */
-
 
119
        if (xMin > touchBuffer[i].x)
-
 
120
        {
-
 
121
            xMin = touchBuffer[i].x;
-
 
122
        }
-
 
123
        if (xMax < touchBuffer[i].x)
121
        if (xMax < buffer[i].x)
124
        {
122
        {
125
            xMax = touchBuffer[i].x;
123
            xMax = buffer[i].x;
126
        }
-
 
127
        if (yMin > touchBuffer[i].y)
-
 
128
        {
-
 
129
            yMin = touchBuffer[i].y;
-
 
130
        }
124
        }
131
        if (yMax < touchBuffer[i].y)
125
        if (yMin > buffer[i].y)
132
        {
126
        {
-
 
127
            yMin = buffer[i].y;
-
 
128
        }
-
 
129
        if (yMax < buffer[i].y)
-
 
130
        {
133
            yMax = touchBuffer[i].y;
131
            yMax = buffer[i].y;
134
        }
132
        }
135
       
133
       
136
        /* Function 4 represents the sign value of the sum of the x coordinates of all the points that constitute strokes
134
        /* Function 4 represents the sign value of the sum of the x coordinates of all the points that constitute strokes
137
        minus the x coordinates of the last point */
135
        minus the x coordinates of the last point */
138
        f4_tmp += (int16_t)touchBuffer[i].x - (int16_t)touchBuffer[endIndex].x;
136
        f4_tmp += (int16_t)buffer[i].x - (int16_t)buffer[endIndex].x;
139
       
137
       
140
        /* Function 5 checks the sign value of the sum of the x coordinates of all the points that constitute strokes
138
        /* Function 5 checks the sign value of the sum of the x coordinates of all the points that constitute strokes
141
        minus x coordinates of the first point */
139
        minus x coordinates of the first point */
142
        f5_tmp += (int16_t)touchBuffer[i].x - (int16_t)touchBuffer[startIndex].x;
140
        f5_tmp += (int16_t)buffer[i].x - (int16_t)buffer[startIndex].x;
143
    }
141
    }
144
   
142
   
145
    /* Function 7 indicates the number of intersection points between an input gesture g(x) and all horizontal lines yi,
143
    /* Function 7 indicates the number of intersection points between an input gesture g(x) and all horizontal lines yi,
146
    where i is between 0 and n, that constitute a gesture*/
144
    where i is between 0 and n, that constitute a gesture*/
147
    for (uint8_t j = yMin; j < yMax-1; j++)
145
    for (uint8_t j = yMin; j < yMax-1; j++)
148
    {
146
    {
149
        f7_tmp = 0xff;
147
        f7_tmp = 0xff;
150
        f7_sign = 0;
148
        f7_sign = 0;
151
        for (uint8_t i = startIndex+1; i < endIndex-1; i++)
149
        for (uint8_t i = startIndex+1; i < endIndex-1; i++)
152
        {
150
        {
153
            if (j > touchBuffer[i].y)
151
            if (j > buffer[i].y)
154
            {
152
            {
155
                if (f7_sign != '+')
153
                if (f7_sign != '+')
156
                {
154
                {
157
                    f7_tmp++;
155
                    f7_tmp++;
158
                }
156
                }
Line 164... Line 162...
164
                    f7_tmp++;
162
                    f7_tmp++;
165
                }
163
                }
166
                f7_sign = '-';
164
                f7_sign = '-';
167
            }
165
            }
168
        }
166
        }
169
        if (f7_tmp > f7)
167
        if (f7_tmp > functionData.f7)
170
        {
168
        {
171
            f7 = f7_tmp;
169
            functionData.f7 = f7_tmp;
172
        }
170
        }
173
    }
171
    }
174
   
172
   
175
    f1--;
173
    functionData.f1--;
176
    /* Function 2 checks if the y coordinates of the points which exist between the intersection point and the last point are
174
    /* Function 2 checks if the y coordinates of the points which exist between the intersection point and the last point are
177
    greater than the y coordinates of the intersection point */
175
    greater than the y coordinates of the intersection point */
178
    f2 = f1_sign;
176
    functionData.f2 = f1_sign;
179
    if (f1 == 0)
177
    if (functionData.f1 == 0)
180
    {
178
    {
181
        f2 = CAN_MODULE_ENUM_TOUCH_GESTURE_F2_U;
179
        functionData.f2 = CAN_MODULE_ENUM_TOUCH_GESTURE_F2_U;
182
    }
180
    }
183
   
181
   
184
    /* Function 3 indicates the sign value of area gap between g(x) and f(x) */
182
    /* Function 3 indicates the sign value of area gap between g(x) and f(x) */
185
    f3 = CAN_MODULE_ENUM_TOUCH_GESTURE_F3_P;
183
    functionData.f3 = CAN_MODULE_ENUM_TOUCH_GESTURE_F3_P;
186
    if (f3_tmp > 0)
184
    if (f3_tmp > 0)
187
    {
185
    {
188
        f3 = CAN_MODULE_ENUM_TOUCH_GESTURE_F3_M;
186
        functionData.f3 = CAN_MODULE_ENUM_TOUCH_GESTURE_F3_M;
189
    }
187
    }
190
       
188
       
191
    /* Function 9 represents the sign value of the multiplication of x coordinates of the first point and the last point
189
    /* Function 9 represents the sign value of the multiplication of x coordinates of the first point and the last point
192
    minus the mediate value of x coordinates of all the points */
190
    minus the mediate value of x coordinates of all the points */
193
    f9_tmp = ((touchBuffer[startIndex].x - (xMax+xMin)/2)*(touchBuffer[endIndex].x - (xMax+xMin)/2));
191
    f9_tmp = ((buffer[startIndex].x - (xMax+xMin)/2)*(buffer[endIndex].x - (xMax+xMin)/2));
194
    f9 = CAN_MODULE_ENUM_TOUCH_GESTURE_F9_M;
192
    functionData.f9 = CAN_MODULE_ENUM_TOUCH_GESTURE_F9_M;
195
    if (f9_tmp > 0)
193
    if (f9_tmp > 0)
196
    {
194
    {
197
        f9 = CAN_MODULE_ENUM_TOUCH_GESTURE_F9_P;
195
        functionData.f9 = CAN_MODULE_ENUM_TOUCH_GESTURE_F9_P;
198
    }
196
    }
199
   
197
   
200
    /* Function 5 checks the sign value of the sum of the x coordinates of all the points that constitute strokes
198
    /* Function 5 checks the sign value of the sum of the x coordinates of all the points that constitute strokes
201
    minus x coordinates of the first point */
199
    minus x coordinates of the first point */
202
    f5 = CAN_MODULE_ENUM_TOUCH_GESTURE_F5_M;
200
    functionData.f5 = CAN_MODULE_ENUM_TOUCH_GESTURE_F5_M;
203
    if (f5_tmp > 0)
201
    if (f5_tmp > 0)
204
    {
202
    {
205
        f5 = CAN_MODULE_ENUM_TOUCH_GESTURE_F5_P;
203
        functionData.f5 = CAN_MODULE_ENUM_TOUCH_GESTURE_F5_P;
206
    }
204
    }
207
   
205
   
208
    /* Function 4 represents the sign value of the sum of the x coordinates of all the points that constitute strokes
206
    /* Function 4 represents the sign value of the sum of the x coordinates of all the points that constitute strokes
209
    minus the x coordinates of the last point */
207
    minus the x coordinates of the last point */
210
    f4 = CAN_MODULE_ENUM_TOUCH_GESTURE_F4_M;
208
    functionData.f4 = CAN_MODULE_ENUM_TOUCH_GESTURE_F4_M;
211
    if (f4_tmp > 0)
209
    if (f4_tmp > 0)
212
    {
210
    {
213
        f4 = CAN_MODULE_ENUM_TOUCH_GESTURE_F4_P;
211
        functionData.f4 = CAN_MODULE_ENUM_TOUCH_GESTURE_F4_P;
214
    }
212
    }
215
   
213
   
216
    /* 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 */
214
    /* 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 */
217
    f8 = CAN_MODULE_ENUM_TOUCH_GESTURE_F8_M;
215
    functionData.f8 = CAN_MODULE_ENUM_TOUCH_GESTURE_F8_M;
218
    if (xMin < min(touchBuffer[startIndex].x,touchBuffer[endIndex].x) || xMax > max(touchBuffer[startIndex].x,touchBuffer[endIndex].x))
216
    if (xMin < min(buffer[startIndex].x,buffer[endIndex].x) || xMax > max(buffer[startIndex].x,buffer[endIndex].x))
219
    {
217
    {
220
        f8 = CAN_MODULE_ENUM_TOUCH_GESTURE_F8_P;
218
        functionData.f8 = CAN_MODULE_ENUM_TOUCH_GESTURE_F8_P;
221
    }
219
    }
222
       
220
       
223
    //printf("1%u2%c3%c4%c5%c6%c7%u8%c9%c\n", f1, f2, f3, f4, f5, f6, f7, f8, f9);
221
    //printf("1%u2%c3%c4%c5%c6%c7%u8%c9%c\n", f1, f2, f3, f4, f5, f6, f7, f8, f9);
224
 
222
 
225
    StdCan_Msg_t txMsg;
-
 
226
    StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
-
 
227
    StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
-
 
228
    txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_TOUCH;
-
 
229
    txMsg.Header.ModuleId = sns_Touch_ID;
-
 
230
    txMsg.Header.Command = CAN_MODULE_CMD_TOUCH_GESTURE;
-
 
231
    txMsg.Length = 3;
-
 
232
    txMsg.Data[0] = f1;
-
 
233
    txMsg.Data[1] = f7;
-
 
234
    txMsg.Data[2] = f3<<7|f4<<6|f5<<5|f6<<4|f8<<3|f9<<2|f2;
-
 
235
   
-
 
236
    StdCan_Put(&txMsg);
-
 
237
    return 0;
223
    return functionData;
238
}
224
}
239
 
225
 
240
 
226
 
241
void sns_Touch_Process(void)
227
void sns_Touch_Process(void)
242
{
228
{
Line 252... Line 238...
252
        uint8_t adxval = ADC_Get(sns_Touch_TOUCHXAD)>>2;    //read x-
238
        uint8_t adxval = ADC_Get(sns_Touch_TOUCHXAD)>>2;    //read x-
253
        gpio_set_in(sns_Touch_YPLUS);
239
        gpio_set_in(sns_Touch_YPLUS);
254
        gpio_clr_pullup(sns_Touch_YPLUS);   //turn off pullup for y+
240
        gpio_clr_pullup(sns_Touch_YPLUS);   //turn off pullup for y+
255
        gpio_set_in(sns_Touch_YMINUS);
241
        gpio_set_in(sns_Touch_YMINUS);
256
        gpio_clr_pullup(sns_Touch_YMINUS);  //turn off pullup for y-
242
        gpio_clr_pullup(sns_Touch_YMINUS);  //turn off pullup for y-
257
        gpio_set_in(sns_Touch_XPLUS);
243
        gpio_set_in(sns_Touch_XPLUS);
258
        gpio_clr_pullup(sns_Touch_XPLUS);   //turn off pullup for x+
244
        gpio_clr_pullup(sns_Touch_XPLUS);   //turn off pullup for x+
259
       
245
       
260
        gpio_set_in(sns_Touch_YPLUS);
246
        gpio_set_in(sns_Touch_YPLUS);
261
        gpio_set_pullup(sns_Touch_YPLUS);   //turn on pullup for y+
247
        gpio_set_pullup(sns_Touch_YPLUS);   //turn on pullup for y+
262
        gpio_set_out(sns_Touch_XPLUS);
248
        gpio_set_out(sns_Touch_XPLUS);
263
        gpio_set_pin(sns_Touch_XPLUS);      //turn on 1 on x+
249
        gpio_set_pin(sns_Touch_XPLUS);      //turn on 1 on x+
264
        gpio_set_out(sns_Touch_XMINUS);
250
        gpio_set_out(sns_Touch_XMINUS);
Line 319... Line 305...
319
            if (pushStatus==1)
305
            if (pushStatus==1)
320
            {
306
            {
321
                pushStatus = 2;
307
                pushStatus = 2;
322
            }
308
            }
323
            //printf("Released %d\n", rxbufidx);
309
            //printf("Released %d\n", rxbufidx);
324
            parseBuffer(0, rxbufidx-1);
310
            gesture functionData = parseBuffer(touchBuffer, 0, rxbufidx-1);
-
 
311
           
-
 
312
            StdCan_Msg_t txMsg;
-
 
313
            StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
-
 
314
            StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
-
 
315
            txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_TOUCH;
-
 
316
            txMsg.Header.ModuleId = sns_Touch_ID;
-
 
317
            txMsg.Header.Command = CAN_MODULE_CMD_TOUCH_GESTURE;
-
 
318
            txMsg.Length = 3;
-
 
319
            txMsg.Data[0] = functionData.f1;
-
 
320
            txMsg.Data[1] = functionData.f7;
-
 
321
            txMsg.Data[2] = functionData.f3<<7|functionData.f4<<6|functionData.f5<<5|functionData.f6<<4|functionData.f8<<3|functionData.f9<<2|functionData.f2;
-
 
322
   
-
 
323
            StdCan_Put(&txMsg);
325
            /*for (uint8_t i = 0; i < rxbufidx; i++)
324
            /*for (uint8_t i = 0; i < rxbufidx; i++)
326
            {
325
            {
327
                printf("%3d ", touchBuffer[i].x);
326
                printf("%3d ", touchBuffer[i].x);
328
            }
327
            }
329
            printf("\n");
328
            printf("\n");