Guten morgen!
Ich haba ein Problem mit der Tastenentprellung von Peda. Also insgesamt
läuft die Geschichte fantastisch! Aber jetzt versuche ich gerade das
"repeat_next" zu verändern um bei länger gedrückten Tasten die
Repeat-Funktion zu verschnellern.
Ich habe eine "button_functions.h" und eine "button_functions.c"
button_functions.h
1 | // button_functions.h
|
2 |
|
3 | #ifndef BUTTON_FUNCTIONS_H
|
4 | #define BUTTON_FUNCTIONS_H
|
5 |
|
6 | #include "button_mcu_specific_definitions.h"
|
7 | #include <stdint.h>
|
8 |
|
9 |
|
10 |
|
11 | static uint8_t repeat_next = 20;
|
12 |
|
13 |
|
14 | #define BUTTON_P ( (get_button_short (BUTTON_3)) \
|
15 | || (get_button_long (BUTTON_3)) )
|
16 | #define BUTTON_PLUS ( (get_button_short (BUTTON_1)) \
|
17 | || (get_button_long (BUTTON_1)) )
|
18 | #define BUTTON_MINUS ( (get_button_short (BUTTON_2)) \
|
19 | || (get_button_long (BUTTON_2)) )
|
20 | ...
|
21 | ...
|
22 | void check_buttons( void );
|
23 |
|
24 | uint8_t get_button_press (uint8_t button_mask);
|
25 | uint8_t get_button_repeat (uint8_t button_mask);
|
26 | uint8_t get_button_short (uint8_t button_mask);
|
27 | uint8_t get_button_long (uint8_t button_mask);
|
28 | uint8_t get_button_common (uint8_t button_mask);
|
In dieser.h habe ich repeat_next als static deklariert.
Dazu meine button_functions.c
1 | // button_functions.c
|
2 |
|
3 | #include "button_functions.h"
|
4 | #include "button_mcu_specific_definitions.h"
|
5 | #include "msp430x24x.h"
|
6 | #include <stdint.h>
|
7 |
|
8 | extern uint8_t repeat_next;
|
9 |
|
10 | #define ALL_BUTTONS ( BUTTON_1 | BUTTON_2 | BUTTON_3 )
|
11 | #define REPEAT_MASK ( BUTTON_1 | BUTTON_2 | BUTTON_3 )
|
12 | #define REPEAT_START 50
|
13 |
|
14 | // #define BUTTON_TIMEOUT
|
15 |
|
16 | static uint8_t button_state; // debounced and inverted key state
|
17 | static uint8_t button_press; // key press detect
|
18 | static uint8_t button_repeat; // key long press and repeat
|
19 |
|
20 | void check_buttons( void )
|
21 | {
|
22 | static uint8_t counter0;
|
23 | static uint8_t counter1;
|
24 | static uint8_t repeat;
|
25 |
|
26 | uint8_t temp;
|
27 |
|
28 | temp = button_state ^ ~BUTTON_IN; // key changed ?
|
29 | counter0 = ~( counter0 & temp ); // reset or count ct0
|
30 | counter1 = counter0 ^ (counter1 & temp); // reset or count ct1
|
31 | temp &= counter0 & counter1; // count until roll over ?
|
32 | button_state ^= temp; // then toggle debounced state
|
33 | button_press |= button_state & temp; // 0->1: key press detect
|
34 |
|
35 | if( (button_state & REPEAT_MASK) == 0 ) // check repeat function
|
36 | {
|
37 | repeat = REPEAT_START; // start delay
|
38 | }
|
39 |
|
40 | if( --repeat == 0 )
|
41 | {
|
42 | repeat = repeat_next; // repeat delay
|
43 | button_repeat |= button_state & REPEAT_MASK;
|
44 | }
|
45 | }
|
In dieser .c Datei wird auf die in der .h deklarierte Variable
repeat_next mittels extern zugegriffen.
Und dann kommt da noch meine Funktion, in der ich diese Repeat-Zeit
verändern möchte - diese befindet sich in einer anderen .c Datei und
bindet die button_functions.h mit ein:
1 | ...
|
2 | ...
|
3 |
|
4 | if( BUTTON_PLUS_REPEAT || BUTTON_PLUS )
|
5 | {
|
6 | repeat_counter++;
|
7 |
|
8 | if( (repeat_counter > 10) && (repeat_counter < 20) )
|
9 | {
|
10 | repeat_next = 10;
|
11 | }
|
12 | else if( repeat_counter > 20 )
|
13 | {
|
14 | repeat_counter = 20;
|
15 | repeat_next = 5;
|
16 | }
|
17 | ...
|
18 | ...
|
19 | }
|
20 |
|
21 | ...
|
22 | ...
|
23 | if( BUTTON_PLUS_PRESSED || BUTTON_MINUS_PRESSED )
|
24 | {
|
25 | repeat_button = TRUE;
|
26 | }
|
27 | else
|
28 | {
|
29 | repeat_button = FALSE;
|
30 | repeat_counter = 20;
|
31 | repeat_next = 20;
|
32 | }
|
In dieser .c Datei ist ebenfalls "extern uint8_t repeat_next"
deklariert.
So, das Problem ist nun, dass wenn das Programm hier vorbei kommt, alles
wunderbar gezählt wird. "repeat_counter" ist hier natürlich ebenfalls
static deklariert. Das geht auch alles. repeat_next wird richtig
verändert, aber jedesmal, wenn durch den 10ms-Interrupt wieder die
Tastenabfrage aufgerufen wird, ist repeat_next wieder auf 20.
Das schneller zählen geht also nicht.
Was mache ich falsch? Wie relisiert ihr so ein Erhöhen der
Geschwindigkeit?