前一陣做了個安卓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 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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放進去, 重啟后就能測試效果了.
