In fact, this is the first task for the Linux driver in the company. It should be put on the Linux, but there are many infrared remote controls in Linux, however, there is no information on the Internet about the infrared remote control in Android. Just write it down to help you learn new things.
Here, I have debugged the IR driver in Linux. At first, it was registered as a char device. However, in Android, basically all the drivers are input devices, this is because the device node in the/dev/input/directory is enabled in eventhub. Therefore, if the remote control is used as the input device, it is not better. In fact, the input device also belongs to the char device, but she has implemented many mechanisms and only needs to report the data, simple and Convenient. Here is an assumption that we want to map the key codes of IR to the keyboard of Android. Can this be done directly? With this problem, we tested the infrared drive of the prepared IR. You can add power, volume, numbers, home, return, menu, and so on.
Unexpectedly, after the driver layer is well adapted, the android upper layer can be implemented. As a result, we have not gone into depth and implemented the functions. The following describes the implementation process.
The first step is to register as an input device. There are many online devices, followed by remote control decoding. The specific decoding process has been well implemented. After the interruption, because the decoding process is time-consuming, it will be placed in the lower half of the interruption to work, that is, in the work queue. Then, report the key value according to the implemented code. For example, if you press the power key
input_report_key(ir_dev, KEY_POWER, 1);input_report_key(ir_dev, KEY_POWER, 0);input_sync(ir_dev);
In this case, the android upper layer will know that this is the power key. If it is the volume plus key, it will be reported.
input_report_key(ir_dev, KEY_VOLUMEUP, 1);input_report_key(ir_dev, KEY_VOLUMEUP, 0);input_sync(ir_dev);
You can also control the volume when playing music.
The specific key_power, key_volumeup, and so on can be found in Linux/Linux. h in Linux. Basically, all operations are defined. All functions can be mapped to the android keyboard. At this point, you can use the remote control to control various Android functions.