Exemplo n.º 1
0
ControlledLeds newControlledLed(Led led) {
    struct LedGroup group = (struct LedGroup){ &led, 1 };
    return newControlledLedGroup(&group);
}

ControlledLeds newControlledLedGroup(LedGroup group) {
    if (group == NULL) return Invalid(ControlledLeds);
    _ControlledLeds leds = kalloc(sizeof(struct _ControlledLeds));
    if (!leds) return Invalid(ControlledLeds);
    LedList *underlying = addNewLedsToList(group);
    if (!underlying) {
        free(leds);
        return Invalid(ControlledLeds);
    }
    leds->mask = 0;
    leds->leds = underlying;
    leds->count = group->count;
    leds->next = NULL;
    ControlledLeds result = As(ControlledLeds, leds);
    controlLeds(result, LedsDisabled);
    LL_APPEND(controlled_leds, leds);
    return result;
}

static void cleanUnderlyingLeds(ControlledLeds leds) {
    LedList elem = NULL, tmp = NULL;
    LL_FOREACH_SAFE(underlying_leds, elem, tmp) {
        for (int i = 0; i < LEDS->count; i++) {
            if (elem == LEDS->leds[i]) {
                reduceRefcount(elem);
            }
        }
    }
}
Exemplo n.º 2
0
void Tohkbd::handleCtrlChanged()
{
    controlLeds(true);
    checkDoWeNeedBacklight();

    uinputif->sendUinputKeyPress(KEY_LEFTCTRL, keymap->ctrl->pressed ? 1 : 0);
    QThread::msleep(KEYREPEAT_RATE);
    uinputif->synUinputDevice();
}
Exemplo n.º 3
0
/* Handle state change of phone display
 * Turn keyboard backlight on and off
 */
void Tohkbd::handleDisplayStatus(const QDBusMessage& msg)
{
    QList<QVariant> args = msg.arguments();
    const char *turn = qPrintable(args.at(0).toString());

    printf("Display status changed to \"%s\"\n", turn);
    if (strcmp(turn, "on") == 0)
    {
        controlLeds(true);
        checkDoWeNeedBacklight();
        displayIsOn = true;
        slideEventEmitted = false;
    }
    else if (strcmp(turn, "off") == 0)
    {
        displayIsOn = false;

        backlightTimer->stop();
        controlLeds(false);
    }
}
Exemplo n.º 4
0
/* Shift, Ctrl, Alt and Sym key press and release handlers
 */
void Tohkbd::handleShiftChanged()
{
    /* Release capslock if shift is pressed, to aVOID tHIS */
    if (capsLock && keymap->shift->pressed)
        toggleCapsLock();

    controlLeds(true);
    checkDoWeNeedBacklight();

    uinputif->sendUinputKeyPress(KEY_LEFTSHIFT, keymap->shift->pressed ? 1 : 0);
    QThread::msleep(KEYREPEAT_RATE);
    uinputif->synUinputDevice();
}
Exemplo n.º 5
0
void Tohkbd::handleAltChanged()
{
    controlLeds(true);
    checkDoWeNeedBacklight();

    uinputif->sendUinputKeyPress(KEY_LEFTALT, keymap->alt->pressed ? 1 : 0);
    QThread::msleep(KEYREPEAT_RATE);
    uinputif->synUinputDevice();

    if (!keymap->alt->pressed && taskSwitcherVisible)
    {
        /* hide taskswitcher when alt is released
         * this will also activate selected application */
        tohkbd2user->hideTaskSwitcher();
        taskSwitcherVisible = false;
    }
}
Exemplo n.º 6
0
void Tohkbd::handleSymChanged()
{
    controlLeds(true);
    checkDoWeNeedBacklight();
}
Exemplo n.º 7
0
bool Tohkbd::checkKeypadPresence()
{
    bool __prev_keypadPresence = keypadIsPresent;

    if (!vddEnabled)
    {
        /* keyboard is being connected to base */
        /* TODO: how to detect keyboard is removed ??? */
        printf("Presence detected, turning power on\n");
        QThread::msleep(150);
        setVddState(true);
        QThread::msleep(150);
        tca8424->reset();
        QThread::msleep(150);
    }

    tca8424driver::PresenceResult res = tca8424->testComms();

    if (res == tca8424driver::DetectFail)
    {
        printf("keypad not present, turning power off\n");
        setVddState(false);

        if (keypadIsPresent)
        {
            keyboardConnectedNotification(false);
            presenceTimer->stop();
            handleKeyReleased();
        }

        keypadIsPresent = false;
    }
    else
    {
        if (!keypadIsPresent)
        {
            keyboardConnectedNotification(true);
            controlLeds(true);
            checkDoWeNeedBacklight();
            checkEEPROM();
        }
        else if (res == tca8424driver::NoKeyPressedSinceReset && displayIsOn)
        {
            /* Keyboard power interrupt shortly? refresh leds just in case */
            controlLeds(true);
        }

        presenceTimer->start();
        keypadIsPresent = true;
    }

    if (__prev_keypadPresence != keypadIsPresent)
    {
        emit keyboardConnectedChanged(keypadIsPresent);
        emitKeypadSlideEvent(keypadIsPresent);

        vkbLayoutIsTohkbd = keypadIsPresent;
        changeActiveLayout();
        if (forceLandscapeOrientation)
            changeOrientationLock();
    }

    return keypadIsPresent;
}