Exemplo n.º 1
0
int8_t processKeysBase(const uint8_t* current, const uint8_t* processed, uint8_t* report)
{
    uint8_t modifiers = current[0];
    if (!(current[1] & MOD_PAD)) {
        uint8_t count = 2;
        for (int8_t i = 2; i < 8; ++i) {
            uint8_t code = current[i];
            uint8_t key = getKeyNumLock(code);
            if (!key)
                key = getKeyBase(code);
            key = toggleKanaMode(key, modifiers, !memchr(processed + 2, key, 6));
            report[count++] = key;
        }
    }
    report[0] = modifiers;
    return XMIT_NORMAL;
}
Exemplo n.º 2
0
static int8_t processKeys(const uint8_t* current, uint8_t* processed, uint8_t* report)
{
    int8_t xmit;

    if (!memcmp(current, processed, 8))
        return XMIT_NONE;
    memset(report, 0, 8);
    if (current[1] & MOD_FN) {
        uint8_t modifiers = current[0];
        uint8_t count = 2;
        xmit = XMIT_NORMAL;
        for (int8_t i = 2; i < 8 && xmit == XMIT_NORMAL; ++i) {
            uint8_t code = current[i];
            const uint8_t* a = getKeyFn(code);
            for (int8_t j = 0; j < 3 && count < 8; ++j) {
                uint8_t key = a[j];
                int8_t make = !memchr(processed + 2, code, 6);

                switch (key) {
                case 0:
                    break;
                case KEY_F1:
                    if (make) {
#ifdef WITH_HOS
                        if (current[0] & MOD_SHIFT) {
                            switchProfile(1);
                            modifiers &= ~(MOD_CONTROL | MOD_SHIFT);
                            xmit = XMIT_BRK;
                        }
                        else
#endif
                        {
                            about();
                            xmit = XMIT_MACRO;
                        }
                    }
                    break;
                case KEY_F2:
                    if (make) {
#ifdef WITH_HOS
                        if (current[0] & MOD_SHIFT) {
                            switchProfile(2);
                            modifiers &= ~(MOD_CONTROL | MOD_SHIFT);
                            xmit = XMIT_BRK;
                        }
                        else
#endif
                        {
                            switchOS();
                            xmit = XMIT_MACRO;
                        }
                    }
                    break;
                case KEY_F3:
                    if (make) {
#ifdef WITH_HOS
                        if (current[0] & MOD_SHIFT) {
                            switchProfile(3);
                            modifiers &= ~(MOD_CONTROL | MOD_SHIFT);
                            xmit = XMIT_BRK;
                        }
                        else
#endif
                        {
                            switchBase();
                            xmit = XMIT_MACRO;
                        }
                    }
                    break;
                case KEY_F4:
                    if (make) {
#ifdef WITH_HOS
                        if (current[0] & MOD_SHIFT) {
                            switchProfile(0);
                            modifiers &= ~(MOD_CONTROL | MOD_SHIFT);
                            xmit = XMIT_BRK;
                        }
                        else
#endif
                        {
                            switchKana();
                            xmit = XMIT_MACRO;
                        }
                    }
                    break;
                case KEY_F5:
                    if (make) {
                        switchDelay();
                        xmit = XMIT_MACRO;
                    }
                    break;
                case KEY_F6:
                    if (make) {
                        switchMod();
                        xmit = XMIT_MACRO;
                    }
                    break;
                case KEY_F7:
                    if (make) {
                        switchIME();
                        xmit = XMIT_MACRO;
                    }
                    break;
                case KEY_F8:
                    if (make) {
                        switchLED();
                        xmit = XMIT_MACRO;
                    }
                    break;
                case KEY_F9:
                    if (make) {
                        switchPrefixShift();
                        xmit = XMIT_MACRO;
                    }
                    break;
                case KEY_LEFTCONTROL:
                    modifiers |= MOD_LEFTCONTROL;
                    break;
                case KEY_RIGHTCONTROL:
                    modifiers |= MOD_RIGHTCONTROL;
                    break;
                case KEY_LEFTSHIFT:
                    modifiers |= MOD_LEFTSHIFT;
                    break;
                case KEY_RIGHTSHIFT:
                    modifiers |= MOD_RIGHTSHIFT;
                    break;
#ifdef WITH_HOS
                case KEY_ESCAPE:
                    if (make) {
                        if (!isUSBMode() && (current[0] & MOD_SHIFT)) {
                            HosSetEvent(HOS_TYPE_DEFAULT, HOS_EVENT_CLEAR_BONDING_DATA);
                            modifiers &= ~(MOD_CONTROL | MOD_SHIFT);
                            xmit = XMIT_BRK;
                        } else {
                            key = toggleKanaMode(key, current[0], make);
                            report[count++] = key;
                        }
                    }
                    break;
#endif
                default:
                    key = toggleKanaMode(key, current[0], make);
                    report[count++] = key;
                    break;
                }
            }
        }
#ifdef WITH_HOS
        if (count == 2) {
            modifiers &= ~MOD_SHIFT;
        }
#endif
        report[0] = modifiers;
    } else if (isKanaMode(current))
        xmit = processKeysKana(current, processed, report);
    else
        xmit = processKeysBase(current, processed, report);

#ifdef ENABLE_DUAL_ROLE_FN
    if (isDualRoleFnMod()) {
        if ((current[1] ^ processed[1]) & MOD_FN) {
            modFn = (current[1] & MOD_FN);
            if (modFn) {
                dualFn = modFn;
            } else if (dualFn && xmit == XMIT_NORMAL && !report[2]) {
                uint8_t key = (dualFn & MOD_RIGHTFN) ? KEY_LANG1 : KEY_LANG2;
                key = toggleKanaMode(key, current[0], 1);
                report[2] = key;
                memmove(processed, current, 8);
                processed[1] |= dualFn;
                dualFn = 0;
                return xmit;
            }
        }
        if (dualFn && (xmit != XMIT_NORMAL || report[2])) {
            dualFn = 0;
        }
    }
#endif

    if (xmit == XMIT_NORMAL || xmit == XMIT_IN_ORDER || xmit == XMIT_MACRO)
        memmove(processed, current, 8);

    return xmit;
}