Subversion Repositories Projects

Rev

Rev 426 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 426 Rev 434
1
#include "timer0.h"
1
#include "timer0.h"
2
#include "button.h"
2
#include "button.h"
-
 
3
#include "printf_P.h"
3
 
4
 
4
 
5
 
5
#ifdef USE_FOLLOWME
6
#ifdef USE_FOLLOWME
6
#define BUTTON       !(PINC & (1<<PINC6))
7
#define BUTTON       !(PINC & (1<<PINC6))
7
#endif
8
#endif
8
#ifdef USE_SDLOGGER
9
#ifdef USE_SDLOGGER
9
#define BUTTON       !(PINC & (1<<PINC3))
10
#define BUTTON       !(PINC & (1<<PINC3))
10
#endif
11
#endif
11
 
12
 
12
#define CNT_KEY     10 // at least 3
13
#define CNT_KEY     10 // at least 3
13
#define KEY_DELAY_MS  50
14
#define KEY_DELAY_MS  50
14
 
15
 
15
uint16_t ButtonTimer = 0;
16
uint16_t ButtonTimer = 0;
16
 
17
 
17
void Button_Init(void)
18
void Button_Init(void)
18
{
19
{
19
 
-
 
-
 
20
        printf("\r\n BUTTON init...");
20
        // set port pin as input pullup
21
        // set port pin as input pullup
21
        #ifdef USE_FOLLOWME
22
        #ifdef USE_FOLLOWME
22
        PORTC |= (1 << PORTC6);
23
        PORTC |= (1 << PORTC6);
23
        DDRC &= ~(1 << DDC6);
24
        DDRC &= ~(1 << DDC6);
24
        #endif
25
        #endif
25
 
26
 
26
        #ifdef USE_SDLOGGER
27
        #ifdef USE_SDLOGGER
27
        PORTC |= (1 << PORTC3);
28
        PORTC |= (1 << PORTC3);
28
        DDRC &= ~(1 << DDC3);
29
        DDRC &= ~(1 << DDC3);
29
        #endif
30
        #endif
30
        ButtonTimer = SetDelay(KEY_DELAY_MS);
31
        ButtonTimer = SetDelay(KEY_DELAY_MS);
-
 
32
        printf("ok");
31
}
33
}
32
 
34
 
33
uint8_t GetButton(void)
35
uint8_t GetButton(void)
34
{
36
{
35
        static uint8_t button = 0;
37
        static uint8_t button = 0;
36
        uint8_t ret = 0;
38
        uint8_t ret = 0;
37
 
39
 
38
        if(CheckDelay(ButtonTimer))
40
        if(CheckDelay(ButtonTimer))
39
        {
41
        {
40
                if(BUTTON)
42
                if(BUTTON)
41
                {
43
                {
42
                        if(button++ == 0 || button == CNT_KEY) ret = 1;
44
                        if(button++ == 0 || button == CNT_KEY) ret = 1;
43
                        if(button == CNT_KEY) button = CNT_KEY - CNT_KEY / 3;
45
                        if(button == CNT_KEY) button = CNT_KEY - CNT_KEY / 3;
44
                }
46
                }
45
                else button = 0;
47
                else button = 0;
46
                ButtonTimer = SetDelay(KEY_DELAY_MS);
48
                ButtonTimer = SetDelay(KEY_DELAY_MS);
47
        }
49
        }
48
        return(ret);
50
        return(ret);
49
}
51
}
50
 
52
 
51
 
53