コード例 #1
0
ファイル: KeyboardCommon.c プロジェクト: esrille/new-keyboard
void emitString(const uint8_t s[])
{
    uint8_t i = 0;
    uint8_t c;
    for (c = s[i]; c; c = s[++i])
        emitKey(c);
}
コード例 #2
0
ファイル: KeyboardCommon.c プロジェクト: esrille/new-keyboard
void emitStringN(const uint8_t s[], uint8_t len)
{
    uint8_t i = 0;
    uint8_t c;
    for (c = s[i]; i < len && c; c = s[++i])
        emitKey(c);
}
コード例 #3
0
ファイル: KeyboardCommon.c プロジェクト: esrille/new-keyboard
void emitNumber(uint16_t n)
{
    int8_t zero = 0;

    for (uint16_t i = 10000;;) {
        uint8_t d = n / i;
        if (d || zero) {
            zero = 1;
            emitKey(getNumKeycode(d));
        }
        n %= i;
        i /= 10;
        if (i == 1)
            zero = 1;
        else if (i == 0)
            break;
    }
}
コード例 #4
0
ファイル: KeyboardCommon.c プロジェクト: esrille/new-keyboard
static void about(void)
{
    emitString(about_title);

    // REV.
    emitString(about_rev);
    emitKey(getNumKeycode(BOARD_REV_VALUE));
    emitKey(KEY_ENTER);

    // VER.
    emitString(about_ver);
    emitKey(getNumKeycode((APP_VERSION_VALUE >> 8) & 0xf));
    emitKey(KEY_PERIOD);
    emitKey(getNumKeycode((APP_VERSION_VALUE >> 4) & 0xf));
    emitKey(getNumKeycode(APP_VERSION_VALUE & 0xf));
    emitKey(KEY_ENTER);

#ifdef WITH_HOS
    emitString(about_ble);
    emitString(about_rev);
    emitKey(getNumKeycode(HosGetRevision() & 0xf));
    emitKey(KEY_ENTER);

    emitString(about_ver);
    emitKey(getNumKeycode((HosGetVersion() >> 8) & 0xf));
    emitKey(KEY_PERIOD);
    emitKey(getNumKeycode((HosGetVersion() >> 4) & 0xf));
    emitKey(getNumKeycode(HosGetVersion() & 0xf));
    emitKey(KEY_ENTER);

    emitString(about_copyright);

    emitString(about_kvm);
    emitKey(getNumKeycode(CurrentProfile()));
    emitKey(KEY_ENTER);

    if (!isUSBMode()) {
        emitString(about_lesc);
        emitKey(getNumKeycode(HosGetLESC()));
        emitKey(KEY_ENTER);
    }
#else
    emitString(about_copyright);
#endif

    // F2 OS
    emitString(about_f2);
    emitOSName();

    // F3 Layout
    emitString(about_f3);
    emitBaseName();

    // F4 Kana Layout
    emitString(about_f4);
    emitKanaName();

    // F5 Delay
    emitString(about_f5);
    emitDelayName();

    // F6 Modifiers
    emitString(about_f6);
    emitModName();

    // F7 IME
    emitString(about_f7);
    emitIMEName();

    // F8 LED
    emitString(about_f8);
    emitLEDName();

    // F9 Prefix Shift
    emitString(about_f9);
    emitPrefixShift();

#ifdef ENABLE_MOUSE
    emitMouse();
#endif

#ifdef WITH_HOS
    if (!isBusPowered()) {
        uint16_t voltage = HosGetBatteryVoltage();
        uint8_t level = HosGetBatteryLevel();
        if (HOS_BATTERY_VOLTAGE_OFFSET < voltage) {
            emitKey(getNumKeycode(voltage / 100));
            emitKey(KEY_PERIOD);
            voltage %= 100;
            emitKey(getNumKeycode(voltage / 10));
            emitKey(getNumKeycode(voltage % 10));
            emitKey(KEY_V);
            emitKey(KEY_SPACEBAR);
            emitNumber(level);
            emitKey(KEYPAD_PERCENT);
            emitKey(KEY_ENTER);
        }
    }
#endif
}
コード例 #5
0
ファイル: ebpfControl.cpp プロジェクト: ederollora/p4c
void ControlBodyTranslator::processApply(const P4::ApplyMethod* method) {
    builder->emitIndent();
    auto table = control->getTable(method->object->getName().name);
    BUG_CHECK(table != nullptr, "No table for %1%", method->expr);

    P4::ParameterSubstitution binding;
    cstring actionVariableName;
    if (!saveAction.empty()) {
        actionVariableName = saveAction.at(saveAction.size() - 1);
        if (!actionVariableName.isNullOrEmpty()) {
            builder->appendFormat("enum %s %s;\n",
                                  table->actionEnumName.c_str(), actionVariableName.c_str());
            builder->emitIndent();
        }
    }
    builder->blockStart();

    BUG_CHECK(method->expr->arguments->size() == 0, "%1%: table apply with arguments", method);
    cstring keyname = "key";
    if (table->keyGenerator != nullptr) {
        builder->emitIndent();
        builder->appendLine("/* construct key */");
        builder->emitIndent();
        builder->appendFormat("struct %s %s = {}", table->keyTypeName.c_str(), keyname.c_str());
        builder->endOfStatement(true);
        table->emitKey(builder, keyname);
    }
    builder->emitIndent();
    builder->appendLine("/* value */");
    builder->emitIndent();
    cstring valueName = "value";
    builder->appendFormat("struct %s *%s = NULL", table->valueTypeName.c_str(), valueName.c_str());
    builder->endOfStatement(true);

    if (table->keyGenerator != nullptr) {
        builder->emitIndent();
        builder->appendLine("/* perform lookup */");
        builder->emitIndent();
        builder->target->emitTableLookup(builder, table->dataMapName, keyname, valueName);
        builder->endOfStatement(true);
    }

    builder->emitIndent();
    builder->appendFormat("if (%s == NULL) ", valueName.c_str());
    builder->blockStart();

    builder->emitIndent();
    builder->appendLine("/* miss; find default action */");
    builder->emitIndent();
    builder->appendFormat("%s = 0", control->hitVariable.c_str());
    builder->endOfStatement(true);

    builder->emitIndent();
    builder->target->emitTableLookup(builder, table->defaultActionMapName,
                                     control->program->zeroKey, valueName);
    builder->endOfStatement(true);
    builder->blockEnd(false);
    builder->append(" else ");
    builder->blockStart();
    builder->emitIndent();
    builder->appendFormat("%s = 1", control->hitVariable.c_str());
    builder->endOfStatement(true);
    builder->blockEnd(true);

    builder->emitIndent();
    builder->appendFormat("if (%s != NULL) ", valueName.c_str());
    builder->blockStart();
    builder->emitIndent();
    builder->appendLine("/* run action */");
    table->emitAction(builder, valueName);
    if (!actionVariableName.isNullOrEmpty()) {
        builder->emitIndent();
        builder->appendFormat("%s = %s->action",
                              actionVariableName.c_str(), valueName.c_str());
        builder->endOfStatement(true);
    }
    toDereference.clear();

    builder->blockEnd(true);
    builder->emitIndent();
    builder->appendFormat("else return %s", builder->target->abortReturnCode().c_str());
    builder->endOfStatement(true);

    builder->blockEnd(true);
}