這幾天在研究Amlogic的紅外搖控,主要涉及到/system/etc/remote.conf和/system/usr/keylayout/Vendor_0001_Product_0001.kl這兩個文件,其實一般情況下只需要修改/system/etc/remote.conf這個文件就可以了,下面我們來介紹下remote.conf怎麼修改.
換搖控之後,你按鍵會出現這樣的打印信息:
[ 727.416139@0] Wrong custom code is 0x2dd2ff00
[ 727.868522@0] Wrong custom code is 0x6699ff00
[ 728.217197@0] Wrong custom code is 0x3ec1ff00
[ 728.626735@0] Wrong custom code is 0x2dd2ff00
[ 728.929900@0] Wrong custom code is 0x6699ff00
[ 729.239544@0] Wrong custom code is 0x3ec1ff00
如果按鍵沒這些,請在終端執行remotecfg,如果還是沒有執行下dmesg查看下內核信息.
我們來看下remote.conf的內容:
[java]
#*********************************************************************************************************
#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
factory_code = 0xff000001
work_mode = 1
repeat_enable = 1
release_delay = 150
debug_enable = 1
reg_control = 0xfbe40
#left 0x6699ff00
left_key_scancode = 0x99
right_key_scancode = 0xc1
up_key_scancode = 0xca
down_key_scancode = 0xd2
ok_key_scancode = 0xce
key_begin
0x99 105
0xc1 106
0xca 103
0xd2 108
0xce 28
0x92 2
0x93 3
key_end
這個是我修改之後的,首先看下這部分:
[java]
#amlogic NEC remote
factory_code = 0xff000001
work_mode = 1
repeat_enable = 1
release_delay = 150
debug_enable = 1
reg_control = 0xfbe40
這裡只有factory_code需要進行修改,我們按鍵之後的打印信息如下:
[ 727.416139@0] Wrong custom code is 0x2dd2ff00
[ 727.868522@0] Wrong custom code is 0x6699ff00
[ 728.217197@0] Wrong custom code is 0x3ec1ff00
[ 728.626735@0] Wrong custom code is 0x2dd2ff00
[ 728.929900@0] Wrong custom code is 0x6699ff00
[ 729.239544@0] Wrong custom code is 0x3ec1ff00
可以看到後16位是不變的都是ff00,有的可能是在高16位例如:
[ 728.929900@0] Wrong custom code is 0xff002dd2
[ 729.239544@0] Wrong custom code is 0xff003ec1
這是我亂編的,當然也有可能不是ff00也有可能是其它的,所以這裡我們得到factory_code
factory_code就是0xff000001,前面得到的ff00在高位,低位的0001網上說可以隨便寫,不過這裡還是寫成0001
我們依次讀到各個按鍵所打印出的數據:
[ 727.416139@0] Wrong custom code is 0x2dd2ff00
[ 727.868522@0] Wrong custom code is 0x6699ff00
[ 728.217197@0] Wrong custom code is 0x3ec1ff00
[ 728.626735@0] Wrong custom code is 0x2dd2ff00
[ 728.929900@0] Wrong custom code is 0x6699ff00
[ 729.239544@0] Wrong custom code is 0x3ec1ff00
這些code就是對應的按鍵信息:
up: 0x35caff00
down:0x2dd2ff00
left:0x6699ff00
right:0x3ec1ff00
這裡我就只說這幾個了,其它的按鍵方法都是一樣.
我們看到remote.conf剩下的部分:
[java]
left_key_scancode = 0x99
right_key_scancode = 0xc1
up_key_scancode = 0xca
down_key_scancode = 0xd2
ok_key_scancode = 0xce
key_begin
0x99 105
0xc1 106
0xca 103
0xd2 108
0xce 28
0x92 2
0x93 3
key_end
left_key_scancode後面的是一個8位的數和key_begin下面的以0x開關的數都是從
[ 727.416139@0] Wrong custom code is 0x2dd2ff00
[ 727.868522@0] Wrong custom code is 0x6699ff00
[ 728.217197@0] Wrong custom code is 0x3ec1ff00
[ 728.626735@0] Wrong custom code is 0x2dd2ff00
[ 728.929900@0] Wrong custom code is 0x6699ff00
[ 729.239544@0] Wrong custom code is 0x3ec1ff00
這些數據裡面解析出來的,而key_begin後面的105 106 這些都是對應的系統的鍵碼
我們先來看下前面的那個0x的數據怎麼得到,首先以0x2dd2ff00為例,這個在搖控器上是對應的方向鍵down
0x2dd2ff00去掉產家代號ff00後剩下的就是2dd2了,remote.conf中的數值碼就是以0x開關的那個要麼就是0x2d要麼就是0xd2,不是高8位就是低8位,這個不同的產家有可能不一樣,像我這個就是低8位0xd2,這個我是試了之後才知道的。
不過也可以不用試就可以得出,首先得記錄搖控器各個按鍵的編碼,然後修改remote.conf的factory_code後,重啟盒子,然後你在按鍵的時候就會出來這樣的信息:
[ 145.727698@0] scancode is 0x008a, invalid key is 0x0000.
[ 145.868198@0] scancode is 0x008a, invalid key is 0x0000.
[ 166.160143@0] scancode is 0x008b, invalid key is 0x0000.
[ 166.308242@0] scancode is 0x008b, invalid key is 0x0000.
這個0x008a,8a是低8位,所以可以確定低8位是按鍵數值碼.
下面說下remote.conf後面的105 103這些值,這些都是系統鍵碼,碼值定義一般是在內核源碼include/linux/input.h中,然後在/system/usr/keylayout/Vendor_0001_Product_0001.kl中也會出現部分,當你要用的按鍵功能這個.kl裡沒有的時候你就可以去input.h裡找.
我們看下/system/usr/keylayout/Vendor_0001_Product_0001.kl內容:
[java]
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
key 62 ENDCALL
key 139 MENU
key 125 MENU
key 60 NOTIFICATION
key 127 SEARCH
key 217 SEARCH
key 228 POUND
key 227 STAR
key 231 CALL
key 61 CALL
key 97 DPAD_CENTER
key 232 DPAD_CENTER
key 108 DPAD_DOWN
key 103 DPAD_UP
key 102 HOME
key 105 DPAD_LEFT
key 106 DPAD_RIGHT
key 115 VOLUME_UP
key 114 VOLUME_DOWN
key 104 VOLUME_UP
key 109 VOLUME_DOWN
key 212 CAMERA
key 16 Q
key 17 W
key 18 E
key 19 R
key 20 T
key 21 Y
key 22 U
key 23 I
key 24 O
key 25 P
key 26 LEFT_BRACKET
key 27 RIGHT_BRACKET
key 43 BACKSLASH
key 30 A
key 31 S
key 32 D
key 33 F
key 34 G
key 35 H
key 36 J
key 37 K
key 38 L
key 39 SEMICOLON
key 40 APOSTROPHE
key 14 DEL
key 44 Z
key 45 X
key 46 C
key 47 V
key 48 B
key 49 N
key 50 M
key 51 COMMA
key 52 PERIOD
key 53 SLASH
key 28 ENTER
key 56 ALT_LEFT
key 100 ALT_RIGHT
key 42 SHIFT_LEFT
key 54 SHIFT_RIGHT
#key 15 TAB
key 57 SPACE
key 70 EXPLORER
key 155 ENVELOPE
key 12 MINUS
key 13 EQUALS
key 215 AT
key 119 MEDIA_PLAY_PAUSE
key 122 MEDIA_PREVIOUS
key 123 MEDIA_NEXT
key 120 MEDIA_FAST_FORWARD
key 121 MEDIA_REWIND
key 116 POWER WAKE
key 113 VOLUME_MUTE
key 128 MEDIA_STOP
key 130 ZOOM_IN
key 131 ZOOM_OUT
key 133 TAB
key 140 F10
裡面有一個:
[java]
key 108 DPAD_DOWN
這個108就是down對應的系統鍵碼
前面我們說到搖控器down對應的編碼是0x2dd2ff00
按鍵數值碼是0xd2,功能是down,所以在key_begin裡就應該是:
0xd2 108
我的搖控器部分編碼:
up:0x35caff00
down:0x2dd2ff00
left:0x6699ff00
right:0x3ec1ff00
1:0x6d92ff00
2:0x6c93ff00
所以最後的remote.conf為:
[java]
#*********************************************************************************************************
#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
factory_code = 0xff000001
work_mode = 1
repeat_enable = 1
release_delay = 150
debug_enable = 1
reg_control = 0xfbe40
#left 0x6699ff00
left_key_scancode = 0x99
right_key_scancode = 0xc1
up_key_scancode = 0xca
down_key_scancode = 0xd2
ok_key_scancode = 0xce
key_begin
0x99 105
0xc1 106
0xca 103
0xd2 108
0xce 28
0x92 2
0x93 3
key_end
網上有一對remote.conf裡面這些的詳細說明,我這裡就不作說明,我就說下這些數據怎麼來的,不知道有沒有說清楚。