📄 add_keypad.c
字号:
for(i=0; i<u8KeyCtr; i++) { if(Key2.u32Scancode == KeyDetectionArray[i].u32Scancode) { // Key2 is still pressed u8Key1Flag = u8Key1Flag + 0x2; break; } } // u8Key1Flag = 0: Key1 and Key2 was released // u8Key1Flag = 1: Key1 is still pressed, Key2 was released // u8Key1Flag = 2: Key2 is still pressed, Key1 was released // u8Key1Flag = 3: Key1 and Key2 are still pressed switch (u8Key1Flag) { case 3: // Key1 and Key2 are still pressed. if(mg_u8KeypadMode == eSingleKeyMode) { // in single mode there are no key2 known SEXIT(WRONG_MULTIPLE_STANDARD_KEY_IN_SINGLE_KEY_MODE_CASE_3); Keyp_RescueKeyRelease(); //---- switch state ------- mg_u8KeyState = eIdle; return; } if(u8KeyCtr == 2) { // only the two known keys are pressed //---- switch state ------- mg_u8KeyState = eSecondStandardKey; return; } // more then the two known keys are pressed //---- switch state ------- mg_u8KeyState = eMultipleStandardKey; return; case 1: // Key1 is still pressed but Key2 was released if(mg_u8KeypadMode == eDoubleKeyMode) { // for double key detection //---- write key into buffer ----- Keyp_WriteReleaseKey(Key2.u8Type, Key2.u32Scancode); //---- reset Key2 ---- Key2.u32Scancode = 0; Key2.u8Type = 0; } if(u8KeyCtr == 1) { // only Key1 is pressed. //---- switch state ------- mg_u8KeyState = eFirstStandardKey; return; } else if(u8KeyCtr == 2) { // Key1 and an unknown key are pressed if(mg_u8KeypadMode == eSingleKeyMode) { // for single key mode //---- switch state ------- mg_u8KeyState = eMultipleStandardKey; return; } if(Key1.u32Scancode == KeyDetectionArray[0].u32Scancode) { Keyp_WriteAndSaveKey2(KeyDetectionArray[1].u8Type, KeyDetectionArray[1].u32Scancode); } else { Keyp_WriteAndSaveKey2(KeyDetectionArray[0].u8Type, KeyDetectionArray[0].u32Scancode); } //---- switch state ------- mg_u8KeyState = eSecondStandardKey; return; } // u8KeyCtr > 2 // Key1 is pressed and more then one unknown key is pressed if(mg_u8KeypadMode == eSingleKeyMode) { // for single key mode //---- switch state ------- mg_u8KeyState = eMultipleStandardKey; return; } for(i=0; i<u8KeyCtr; i++) { if(Key1.u32Scancode == KeyDetectionArray[i].u32Scancode) { if(i == (u8KeyCtr-1)) { // last buffer value was reached i = 0; Keyp_WriteAndSaveKey2(KeyDetectionArray[0].u8Type, KeyDetectionArray[0].u32Scancode); } else { Keyp_WriteAndSaveKey2(KeyDetectionArray[i+1].u8Type, KeyDetectionArray[i+1].u32Scancode); } break; } } //---- switch state ------- mg_u8KeyState = eMultipleStandardKey; return; case 2: // Key2 is still pressed but Key1 was released if(mg_u8KeypadMode == eSingleKeyMode) { // in single mode there are no key2 known SEXIT(WRONG_MULTIPLE_STANDARD_KEY_IN_SINGLE_KEY_MODE_CASE_2); Keyp_RescueKeyRelease(); //---- switch state ------- mg_u8KeyState = eIdle; return; } Keyp_WriteReleaseKey(Key1.u8Type, Key1.u32Scancode); //---- copy Key2 into Key1 ---- Key1.u32Scancode = Key2.u32Scancode; Key1.u8Type = Key2.u8Type; //---- reset Key2 ---- Key2.u32Scancode = 0; Key2.u8Type = 0; if(u8KeyCtr == 1) { // only Key1 is pressed. //---- switch state ------- mg_u8KeyState = eFirstStandardKey; return; } else if(u8KeyCtr == 2) { // Key1 and an unknown key are pressed if(Key1.u32Scancode == KeyDetectionArray[0].u32Scancode) { Keyp_WriteAndSaveKey2(KeyDetectionArray[1].u8Type, KeyDetectionArray[1].u32Scancode); } else { Keyp_WriteAndSaveKey2(KeyDetectionArray[0].u8Type, KeyDetectionArray[0].u32Scancode); } //---- switch state ------- mg_u8KeyState = eSecondStandardKey; return; } // u8KeyCtr > 2 // Key1 is pressed and more then one unknown key is pressed for(i=0; i<u8KeyCtr; i++) { if(Key1.u32Scancode == KeyDetectionArray[i].u32Scancode) { if(i == (u8KeyCtr-1)) { // last buffer value was reached i = 0; Keyp_WriteAndSaveKey2(KeyDetectionArray[0].u8Type, KeyDetectionArray[0].u32Scancode); } else { Keyp_WriteAndSaveKey2(KeyDetectionArray[i+1].u8Type, KeyDetectionArray[i+1].u32Scancode); } break; } } //---- switch state ------- mg_u8KeyState = eMultipleStandardKey; return; default: // case0 Key 1 and Key2 are released. if(mg_u8KeypadMode == eDoubleKeyMode) { // for double key detection Keyp_WriteReleaseKey(Key2.u8Type, Key2.u32Scancode); } Keyp_WriteReleaseKey(Key1.u8Type, Key1.u32Scancode); //---- reset Key1 and Key2 ---- Key1.u32Scancode = Key2.u32Scancode = 0; Key1.u8Type = Key2.u8Type = 0; if(u8KeyCtr == 0) { // no key pressed //---- switch state ------- mg_u8KeyState = eIdle; return; } else if(u8KeyCtr == 1) { // save new Key in Key1. Keyp_WriteAndSaveKey1(KeyDetectionArray[0].u8Type, KeyDetectionArray[0].u32Scancode); //---- switch state ------- mg_u8KeyState = eFirstStandardKey; return; } else if(u8KeyCtr >= 2) { // save the new keys Keyp_WriteAndSaveKey1(KeyDetectionArray[0].u8Type, KeyDetectionArray[0].u32Scancode); if(mg_u8KeypadMode == eSingleKeyMode) { // in single mode there are no key2 known //---- switch state ------- mg_u8KeyState = eMultipleStandardKey; return; } Keyp_WriteAndSaveKey2(KeyDetectionArray[1].u8Type, KeyDetectionArray[1].u32Scancode); if(u8KeyCtr == 2) { //---- switch state ------- mg_u8KeyState = eSecondStandardKey; return; } // more then two keys are pressed //---- switch state ------- mg_u8KeyState = eMultipleStandardKey; return; } } break; case eMultipleSpecialKey: // test if the known key1, is still pressed for(i=0; i<u8KeyCtr; i++) { if(Key1.u32Scancode == KeyDetectionArray[i].u32Scancode) { // Key1 is still pressed u8Key1Flag = 0x1; break; } } // test if the known key2 is still pressed for(i=0; i<u8KeyCtr; i++) { if(Key2.u32Scancode == KeyDetectionArray[i].u32Scancode) { // Key2 is still pressed u8Key1Flag = u8Key1Flag + 0x2; break; } } // u8Key1Flag = 0: Key1 and Key2 was released // u8Key1Flag = 1: Key1 is still pressed, Key2 was released // u8Key1Flag = 2: Key2 is still pressed, Key1 was released // u8Key1Flag = 3: Key1 and Key2 are still pressed switch (u8Key1Flag) { case 3: // Key1 and Key2 are still pressed. if(mg_u8KeypadMode == eSingleKeyMode) { // in single mode there are no key2 known SEXIT(WRONG_MULTIPLE_SPECIAL_KEY_IN_SINGLE_KEY_MODE_CASE_3); Keyp_RescueKeyRelease(); //---- switch state ------- mg_u8KeyState = eIdle; return; } if(u8KeyCtr == 2) { // only the two known keys are pressed //---- switch state ------- mg_u8KeyState = eSecondSpecialKey; return; } // more then the two known keys are pressed //---- switch state ------- mg_u8KeyState = eMultipleSpecialKey; return; case 1: // Key1 is still pressed but Key2 was released if(mg_u8KeypadMode == eDoubleKeyMode) { // for double key detection //---- write key into buffer ----- Keyp_WriteReleaseKey(Key2.u8Type, Key2.u32Scancode); //---- reset Key2 ---- Key2.u32Scancode = 0; Key2.u8Type = 0; } if(u8KeyCtr == 1) { // only Key1 is pressed. //---- switch state ------- mg_u8KeyState = eFirstSpecialKey; return; } else if(u8KeyCtr == 2) { // Key1 and an unknown key are pressed if(mg_u8KeypadMode == eSingleKeyMode) { // for single key mode //---- switch state ------- mg_u8KeyState = eMultipleSpecialKey; return; } if(Key1.u32Scancode == KeyDetectionArray[0].u32Scancode) { Keyp_WriteAndSaveKey2(KeyDetectionArray[1].u8Type, KeyDetectionArray[1].u32Scancode); } else { Keyp_WriteAndSaveKey2(KeyDetectionArray[0].u8Type, KeyDetectionArray[0].u32Scancode); } //---- switch state ------- mg_u8KeyState = eSecondSpecialKey; return; } // u8KeyCtr > 2 // Key1 is pressed and more then one unknown key is pressed if(mg_u8KeypadMode == eSingleKeyMode) { // for single key mode //---- switch state ------- mg_u8KeyState = eMultipleSpecialKey; return; } for(i=0; i<u8KeyCtr; i++) { if(Key1.u32Scancode == KeyDetectionArray[i].u32Scancode) { if(i == (u8KeyCtr-1)) { // last buffer value was reached i = 0; Keyp_WriteAndSaveKey2(KeyDetectionArray[0].u8Type, KeyDetectionArray[0].u32Scancode);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -