⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 add_keypad.c

📁 Nulceus下的键盘驱动程序
💻 C
📖 第 1 页 / 共 5 页
字号:
                            mg_u8KeyState = eSecondStandardKey;                        }                        return;                        default:                        // more then two keys are pressed                        Keyp_WriteAndSaveKey1(KeyDetectionArray[0].u8Type, KeyDetectionArray[0].u32Scancode);                        if(mg_u8KeypadMode == eDoubleKeyMode)                        {   // for double key detection                            Keyp_WriteAndSaveKey2(KeyDetectionArray[1].u8Type, KeyDetectionArray[1].u32Scancode);                        }                    //---- switch state -------                        if(u8KeyType == eSpecialKey)                        {   // special key detected => switch to special key state                            mg_u8KeyState = eMultipleSpecialKey;                        }                        else                        {   // standard key detected => switch to standard key state                            mg_u8KeyState = eMultipleStandardKey;                        }                        return;                }            }            // wrong key type         //---- switch state -------            mg_u8KeyState = eIdle;            return ;                    case eFirstStandardKey:            if(u8KeyCtr == 0)            {   // no key pressed                Keyp_WriteReleaseKey(Key1.u8Type, Key1.u32Scancode);                Key1.u32Scancode = 0;                Key1.u8Type = 0;            //---- switch state -------                mg_u8KeyState = eIdle;                return;            }            if(u8KeyCtr == 1)            {                if(Key1.u32Scancode == KeyDetectionArray[0].u32Scancode)                {   // the known key is still pressed                //---- switch state -------                    mg_u8KeyState = eFirstStandardKey;                    return;                }            }            // test if the known key1, is still pressed            for(i=0; i<u8KeyCtr; i++)            {                if(Key1.u32Scancode == KeyDetectionArray[i].u32Scancode)                {   // the known key is still pressed => save the next one                    if(mg_u8KeypadMode == eSingleKeyMode)                    {   // for single key mode                        if(u8KeyCtr > 1)                        {                        //---- switch state -------                            mg_u8KeyState = eMultipleStandardKey;                        }                        // dont leave this state                        return;                    }                    //double key mode                    if(i == 0)                    {                        Keyp_WriteAndSaveKey2(KeyDetectionArray[1].u8Type, KeyDetectionArray[1].u32Scancode);                    }                    else if(i == (u8KeyCtr - 1))                    {                        Keyp_WriteAndSaveKey2(KeyDetectionArray[0].u8Type, KeyDetectionArray[0].u32Scancode);                    }                    else                    {                        Keyp_WriteAndSaveKey2(KeyDetectionArray[i+1].u8Type, KeyDetectionArray[i+1].u32Scancode);                    }                    if(u8KeyCtr == 2)                    {                    //---- switch state -------                        mg_u8KeyState = eSecondStandardKey;                        return;                    }                    else if(u8KeyCtr > 2)                    {                    //---- switch state -------                        mg_u8KeyState = eMultipleStandardKey;                        return;                    }                }            }// end for loop            // the known key was released            //---- save release mark into buffer            Keyp_WriteReleaseKey(Key1.u8Type, Key1.u32Scancode);                                    if(u8KeyCtr == 1)            {                Keyp_WriteAndSaveKey1(KeyDetectionArray[0].u8Type, KeyDetectionArray[0].u32Scancode);            //---- switch state -------                mg_u8KeyState = eFirstStandardKey;                return;            }            else if(u8KeyCtr == 2)            {                Keyp_WriteAndSaveKey1(KeyDetectionArray[0].u8Type, KeyDetectionArray[0].u32Scancode);                if(mg_u8KeypadMode == eSingleKeyMode)                {   // for single key mode                //---- switch state -------                    mg_u8KeyState = eMultipleStandardKey;                    return;                }            //---- save second key                Keyp_WriteAndSaveKey2(KeyDetectionArray[1].u8Type, KeyDetectionArray[1].u32Scancode);            //---- switch state -------                mg_u8KeyState = eSecondStandardKey;                 return;            }            // else if(u8KeyCtr > 2)            Keyp_WriteAndSaveKey1(KeyDetectionArray[0].u8Type, KeyDetectionArray[0].u32Scancode);            if(mg_u8KeypadMode == eSingleKeyMode)            {   // for single key mode            //---- switch state -------                mg_u8KeyState = eMultipleStandardKey;                return;            }        //---- save second key            Keyp_WriteAndSaveKey2(KeyDetectionArray[1].u8Type, KeyDetectionArray[1].u32Scancode);        //---- switch state -------            mg_u8KeyState = eMultipleStandardKey;            return;        case eSecondStandardKey:            if(mg_u8KeypadMode == eSingleKeyMode)            {   // in single mode there are no key2 known                SEXIT(WRONG_SECOND_STANDARD_KEY_IN_SINGLE_KEY_MODE);                Keyp_RescueKeyRelease();            //---- switch state -------                mg_u8KeyState = eIdle;                return;            }            // 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 1:                    // Key1 is still pressed but Key2 was released                    //---- 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(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))                            {                                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                    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))                            {                                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 3:                    // Key1 and Key2 are still pressed.                    if(u8KeyCtr == 2)                    {   // only the two know keys are pressed                    //---- switch state -------                        mg_u8KeyState = eSecondStandardKey;                        return;                    }                    //more then the two known keys are pressed                //---- switch state -------                    mg_u8KeyState = eMultipleStandardKey;                    return;                                        default:                    // case0 Key 1 and Key2 are released.                    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);                        Keyp_WriteAndSaveKey2(KeyDetectionArray[1].u8Type, KeyDetectionArray[1].u32Scancode);                        if(u8KeyCtr  == 2)                        {                        //---- switch state -------                            mg_u8KeyState = eSecondStandardKey;                            return;                        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -