Rev Author Line No. Line
1384 mija 1 /* mija 2009 key
2  
3 source file for process keyboard
4  
5 !!! must be set PINs,PORTs,DDR in lcd.h
6  
7  
8 ver.: 0.0 TESTED
9  
10 */
11  
12 #include <avr/io.h>
13 #include "key.h"
14  
15 void KeyInit()
16 {
17 KEY1Init();
18 KEY1Pullup();
19 KEY2Init();
20 KEY2Pullup();
21 }
22  
23 void ProcesKey(uint8_t *key)
24 {
25 //stav
26 enum{STABLE_NO_KEY,NO_STABLE,REPEAT};
27 static uint8_t stav = STABLE_NO_KEY;
28 static uint8_t KeyPrev = NOKEY;
29 static uint16_t KeyTimer;
30 uint8_t Key;
31  
32 Key = NOKEY;
33 if (KEY1Input()) Key = TL1;
34 if (KEY2Input()) Key = TL2;
35 if (KEY1Input() && KEY2Input()) Key = TL1TL2;
36  
37 switch (stav)
38 {
39 case STABLE_NO_KEY: if (Key){
40 KeyPrev = Key;
41 KeyTimer = KEYSTABLETIME;
42 stav = NO_STABLE;
43 }
44 *key = NOKEY;
45 break;
46 case NO_STABLE: if (--KeyTimer){
47 *key = NOKEY;
48 break;
49 }
50 if (Key == KeyPrev){
51 *key = Key;
52 KeyTimer = KEYFIRSTREPEATTIME;
53 stav = REPEAT;
54 break;
55 }
56 stav = STABLE_NO_KEY;
57 *key = NOKEY;
58 break;
59 /* case FIRST_REPEAT: if (--KeyTimer){
60 if (Key == NOKEY) stav = STABLE_NO_KEY;
61 *key = NOKEY;
62 break;
63 }
64 if (Key == KeyPrev){
65 *key = Key;
66 KeyTimer = KEYREPEATTIME;
67 stav = REPEAT;
68 break;
69 }
70 stav = STABLE_NO_KEY;
71 *key = NOKEY;
72 break;*/
73 case REPEAT: if (--KeyTimer){
74 if (Key != KeyPrev) stav = STABLE_NO_KEY;
75 *key = NOKEY;
76 break;
77 }
78 if (Key == KeyPrev){
79 *key = Key;
80 KeyTimer = KEYREPEATTIME;
81 //stav = REPEAT;
82 break;
83 }
84 default: stav = STABLE_NO_KEY;
85 *key = NOKEY;
86 }
87 }