Go to the source code of this file.
Data Structures | |
struct | KEY_CONTROL |
Defines | |
#define | KEY_DEBOUNCE_NUMBER 10 |
#define | KEY_ACCEPT_NUMBER 5 |
#define | KEY_UP 0x37 |
#define | KEY_DOWN 0x1f |
#define | KEY_LEFT 0x3e |
#define | KEY_RIGHT 0x3b |
#define | KEY_ENTER 0x3d |
Functions | |
void | KeyInit (void) |
void | KeySvc (void) |
INT8U | KeyGet (void) |
BOOL | KeyStatusCheck (void) |
void | KeyRun (void) |
void | KeyReset (void) |
Variables | |
KEY_CONTROL | KeyCtrl |
INT8U KeyGet | ( | void | ) |
void KeyInit | ( | void | ) |
void KeyReset | ( | void | ) |
void KeyRun | ( | void | ) |
BOOL KeyStatusCheck | ( | void | ) |
void KeySvc | ( | void | ) |
Definition at line 37 of file key.c.
00037 { 00038 if(KeyCtrl.State==KeyIdleState) return; // key is not in use 00039 if(KeyCtrl.Timer!=0) return; 00040 KeyCtrl.Timer=1; 00041 switch(KeyCtrl.State){ 00042 case KeyReleaseState: 00043 if((Keys&0x3f)!=0x3f){ 00044 //DebugStringPrint("0."); 00045 KeyCtrl.KeyValue=Keys&0x3f; 00046 KeyCtrl.ReadKeyCounter=0; 00047 KeyCtrl.HitKeyCounter=0; 00048 KeyCtrl.State=KeyPressTransitionState; 00049 } 00050 break; 00051 case KeyPressTransitionState: 00052 if((Keys&0x3f)!=0x3f){ 00053 if((Keys&0x3f)==KeyCtrl.KeyValue){ 00054 //DebugStringPrint("1."); 00055 KeyCtrl.HitKeyCounter++; 00056 } 00057 else{ 00058 KeyCtrl.KeyValue=Keys&0x3f; 00059 KeyCtrl.HitKeyCounter=0; // reset HitKeyCounter 00060 } 00061 } 00062 KeyCtrl.ReadKeyCounter++; 00063 if(KeyCtrl.ReadKeyCounter>=KEY_DEBOUNCE_NUMBER){ 00064 if(KeyCtrl.HitKeyCounter>=KEY_ACCEPT_NUMBER){ 00065 //DebugStringPrint("2."); 00066 if(KeyCtrl.HasKey==FALSE){ 00067 //DebugStringPrint("3."); 00068 KeyCtrl.HasKey=TRUE; 00069 KeyCtrl.HasKeyValue=KeyCtrl.KeyValue; 00070 KeyCtrl.State=KeyPressState; 00071 } 00072 else{ 00073 KeyCtrl.State=KeyPressState; 00074 } 00075 } 00076 else{ 00077 KeyCtrl.State=KeyReleaseState; 00078 } 00079 } 00080 break; 00081 case KeyPressState: 00082 if((Keys&0x3f)!=KeyCtrl.HasKeyValue){ 00083 KeyCtrl.ReadKeyCounter=0; 00084 KeyCtrl.HitKeyCounter=0; 00085 KeyCtrl.State=KeyReleaseTransitionState; 00086 } 00087 else{ 00088 // time delay for key repeat 00089 } 00090 break; 00091 case KeyReleaseTransitionState: 00092 KeyCtrl.ReadKeyCounter++; 00093 if((Keys&0x3f)!=0x3f){ 00094 if(KeyCtrl.ReadKeyCounter>=KEY_DEBOUNCE_NUMBER){ 00095 KeyCtrl.ReadKeyCounter=0; 00096 KeyCtrl.HitKeyCounter=0; 00097 } 00098 } 00099 else{ 00100 KeyCtrl.HitKeyCounter++; 00101 if(KeyCtrl.ReadKeyCounter>=KEY_DEBOUNCE_NUMBER){ 00102 if(KeyCtrl.HitKeyCounter>=KEY_ACCEPT_NUMBER){ 00103 KeyCtrl.State=KeyReleaseState; 00104 } 00105 else{ 00106 KeyCtrl.ReadKeyCounter=0; 00107 KeyCtrl.HitKeyCounter=0; 00108 } 00109 } 00110 } 00111 break; 00112 } 00113 }