TV infrared/Bluetooth remote control key value definition and adaptation

Adaptation and common problems of TV remote control

Remote control key value adaptation

Generally speaking, the remote control is divided into Bluetooth remote control and infrared remote control. Infrared remote control means that the remote control transmits signals through an infrared transmitter, and the receiving device receives signals through an infrared receiver; Bluetooth remote control means that the remote control interacts through Bluetooth, and both the remote control and the connected device support Bluetooth. Bluetooth operation is possible.
Each button of each remote control has a unique physical code, which is already available when the remote control leaves the factory, and different remote control manufacturers also have separate user codes. We need to make corresponding adaptation and mapping in the SDK through the known conditions.

  • The infrared key value of the remote control is not defined
    1. Step 1 : What is the scancode corresponding to the key of the remote control? There are two ways to know what the undefined value of this scancode is. 1. Use the command dmesg -c; 2. Use echo 8 > /proc/sys/kernel/printk; these two methods can query the undefined physical code of a button on the remote control. Below I use the volume key minus definition as an example.
    Use dmesg -c to query as follows: As
    insert image description here
    shown in the figure above, it is obvious that the physical code defined by the volume key is 154, which is a decimal value and needs to be converted to hexadecimal. After conversion, it is 9A. This value Keep it in mind first, and you need to use it later when adapting.

    2. The second step : You need to know the user code of the remote control. Each remote control has a unique user code, just like everyone has their own ID card. The user code is the ID card of the remote control. Use the cat /sys/devices/virtual/remote/amremote/customcode command to view the user code of the remote control. After executing this command on the serial port, press any key on the remote control and execute this command again to see that you are using this remote control device user code.

    3. The third step : define. The remote configuration file related to the user code needs to be defined. This file mainly maps the physical code and the Android key code, and is a hub file connecting the bottom layer and the upper layer. Once you know the user code and physical code, you can start configuring the remote configuration file. The configuration content is as follows:

    // remote配置文件
    custom_name = test-remote-1
    custom_code = 0xc43b
    release_delay = 80
    key_begin
        0x9a    114   #VOLUME_DOWN
    key_end
    

    At this time, use the getevent command, and then press the volume key to decrease, there will be corresponding output, as follows:
    insert image description here
    But the function of the volume key is not working properly at this time, and the remote file needs to be associated with the kl file.

    4. Step 4 : Need to know which kl corresponds to the remote control, and what are the pid and vid of the remote control? You can also know which kl file is currently used by the remote control? From the above steps, we can know that the event currently used by the remote control is /dev/input/event1, you can use getevent -v to know which pid and vid corresponds to /dev/input/event1, use getevent -v to get the following results :
    insert image description here
    The red box is the pid and vid, we can directly configure the kl file through the pid and vid, and place the file in the specified directory. You can use the dumpsys input command to query the current kl file corresponding to /dev/input/event1, as follows:
    insert image description here
    Now that you know the kl file, the file name also corresponds to pid and vid, so you don’t need to create a new one, directly modify the file through vi, and reduce the volume key The logic is added in. Just defined 0x9a in the remote file to correspond to 114, so in the kl file, the id of 114 is used for identification. Add the logic in the kl file as follows:

    key 114   VOLUME_DOWN
    

    At this time, the volume key down function has taken effect, and there must be some observers who will be very puzzled why the volume key down function will take effect. In fact, the key lies in the value of VOLUME_DOWN. This is not just written casually, but there are underlying files corresponding to it. of.

    5. Step 5 : To find the relevant definition of the KeyEvent.java file, the path is frameworks/base/core/java/android/view/, and the relevant code is as follows:

        /** Key code constant: Volume Down key.
     	* Adjusts the speaker volume down. */
        public static final int KEYCODE_VOLUME_DOWN     = 25;
    

    The value 25 is mapped to the top-level Android key value, which can be queried through the command logcat -s WindowManager, press the volume button to decrease, and the output of logcat -s WindowManager is as follows: pressing and popping up is a cycle, and you can see the
    insert image description here
    output The result is 25, which corresponds to the value in the KeyEvent.java file.
    Key point: The generally defined key value involves three files (attrs.xml, keycodes.h, InputEventLabels.h), and some logic related to volume key reduction will be obtained in these three files, as follows:

    //路径为:frameworks/base/core/res/res/values/attrs.xml
    <enum name="KEYCODE_VOLUME_DOWN" value="25" />
    
    //路径为:frameworks/native/include/android/keycodes.h
    /** Volume Down key.
     * Adjusts the speaker volume down. */
    AKEYCODE_VOLUME_DOWN     = 25,
    
    //路径为:frameworks/native/include/input/InputEventLabels.h
    DEFINE_KEYCODE(VOLUME_DOWN),
    

    After that, you need to define the custom key value in the four files.
    Tips: Hotkeys can be configured in the hotkey.properties file, which is generally preset in the /system/etc directory of the device.
    So far, the simple adaptation and definition of the key value of the infrared remote control has been explained. Next, the key value adaptation and definition of the Bluetooth remote control will be discussed.

  • The bluetooth key value of the remote control is not defined
    1. Step 1 : Connect the bluetooth remote control and the device through bluetooth.
    2. The second step : You need to know the usage ID of the Bluetooth HID key code value that does not define the remote control. If it is a custom Usage ID, it generally needs to be provided by the remote control manufacturer, which is generally defined according to the specification. I take the # key of the Bluetooth remote control as an example. At present, the # key of the Bluetooth remote control has no effect, and there is no output through the getevent command. The usage ID of the # key is 0x304 through the query. This needs to be remembered, and the following adaptation needs to be used.
    Tips: The HID key code value is not only the Usage ID, but also the Usage Page. The Usage Page is generally 0x07 and 0x0C. 0x07 represents the defined key code, and 0x0C represents the user-defined key code.
    3. Step 3 : To adapt the HID key value, you first need to modify hid-input.c. This file is first associated with Usage ID and input.h. User-defined key values ​​generally need to be modified in hid-input.c hidinput_configure_usage method, and then find the HID_UP_CONSUMER in the method to add, the code is added as follows:

    //common/drivers/hid/hid-input.c
    case 0x304: map_key_clear(KEY_POUND);		break;
    

    The input.h file must also add relevant codes. The corresponding values ​​in input.h will be output by getevent at that time. The added codes are as follows:

    //common/include/uapi/linux/input.h
    #define KEY_POUND		0x2f1
    

    Note: In input.h, you can also know that the defined maximum value cannot exceed 0x2ff, otherwise the definition will fail if it overflows.
    Little knowledge: The HID key code table of 0x07 is as follows:

    	static const unsigned char hid_keyboard[256] = {
    	  0,  0,  0,  0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38,
    	 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44,  2,  3,
    	  4,  5,  6,  7,  8,  9, 10, 11, 28,  1, 14, 15, 57, 12, 13, 26,
    	 27, 43, 43, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64,
    	 65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106,
    	105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71,
    	 72, 73, 82, 83, 86,127,116,117,183,184,185,186,187,188,189,190,
    	191,192,193,194,134,138,130,132,128,129,131,137,133,135,136,113,
    	115,114,unk,unk,unk,121,unk, 89, 93,124, 92, 94, 95,unk,unk,unk,
    	122,123, 90, 91, 85,unk,unk,unk,unk,unk,unk,unk,111,unk,unk,unk,
    	unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,
    	unk,unk,unk,unk,unk,unk,179,180,unk,unk,unk,unk,unk,unk,unk,unk,
    	unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,
    	unk,unk,unk,unk,unk,unk,unk,unk,111,unk,unk,unk,unk,unk,unk,unk,
    	 29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113,
    	150,158,159,128,136,177,178,176,142,152,173,140,unk,unk,unk,unk
    };
    

    4. The fourth step : getevent has a value and knows that the value is 0x2f1. It needs to be converted to 753 in decimal. It needs to be configured in the corresponding kl file. Get the pid and vid of the Bluetooth remote control through getevent -v, as follows: So
    insert image description here
    pass pid and vid can be configured with related kl. Use dumpsys input to know that the currently used kl is the default, as follows:
    insert image description here
    configure kl through pid and vid, the name is Vendor_0508_Product_0110.kl, and the configuration and content are as follows:
    insert image description here

    ///system/usr/keylayout/Vendor_0508_Product_0110.kl
    key 753  POUND
    

    So far, the definition of Bluetooth key value is completed.

    From the above, the key value definition and adaptation of the infrared remote control and the Bluetooth remote control are completed. If you have any questions, please contact.

Guess you like

Origin blog.csdn.net/weixin_47368640/article/details/129026336