zoukankan      html  css  js  c++  java
  • Amlogic电视盒子红外遥控适配笔记

    前一阵做了个安卓6的固件, 在R3300L和Q7上跑的, 其他问题没有, 但是有用户反映原来的遥控器用不了了, 于是检查了一下遥控器配置, 顺便学习一下此类设备的红外遥控机制. 为了方便测试还上淘宝买了六个遥控器.

    Amlogic电视盒子的红外遥控配置

    相关的配置文件有

    /system/usr/keylayout/Generic.kl

    /system/usr/keylayout/Vendor_0001_Product_0001.kl

    /system/etc/remote.conf 或 /system/etc/remote1.conf

    Generic.kl文件

    Generic key layout file for full alphabetic US English PC style external keyboards.
    This file is intentionally very generic and is intended to support a broad rang of keyboards.
    Do not edit the generic key layout to support a specific keyboard; instead, create a new key layout file with the required keyboard configuration.

    这个文件的格式很简单, 每一行都是 key [Number] [Function], 按Number排序, 依次定义了每个Key Number对应的功能, 其内容为

    key 1     ESCAPE
    key 2     1
    key 3     2
    key 4     3
    key 5     4
    key 6     5
    key 7     6
    key 8     7
    key 9     8
    key 10    9
    key 11    0
    key 12    MINUS
    key 13    EQUALS
    key 14    DEL
    key 15    TAB
    ...
    

      

    Vendor_0001_Product_0001.kl

    Vendor_xxx.kl 这个文件是基于Generic.kl 的厂商自定义键布局, 在其基础上修改了一些key的定义, 其内容为

    key 399   GRAVE
    key 1     BACK
    key 2     1
    key 3     2
    key 4     3
    key 5     4
    key 6     5
    key 7     6
    key 8     7
    key 9     8
    key 10    9
    key 11    0
    key 15    BACK
    key 158   BACK
    key 58    SOFT_RIGHT
    key 107   ENDCALL
    ...
    

    remote.conf 和 remote1.conf

    系统默认用的是remote.conf, 但是有些固件使用的是remote1.conf. 如何判断呢? 我没找到合适的方法, 只能将其中一个文件更名后重启, 如果遥控器无法使用了, 就说明使用的是那个文件. remote.conf的格式会稍微复杂, 下面是一个完整的例子

    #*********************************************************************************************************
    # this file is configuration for each factory remote device
    # 	work_mode	  0 :software mode  1 :hardware mode
    #	repeat_enable	  0 :disable repeat 1 :enable repeat
    #
    #	factory_code      each device has it's unique factory code.
    #			  pattern:custom_code(16bit)+index_code(16bit)
    #			  examble: 0xff000001 = 0xff00(custom cod)  0001 (index)
    #
    #	release_delay	  unit:ms.release will report from kernel to user layer after this period of time
    #			  from press or repeat triggered.
    #
    #	debug_enable      0 :debug disable  1 :debug disable
    #
    # SW MODE:
    #	bit_count	  how many bits in each frame
    #	tw_leader_act	  time window for leader active
    #	tw_bit0		  time window for bit0 time.
    #	tw_bit1		  time window for bit1 time
    #	tw_repeat_leader  time window for repeat leader
    # REG                       
    #	reg_base_gen	  set value for PREG_IR_DEC_BASE_GEN
    #	reg_control	  set value for PREG_IR_DEC_CONTROL
    #	reg_leader_act	  set value for PREG_IR_DEC_LEADER_ACTIVE
    #	reg_leader_idle	  set value for PREG_IR_DEC_LEADER_IDLE
    #	reg_repeat_leader set value for PREG_IR_DEC_REPEAT_IDLE
    #	reg_bit0_time	  set value for PREG_IR_DEC_BIT0_TIME
    #*************************************************************************************************************
    #amlogic NEC remote
    work_mode  		= 0
    repeat_enable = 1
    repeat_delay = 130
    repeat_peroid = 120
    release_delay   =       20
    debug_enable 	= 1
    
    fn_key_scancode    = 0x15
    left_key_scancode  = 0x1c
    right_key_scancode = 0x48
    up_key_scancode    = 0x44
    down_key_scancode  = 0x1d
    ok_key_scancode    = 0x1e    
    pageup_key_scancode = 0x04
    pagedown_key_scancode = 0x1b
    
    custom_begin
      factory_infcode = 0
      factory_code	= 0xdd220001
    fn_key_scancode    = 0x15
    left_key_scancode  = 0x99
    right_key_scancode = 0xc1
    up_key_scancode    = 0xca
    down_key_scancode  = 0xd2
    ok_key_scancode    = 0xce
    pageup_key_scancode = 0xdd
    pagedown_key_scancode = 0x8c
    
      key_begin
        0xdc 116      ;STB_POWER
        0x9c 113      ;VOLUME_MUTE
        0x8d 150      ;SETTINGS
        #0xcd 141      ;RED     F6
        #0x91 142      ;GREEN   F7
        #0x83 143      ;YELLOW  F8
        #0xc3 144      ;BLUE    F9
        0x88 102      ;HOME
        0x95 15       ;BACK
        0xc5 145      ;HELP F1
        0x82 125      ;MENU
        0x99 105      ;DPAD_LEFT
        0xca 103      ;DPAD_UP
        0xc1 106      ;DPAD_RIGHT
        0xd2 108      ;DPAD_DOWN
        0xce 97       ;DPAD_CENTER
        0x80 104      ;VOLUME_UP
        0x81 109      ;VOLUME_DOWN
        0xdd  92      ;PAGE_UP
        0x8c  93      ;PAGE_DOWN
        0x85 166      ;CHANNEL_UP
        0x86 167      ;CHANNEL_DOWN
        0x89 121      ;MEDIA_REWIND
        0x84 120      ;MEDIA_FAST_FORWARD
        0xd9 119      ;MEDIA_PLAY_PAUSE
        0x96 128      ;MEDIA_STOP
        0x87 11       ;0
        0x92 2        ;1
        0x93 3        ;2
        0xcc 4        ;3
        0x8e 5        ;4
        0x8f 6        ;5
        0xc8 7        ;6
        0x8a 8        ;7
        0x8b 9        ;8
        0xc4 10       ;9
        0xda 228      ;POUND#
      key_end
      repeat_key_begin
        0xdc 116      ;STB_POWER
        0x9c 113      ;VOLUME_MUTE
        0x8d 150      ;SETTINGS
        #0xcd 141      ;RED     F6
        #0x91 142      ;GREEN   F7
        #0x83 143      ;YELLOW  F8
        #0xc3 144      ;BLUE    F9
        0x88 102      ;HOME
        0x95 15       ;BACK
        0xc5 145      ;HELP F1
        0x82 125      ;MENU
        0x99 105      ;DPAD_LEFT
        0xca 103      ;DPAD_UP
        0xc1 106      ;DPAD_RIGHT
        0xd2 108      ;DPAD_DOWN
        0xce 97       ;DPAD_CENTER
        0x80 104      ;VOLUME_UP
        0x81 109      ;VOLUME_DOWN
        0xdd  92      ;PAGE_UP
        0x8c  93      ;PAGE_DOWN
        0x85 166      ;CHANNEL_UP
        0x86 167      ;CHANNEL_DOWN
        0x89 121      ;MEDIA_REWIND
        0x84 120      ;MEDIA_FAST_FORWARD
        0xd9 119      ;MEDIA_PLAY_PAUSE
        0x96 128      ;MEDIA_STOP
        0x87 11       ;0
        0x92 2        ;1
        0x93 3        ;2
        0xcc 4        ;3
        0x8e 5        ;4
        0x8f 6        ;5
        0xc8 7        ;6
        0x8a 8        ;7
        0x8b 9        ;8
        0xc4 10       ;9
        0xda 228      ;POUND#
      repeat_key_end
    custom_end                   
    

    在头部注释部分, 已经对文件的内容作了说明, 在注释部分之外

    首先是 #amlogic NEC remote , 这行固定保留

    然后是全局参数配置,

    然后是每个遥控器的配置, 以 custom_begin 开始, 以 custom_end 结束, 可以有多个遥控器配置共存, 

    每个遥控器配置以 

    factory_infcode = 0
    factory_code = 0xdd220001

    这两行作区分, 这两个值都要和其他遥控器配置不同, 其中 factory_infcode 似乎是序号, 而factory_code是要跟遥控器按键产生的十六进制码后4位一致的.

    键位定义包含 key_begin, key_end 和 repeat_key_begin , repeat_key_end 两部分, 这两部分分别代表了"单击"和"按住"对应的键功能, 如非特殊都可以设成一样的.

    简单的说, 就是遥控器按键产生的十六进制码被盒子接收器接收后, 通过remote.conf找到了对应的key number, 再通过kl文件, 找到了对应的function, 然后就产生了操作.

    红外遥控器键码识别

    如果一个遥控器按键无法识别, 或者已有的遥控器想修改键功能, 但是不知道键码怎么办? 

    首先你要有盒子的TTL环境, 这样才能通过命令行与盒子交互, 理论上在安卓的Terminal APP中应该也可以的, 我还没试过.

    网上有些文章说的systemctl stop eventlircd, ir-keytable -t 这些命令并非每个盒子都有, 但是dmesg命令基本上都是会有的, 可以通过dmesg. 因为其工作机制, 在键码能识别的时候, 是不会记录日志的, 所以要先将remote.conf或remote1.conf更名重启, 然后试试按遥控器, 再执行 dmesg -s 5000, 看看是不是会出现这样的日志记录

    [ 5095.872000] Wrong custom code is 0xef109c21
    [ 5097.694000] Wrong custom code is 0xee119c21
    

    这就是记录下来的键码. 键码一共8位, 前2位是校验用的, 第3 - 4位是需要写在remote.conf里的键码, 第5 - 8位是设备码, 要跟factory_code的前4位一致.

    记录键码的一些操作技巧: 首先四周不能有其他遥控器的干扰, 例如旁边有人在看电视按遥控器, 这样不行. 其次, 因为dmesg会不断产生新的系统消息, 对记录也产生干扰, 所以在操作的时候, 可以一次性按顺序按下七八个按键, 例如 开机, 后退, 上下左右中, 再立即命令行执行 dmesg -s 5000, 这时候最新的记录里面, 这7个键码就基本上是在一块的, 方便提取. 

    这样把遥控器的键码都记下来, 然后编辑remote.conf, 让盒子能识别. 

    在编辑remote.conf时, 可以先将kl里的 key number - > function 先列出来, 前面打上#, 这样方便对应, 例如

    custom_begin
        factory_infcode = 7
        factory_code    = 0xff000001 
    
      key_begin
            #1        ;BACK
        0x0f 2        ;1
        0x11 3        ;2
        0x12 4        ;3
        0x4c 5        ;4
        0x58 6        ;5
        0x1b 7        ;6
        0x17 8        ;7
        0x4d 9        ;8
        0x0a 10       ;9
        0x1d 11       ;0
            #12       ;MINUS
            #13       ;EQUALS
            #14       ;DEL
            #15       ;BACK
            #16       ;Q
            #17       ;W
            #18       ;E
            #19       ;R
            #20       ;T
            #21       ;Y
            #22       ;U                 
            #23       ;I
            #24       ;O
            #25       ;P
            #26       ;LEFT_BRACKET
            #27       ;RIGHT_BRACKET
            #28       ;ENTER      
            #30       ;A
            #31       ;S
            #32       ;D
            #33       ;F
            #34       ;G
            #35       ;H
            #36       ;J
            #37       ;K
            #38       ;L
            #39       ;SEMICOLON
            #40       ;APOSTROPHE
            #42       ;SHIFT_LEFT
            #43       ;BACKSLASH
            #44       ;Z
            #45       ;X
            #46       ;C
            #47       ;V
            #48       ;B
            #49       ;N
            #50       ;M
            #51       ;COMMA
            #52       ;PERIOD.
            #53       ;SLASH
        0x55 97       ;DPAD_CENTER
        0x4e 102      ;HOME    
        0x46 103      ;DPAD_UP
        0x47 105      ;DPAD_LEFT
        0x15 106      ;DPAD_RIGHT
        0x16 108      ;DPAD_DOWN
        0x10 114      ;VOLUME_DOWN
        0x14 115      ;VOLUME_UP
        0x18 116      ;POWER	WAKE
        0x4f 141      ;SETTINGS
            #113      ;MUTE
            #119      ;MEDIA_PLAY_PAUSE
            #120      ;MEDIA_FAST_FORWARD
            #121      ;MEDIA_REWIND
            #122      ;MEDIA_PREVIOUS
            #123      ;MEDIA_NEXT
            #125      ;MENU
        0x04 139      ;MENU
        0x40 158      ;BACK
        0x1c 227      ;STAR*
        0x1e 228      ;POUND#
      key_end
    
      repeat_key_begin
            #1        ;BACK
        0x0f 2        ;1
        0x11 3        ;2
        0x12 4        ;3
        0x4c 5        ;4
        0x58 6        ;5
        0x1b 7        ;6
        0x17 8        ;7
        0x4d 9        ;8
        0x0a 10       ;9
        0x1d 11       ;0
            #12       ;MINUS
            #13       ;EQUALS
            #14       ;DEL
            #15       ;BACK
            #16       ;Q
            #17       ;W
            #18       ;E
            #19       ;R
            #20       ;T
            #21       ;Y
            #22       ;U                 
            #23       ;I
            #24       ;O
            #25       ;P
            #26       ;LEFT_BRACKET
            #27       ;RIGHT_BRACKET
            #28       ;ENTER      
            #30       ;A
            #31       ;S
            #32       ;D
            #33       ;F
            #34       ;G
            #35       ;H
            #36       ;J
            #37       ;K
            #38       ;L
            #39       ;SEMICOLON
            #40       ;APOSTROPHE
            #42       ;SHIFT_LEFT
            #43       ;BACKSLASH
            #44       ;Z
            #45       ;X
            #46       ;C
            #47       ;V
            #48       ;B
            #49       ;N
            #50       ;M
            #51       ;COMMA
            #52       ;PERIOD.
            #53       ;SLASH
        0x55 97       ;DPAD_CENTER
        0x4e 102      ;HOME    
        0x46 103      ;DPAD_UP
        0x47 105      ;DPAD_LEFT
        0x15 106      ;DPAD_RIGHT
        0x16 108      ;DPAD_DOWN
        0x10 114      ;VOLUME_DOWN
        0x14 115      ;VOLUME_UP
        0x18 116      ;POWER	WAKE
        0x4f 141      ;SETTINGS
            #113      ;MUTE
            #119      ;MEDIA_PLAY_PAUSE
            #120      ;MEDIA_FAST_FORWARD
            #121      ;MEDIA_REWIND
            #122      ;MEDIA_PREVIOUS
            #123      ;MEDIA_NEXT
            #125      ;MENU
        0x04 139      ;MENU
        0x40 158      ;BACK
        0x1c 227      ;STAR*
        0x1e 228      ;POUND#
      repeat_key_end
    custom_end
    

     remote.conf编辑完后, 可以通过安卓的Root Explorer应用将原来的remote.conf备份, 再将新的remote.conf放进去, 重启后就能测试效果了.

  • 相关阅读:
    css之隐藏内容的方法
    字符串对象的各种方法
    javascript之自增自减典型运算(易错)
    Fuel 30 分钟快速安装OpenStack
    使用Sublime Text 3做Python开发
    Ubuntu 14.04.02 安装openvswitch-2.3.1
    linux 技巧:使用 screen 管理你的远程会话
    MQTT的学习研究(十七)Mosquitto简要教程(安装&使用)
    MQTT的学习研究(十六) MQTT的Mosquitto的window安装部署
    MQTT的学习研究(十五) MQTT 和android整合文章
  • 原文地址:https://www.cnblogs.com/milton/p/12355976.html
Copyright © 2011-2022 走看看