Rockchip 红外遥控 调试记录

红外遥控

获取红外遥控键值信息

echo 1 > sys/module/rockchip_pwm_remotectl/parameters/code_print

系统不响应红外遥控Ok键

  1. 通过getevent 获取 Ok键的linux key event code。经确认,没有问题。暂时排除内核层问题。
  2. 检查 key layout file, 确认编写了Ok键的映射关系。
  3. 查看EventHublog,logcat -s "EventHub",发现,系统为红外输入设备匹配的KeyLayoutFile 是Generic.kl,该文件内部没有linux ok key code 到Android Ok键的映射。

问题已经明了!but,我已经将红外遥控的kl文件正确的放置到了/system/usr/keylayout/目录中。走读代码。

首先,kl和 kcm文件是在frameworks/native/libs/input/Keyboard.cpp中加载的。

加载流程如下:

status_t KeyMap::load(const InputDeviceIdentifier& deviceIdenfifier,
        const PropertyMap* deviceConfiguration) {
    // 根据IDC文件中的规则查找 kl 和 kcm文件
    if (deviceConfiguration) {
        String8 keyLayoutName;
        if (deviceConfiguration->tryGetProperty(String8("keyboard.layout"),
                keyLayoutName)) {
            status_t status = loadKeyLayout(deviceIdenfifier, keyLayoutName);
            if (status == NAME_NOT_FOUND) {
                ALOGE("Configuration for keyboard device '%s' requested keyboard layout '%s' but "
                        "it was not found.",
                        deviceIdenfifier.name.string(), keyLayoutName.string());
            }
        }

        String8 keyCharacterMapName;
        if (deviceConfiguration->tryGetProperty(String8("keyboard.characterMap"),
                keyCharacterMapName)) {
            status_t status = loadKeyCharacterMap(deviceIdenfifier, keyCharacterMapName);
            if (status == NAME_NOT_FOUND) {
                ALOGE("Configuration for keyboard device '%s' requested keyboard character "
                        "map '%s' but it was not found.",
                        deviceIdenfifier.name.string(), keyLayoutName.string());
            }
        }

        if (isComplete()) {
            return OK;
        }
    }

   
    if (probeKeyMap(deviceIdenfifier, String8::empty())) {
        return OK;
    }

    // Fall back on the Generic key map.
    // TODO Apply some additional heuristics here to figure out what kind of
    //      generic key map to use (US English, etc.) for typical external keyboards.
    if (probeKeyMap(deviceIdenfifier, String8("Generic"))) {
        return OK;
    }

    // Try the Virtual key map as a last resort.
    if (probeKeyMap(deviceIdenfifier, String8("Virtual"))) {
        return OK;
    }

    // Give up!
    ALOGE("Could not determine key map for device '%s' and no default key maps were found!",
            deviceIdenfifier.name.string());
    return NAME_NOT_FOUND;
}

接着看probeKeyMap的实现:

bool KeyMap::probeKeyMap(const InputDeviceIdentifier& deviceIdentifier,
        const String8& keyMapName) {
    if (!haveKeyLayout()) {
        // 加载成功的话  haveKeyLayout() 将会返回true
        loadKeyLayout(deviceIdentifier, keyMapName);
    }
    if (!haveKeyCharacterMap()) {
        // 记载成功 haveKeyCharacterMap 将会返回true
        loadKeyCharacterMap(deviceIdentifier, keyMapName);
    }
    return isComplete();
}

inline bool isComplete() const {
	return haveKeyLayout() && haveKeyCharacterMap();
}

可以简单的理解就是klkcm文件都找到时,probeKeyMap才会返回Ok

如果二者有一个没有加载成功,就会使用系统默认的Generic.*文件。

到这里,我们文件应该放置路径没有错啊,为啥还是加载不到??

后面发现是因为配置文件时从 anroid M中移植过来的,有一些键值是AndroidM调试时前人添加的,而这些键值AndroidO中没有定义,导致解析 kl文件时失败,系统就默认加载了Generic.kl

如果KL文件或者KCM文件解析过程出现错误,也会导致系统去匹配默认的配置文件,所以一定要保证 配置文件的格式及内容(比如kl文件中声明的Android key label 都能在android/keycodes.h找到对应的定义)正确。

原文地址:https://www.cnblogs.com/liutimo/p/14072782.html