RK3288 红外遥控器增加自定义按键

 转载请注明出处:https://www.cnblogs.com/lialong1st/p/10071557.html 

CPU:RK3288

系统:Android 5.1

 

1、在 dts 中增加红外遥控器键值(点播按键),注意文件中加载的 input.h 头文件路径。

#include <dt-bindings/input/input.h>

diff --git a/kernel/arch/arm/boot/dts/rk3288-tb_8846.dts b/kernel/arch/arm/boot/dts/rk3288-tb_8846.dts
index ba9b8f7..0f1a5a4 100755
--- a/kernel/arch/arm/boot/dts/rk3288-tb_8846.dts
+++ b/kernel/arch/arm/boot/dts/rk3288-tb_8846.dts
@@ -728,7 +728,7 @@ clock-frequency = <50000000>;
                        <0xeb KEY_DOT>,          // .
                        <0xe3 KEY_DELETE>,       // Del 
+                       <0xec KEY_VOD>,          // Vod
                        <0xa6 KEY_PAUSE>,        // Pause
                        <0xaa KEY_PLAY>;         // Play

 

2、在内核头文件 input.h 中增加按键定义,不能重复,input.h 路径要与第一步 dts 文件中头文件加载的一致。

diff --git a/kernel/include/dt-bindings/input/input.h b/kernel/include/dt-bindings/input/input.h
index 2b1990d..b49dc4d 100755
--- a/kernel/include/dt-bindings/input/input.h
+++ b/kernel/include/dt-bindings/input/input.h
@@ -619,6 +619,8 @@
 #define BTN_TRIGGER_HAPPY39            0x2e6
 #define BTN_TRIGGER_HAPPY40            0x2e7
 
+#define KEY_VOD                        0x2f0
+
 /* We avoid low common keys in module aliases so they don't get huge. */
 #define KEY_MIN_INTERESTING    KEY_MUTE
 #define KEY_MAX                        0x2ff

 

3、增加键值与上层对应的关系。

diff --git a/device/rockchip/common/ff680000_pwm.kl b/device/rockchip/common/ff680000_pwm.kl
index fb4cae7..eed2df8 100755
--- a/device/rockchip/common/ff680000_pwm.kl
+++ b/device/rockchip/common/ff680000_pwm.kl
@@ -35,6 +35,8 @@ key 111   DEL
 key 119   MEDIA_PAUSE
 key 207   MEDIA_PLAY
 
+key 752   VOD
+
 #key 400   TV_MEDIA_MULT_BACKWARD
 #key 401   TV_MEDIA_MULT_FORWARD
 #key 402   TV_MEDIA_PLAY_PAUSE

 

4、在 KeyEvent.java 中定义按键上层的键值,定义按键值后面有提示,新按键需要更新哪些地方。

    public static final int KEYCODE_VOD = 275;
    private static final int LAST_KEYCODE = KEYCODE_VOD;

//  NOTE: If you add a new keycode here you must also add it to:
//  isSystem()
//  isWakeKey()
//  frameworks/native/include/android/keycodes.h
//  frameworks/native/include/input/InputEventLabels.h
//  frameworks/base/core/res/res/values/attrs.xml
//  emulator?
//  LAST_KEYCODE

在当前文件中定义键值,修改最后面的键值、isSystem 和 isWakeKey 两个方法。

diff --git a/frameworks/base/core/java/android/view/KeyEvent.java b/frameworks/base/core/java/android/view/KeyEvent.java
index bcf9a46..45f6ffb 100755
--- a/frameworks/base/core/java/android/view/KeyEvent.java
+++ b/frameworks/base/core/java/android/view/KeyEvent.java
@@ -773,7 +773,9 @@ public class KeyEvent extends InputEvent implements Parcelable {
     public static final int KEYCODE_TV_MEDIA_PAUSE = 274;
 //$_rbox_$_modify_$ end
 
-    private static final int LAST_KEYCODE = KEYCODE_TV_MEDIA_PAUSE;
+       public static final int KEYCODE_VOD = 275;
+
+    private static final int LAST_KEYCODE = KEYCODE_VOD;
 
     // NOTE: If you add a new keycode here you must also add it to:
     //  isSystem()
@@ -1818,6 +1820,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
             case KeyEvent.KEYCODE_BRIGHTNESS_DOWN:
             case KeyEvent.KEYCODE_BRIGHTNESS_UP:
             case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
+            case KeyEvent.KEYCODE_VOD:
                 return true;
         }
 
@@ -1833,6 +1836,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
             case KeyEvent.KEYCODE_WAKEUP:
             case KeyEvent.KEYCODE_PAIRING:
             case KeyEvent.KEYCODE_NOTIFICATION:
+            case KeyEvent.KEYCODE_VOD:
                 return true;
         }

 

5、在 keycodes.h 文件中定义键值

diff --git a/frameworks/native/include/android/keycodes.h b/frameworks/native/include/android/keycodes.h
index ff998df..212fef6 100755
--- a/frameworks/native/include/android/keycodes.h
+++ b/frameworks/native/include/android/keycodes.h
@@ -307,6 +307,7 @@ enum {
     AKEYCODE_TV_KEYMOUSE_UP = 262,
     AKEYCODE_TV_KEYMOUSE_DOWN = 263,
     AKEYCODE_TV_KEYMOUSE_MODE_SWITCH = 264,
+    AKEYCODE_VOD = 275,
     AKEYCODE_HELP            = 259
 
     // NOTE: If you add a new keycode here you must also add it to several other files.

 

6、在 InputEventLabels.h 中添加按键标签

diff --git a/frameworks/native/include/input/InputEventLabels.h b/frameworks/native/include/input/InputEventLabels.h
index d7a06dd..4359e3f 100755
--- a/frameworks/native/include/input/InputEventLabels.h
+++ b/frameworks/native/include/input/InputEventLabels.h
@@ -304,6 +304,7 @@ static const InputEventLabel KEYCODES[] = {
     DEFINE_KEYCODE(TV_KEYMOUSE_DOWN),
     DEFINE_KEYCODE(TV_KEYMOUSE_MODE_SWITCH),
     DEFINE_KEYCODE(HELP),
+    DEFINE_KEYCODE(VOD),
 
     { NULL, 0 }
 };

 

7、在 attrs.xml 中增加按键

diff --git a/frameworks/base/core/res/res/values/attrs.xml b/frameworks/base/core/res/res/values/attrs.xml
index 75157be..e591fce 100755
--- a/frameworks/base/core/res/res/values/attrs.xml
+++ b/frameworks/base/core/res/res/values/attrs.xml
@@ -1791,6 +1791,7 @@
         <enum name="KEYCODE_TV_MEDIA_MULT_BACKWARD" value="272" />
         <enum name="KEYCODE_TV_MEDIA_PLAY" value="273" />
         <enum name="KEYCODE_TV_MEDIA_PAUSE" value="274" />
+        <enum name="KEYCODE_VOD" value="275" />
 <!--$_rbox_$_modify_$_end-->
     </attr>
 

 

8、此时按键已经添加完毕,但是编译会报错如下,需要更新 api 文件,先执行指令 make update-api,再编译。

******************************
You have tried to change the API from what has been previously approved.

To make these errors go away, you have two choices:
   1) You can add "@hide" javadoc comments to the methods, etc. listed in the
      errors above.

   2) You can update current.txt by executing the following command:
         make update-api

      To submit the revised current.txt to the main Android repository,
      you will need approval.
******************************

 

9、编译成功后,上层就可以接收到此键值,也可以通过 getevent 查看,但是看到的只是键值(02f0),没有解析到实际含义。

$ adb shell
root@rk3288:/ # getevent -rtl /dev/input/event0
getevent -rtl /dev/input/event0
[      43.142191] EV_KEY       02f0                 DOWN
[      43.142191] EV_SYN       SYN_REPORT           00000000
[      43.220034] EV_KEY       02f0                 UP
[      43.220034] EV_SYN       SYN_REPORT           00000000             rate 12

 

10、在 getevent.h 中添加此按键标签

diff --git a/system/core/toolbox/getevent.h b/system/core/toolbox/getevent.h
index 0482d04..785d4f4 100755
--- a/system/core/toolbox/getevent.h
+++ b/system/core/toolbox/getevent.h
@@ -537,6 +537,7 @@ static struct label key_labels[] = {
         LABEL(BTN_TRIGGER_HAPPY38),
         LABEL(BTN_TRIGGER_HAPPY39),
         LABEL(BTN_TRIGGER_HAPPY40),
+        LABEL(KEY_VOD),
         LABEL_END,
 };

 

11、上一步添加标签后编译会报错,提示找不到 KEY_VOD,则需要在头文件中定义。

diff --git a/bionic/libc/kernel/uapi/linux/input.h b/bionic/libc/kernel/uapi/linux/input.h
index b9d5b2a..d7c99c3 100755
--- a/bionic/libc/kernel/uapi/linux/input.h
+++ b/bionic/libc/kernel/uapi/linux/input.h
@@ -787,6 +787,7 @@ struct input_keymap_entry {
 #define BTN_TRIGGER_HAPPY39 0x2e6
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY40 0x2e7
+#define KEY_VOD             0x2f0
 #define KEY_MIN_INTERESTING KEY_MUTE
 #define KEY_MAX 0x2ff
 #define KEY_CNT (KEY_MAX+1)

 

此时,自定义按键添加大功告成,上层app可以接收到按键值,getevent 中也能解析此按键。

$ adb shell
root@rk3288:/ # getevent -rtl /dev/input/event0
getevent -rtl /dev/input/event0
[     138.898690] EV_KEY       KEY_VOD              DOWN
[     138.898690] EV_SYN       SYN_REPORT           00000000
[     138.980104] EV_KEY       KEY_VOD              UP
[     138.980104] EV_SYN       SYN_REPORT           00000000             rate 12

 

RK3288 红外遥控器增加系统中已有的键值

posted @ 2018-12-05 16:14  LeeAaron  阅读(3099)  评论(0编辑  收藏  举报