Subversion Repositories HomeAutomation

Rev

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

Rev 1280 Rev 1284
Line 4... Line 4...
4
uint8_t rxbufidx;
4
uint8_t rxbufidx;
5
 
-
 
-
 
5
uint8_t pushStatus;
6
 
6
 
7
#ifdef sns_Touch_USEEEPROM
7
#ifdef sns_Touch_USEEEPROM
8
#include "sns_Touch_eeprom.h"
8
#include "sns_Touch_eeprom.h"
9
struct eeprom_sns_Touch EEMEM eeprom_sns_Touch =
9
struct eeprom_sns_Touch EEMEM eeprom_sns_Touch =
10
{
10
{
11
    {
11
    {
12
        ///TODO: Define initialization values on the EEPROM variables here, this will generate a *.eep file that can be used to store this values to the node, can in future be done with a EEPROM module and the make-scrips. Write the values in the exact same order as the struct is defined in the *.h file. 
12
        ///TODO: Define initialization values on the EEPROM variables here, this will generate a *.eep file that can be used to store this values to the node, can in future be done with a EEPROM module and the make-scrips. Write the values in the exact same order as the struct is defined in the *.h file. 
13
        0xAB,   // x
13
        0xAB,   // x
14
        0x1234  // y
14
        0x1234  // y
15
    },
15
    },
16
    0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
16
    0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
Line 28... Line 28...
28
    } else
28
    } else
29
    {   //The CRC of the EEPROM is not correct, store default values and update CRC
29
    {   //The CRC of the EEPROM is not correct, store default values and update CRC
30
      eeprom_write_byte_crc(EEDATA.x, 0xAB, WITHOUT_CRC);
30
      eeprom_write_byte_crc(EEDATA.x, 0xAB, WITHOUT_CRC);
31
      eeprom_write_word_crc(EEDATA.y, 0x1234, WITHOUT_CRC);
31
      eeprom_write_word_crc(EEDATA.y, 0x1234, WITHOUT_CRC);
32
      EEDATA_UPDATE_CRC;
32
      EEDATA_UPDATE_CRC;
33
    }
33
    }
34
#endif  
34
#endif  
35
    ///TODO: Initialize hardware etc here
35
    ///TODO: Initialize hardware etc here
36
 
36
 
37
    // to use PCINt lib, call this function: (the callback function look as a timer callback function)
37
    // to use PCINt lib, call this function: (the callback function look as a timer callback function)
38
    // Pcint_SetCallbackPin(sns_Touch_PCINT, EXP_C , &sns_Touch_pcint_callback);
38
    // Pcint_SetCallbackPin(sns_Touch_PCINT, EXP_C , &sns_Touch_pcint_callback);
39
 
39
 
40
    ADC_Init();
40
    ADC_Init();
41
    Timer_SetTimeout(sns_Touch_POLL_TIMER, sns_Touch_POLL_PERIOD , TimerTypeFreeRunning, 0);
41
    Timer_SetTimeout(sns_Touch_POLL_TIMER, sns_Touch_POLL_PERIOD , TimerTypeFreeRunning, 0);
42
   
42
   
43
    rxbufidx = 0;
43
    rxbufidx = 0;
-
 
44
    pushStatus = 0;
44
}
45
}
45
 
46
 
46
 
47
 
47
/*
48
/*
48
F1: Klar
49
F1: Klar
49
F2: Klar
50
F2: Klar
50
F3: Klar
51
F3: Klar
51
F4: Klar
52
F4: Klar
Line 118... Line 119...
118
        if (xMin > touchBuffer[i].x)
119
        if (xMin > touchBuffer[i].x)
119
        {
120
        {
120
            xMin = touchBuffer[i].x;
121
            xMin = touchBuffer[i].x;
121
        }
122
        }
122
        if (xMax < touchBuffer[i].x)
123
        if (xMax < touchBuffer[i].x)
123
        {
124
        {
124
            xMax = touchBuffer[i].x;
125
            xMax = touchBuffer[i].x;
125
        }
126
        }
126
        if (yMin > touchBuffer[i].y)
127
        if (yMin > touchBuffer[i].y)
127
        {
128
        {
128
            yMin = touchBuffer[i].y;
129
            yMin = touchBuffer[i].y;
129
        }
130
        }
130
        if (yMax < touchBuffer[i].y)
131
        if (yMax < touchBuffer[i].y)
131
        {
132
        {
132
            yMax = touchBuffer[i].y;
133
            yMax = touchBuffer[i].y;
133
        }
134
        }
134
       
135
       
135
        /* Function 4 represents the sign value of the sum of the x coordinates of all the points that constitute strokes
136
        /* 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 */
137
        minus the x coordinates of the last point */
137
        f4_tmp += (int16_t)touchBuffer[i].x - (int16_t)touchBuffer[endIndex].x;
138
        f4_tmp += (int16_t)touchBuffer[i].x - (int16_t)touchBuffer[endIndex].x;
138
       
139
       
139
        /* Function 5 checks the sign value of the sum of the x coordinates of all the points that constitute strokes
140
        /* 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 */
141
        minus x coordinates of the first point */
141
        f5_tmp += (int16_t)touchBuffer[i].x - (int16_t)touchBuffer[startIndex].x;
142
        f5_tmp += (int16_t)touchBuffer[i].x - (int16_t)touchBuffer[startIndex].x;
142
    }
143
    }
143
   
144
   
Line 148... Line 149...
148
        f7_tmp = 0xff;
149
        f7_tmp = 0xff;
149
        f7_sign = 0;
150
        f7_sign = 0;
150
        for (uint8_t i = startIndex+1; i < endIndex-1; i++)
151
        for (uint8_t i = startIndex+1; i < endIndex-1; i++)
151
        {
152
        {
152
            if (j > touchBuffer[i].y)
153
            if (j > touchBuffer[i].y)
153
            {
154
            {
154
                if (f7_sign != '+')
155
                if (f7_sign != '+')
155
                {
156
                {
156
                    f7_tmp++;
157
                    f7_tmp++;
157
                }
158
                }
158
                f7_sign = '+';
159
                f7_sign = '+';
159
            }
160
            }
160
            else {
161
            else {
161
                if (f7_sign != '-')
162
                if (f7_sign != '-')
162
                {
163
                {
163
                    f7_tmp++;
164
                    f7_tmp++;
164
                }
165
                }
165
                f7_sign = '-';
166
                f7_sign = '-';
166
            }
167
            }
167
        }
168
        }
Line 270... Line 271...
270
        gpio_set_in(sns_Touch_YPLUS);
271
        gpio_set_in(sns_Touch_YPLUS);
271
        gpio_clr_pullup(sns_Touch_YPLUS);   //turn off pullup for y+
272
        gpio_clr_pullup(sns_Touch_YPLUS);   //turn off pullup for y+
272
       
273
       
273
        if (adyval < 0xf0 && adxval < 0xf0 )
274
        if (adyval < 0xf0 && adxval < 0xf0 )
274
        {
275
        {
-
 
276
            pushStatus = 1;
275
            uint8_t xdiff=0;
277
            uint8_t xdiff=0;
276
            uint8_t ydiff=0;
278
            uint8_t ydiff=0;
277
            if (rxbufidx > 0)
279
            if (rxbufidx > 0)
278
            {
280
            {
279
                xdiff = touchBuffer[rxbufidx-1].x - adxval;
281
                xdiff = touchBuffer[rxbufidx-1].x - adxval;
Line 294... Line 296...
294
                rxbufidx++;
296
                rxbufidx++;
295
                if (rxbufidx==sns_Touch_BUFFERSIZE)
297
                if (rxbufidx==sns_Touch_BUFFERSIZE)
296
                {
298
                {
297
                    rxbufidx=0;
299
                    rxbufidx=0;
298
                }
300
                }
-
 
301
 
-
 
302
                StdCan_Msg_t txMsg;
-
 
303
                StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
-
 
304
                StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
-
 
305
                txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_TOUCH;
-
 
306
                txMsg.Header.ModuleId = sns_Touch_ID;
-
 
307
                txMsg.Header.Command = CAN_MODULE_CMD_TOUCH_RAW;
-
 
308
                txMsg.Length = 3;
-
 
309
                txMsg.Data[0] = CAN_MODULE_ENUM_TOUCH_RAW_STATUS_PRESSED;
-
 
310
                txMsg.Data[1] = adxval;
-
 
311
                txMsg.Data[2] = adyval;
-
 
312
   
-
 
313
                StdCan_Put(&txMsg);
299
            }
314
            }
300
            //printf("Y: %d X: %d\n", adyval, adxval);
315
            //printf("Y: %d X: %d\n", adyval, adxval);
301
        }
316
        }
302
        else if (rxbufidx > 3)
317
        else if (rxbufidx > 3)
303
        {
318
        {
-
 
319
            pushStatus = 2;
304
            //printf("Released %d\n", rxbufidx);
320
            //printf("Released %d\n", rxbufidx);
305
            parseBuffer(0, rxbufidx-1);
321
            parseBuffer(0, rxbufidx-1);
306
            /*for (uint8_t i = 0; i < rxbufidx; i++)
322
            /*for (uint8_t i = 0; i < rxbufidx; i++)
307
            {
323
            {
308
                printf("%3d ", touchBuffer[i].x);
324
                printf("%3d ", touchBuffer[i].x);
Line 314... Line 330...
314
            }
330
            }
315
            printf("\n");
331
            printf("\n");
316
            */
332
            */
317
           
333
           
318
            rxbufidx = 0;
334
            rxbufidx = 0;
-
 
335
        }
-
 
336
        else
-
 
337
        {
-
 
338
            pushStatus = 2;
-
 
339
        }
-
 
340
       
-
 
341
        if (pushStatus == 2)
-
 
342
        {
-
 
343
            pushStatus = 0;
-
 
344
           
-
 
345
            StdCan_Msg_t txMsg;
-
 
346
            StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
-
 
347
            StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
-
 
348
            txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_TOUCH;
-
 
349
            txMsg.Header.ModuleId = sns_Touch_ID;
-
 
350
            txMsg.Header.Command = CAN_MODULE_CMD_TOUCH_RAW;
-
 
351
            txMsg.Length = 3;
-
 
352
            txMsg.Data[0] = CAN_MODULE_ENUM_TOUCH_RAW_STATUS_RELEASED;
-
 
353
            txMsg.Data[1] = adxval;
-
 
354
            txMsg.Data[2] = adyval;
-
 
355
 
-
 
356
            StdCan_Put(&txMsg);
319
        }
357
        }
320
    }
358
    }
321
}
359
}
322
 
360
 
323
 
361