View: 23508|Reply: 13

Tutorial: How to add IR Remote in Android

[Copy link]

2

threads

11

posts

74

credits

Registered member

Rank: 2

credits
74
Published in 2016-3-26 23:00:08 | Show all floors |Read mode
Edited by jmanjulian at 2016-3-26 23:21

As we all know the Orange PI PC has an ir reciever but no official guide on how to use it. There is already a tutorial in the forum on how to setup ir using lirc HERE:Forum_link_second_post But that is more complicated and is not necessary because all that is needed is already inside the Beelink and Zido images of Android. In order to setup Ir you must use an android rom that is rooted or find a way to root it youreself. Luckily Beelink and Ziddo images come prerooted and i am using this one ROM
To get started download an terminal emulator app like Android terminal. I also recommend installing Total commander as a file manager to do all file modiffications because it has an automatic remount feature wich will take kare of all the read-only filesystem problems when you edit the config files in the system partition. Or you can use the command:
  1. mount -o remount,rw /system
Copy code
Now open terminal emulator and enter the command:
  1. su
Copy code
This will grant superuser privilages to the terminal. In order to setup the remote you need to remove the old config first. Open total commander and go to root filesystem /system/usr/keylayout and rename the sunxi-ir.kl to something else i reccomend sunxi-ir.kl.bak. You can do this in the terminal also with the command:
  1. mount -o remount,rw /system
  2. mv /system/usr/keylayout/sunxi-ir.kl /system/usr/keylayout/sunxi-ir.kl.bak
Copy code
Once we have a backup of the original config file we make a new one:
  1. mount -o remount,rw /system
  2. echo new > /system/usr/keylayout/sunxi-ir.kl
Copy code
There seams to be some bug in the sunxi ir driver or maybe the android image itself that prevents the driver from working correctly because it starts with an invalid config. To fix this we must just stop the driver module and reload it. Do the following command in the terminal:
  1. rmmod sunxi_ir_rx
  2. insmod /vendor/modules/sunxi-ir-rx.ko
Copy code
Now the ir reciever should be readi and working but the config is not valid for youre remote because the config file we made is still empty.
To make a valid config we must get the key codes our remotes sends to android. This is done with the command:
  1. getevent
Copy code
The output will be something like this:
  1. root@dolphin-fvd-p1:/ # getevent
  2. add device 1: /dev/input/event6
  3.   name:     "sunxi-ir"
  4. add device 2: /dev/input/event7
  5.   name:     "Virtual.Acc"
  6. could not get driver version for /dev/input/js0, Invalid argument
  7. add device 3: /dev/input/event5
  8.   name:     "Logitech USB Optical Mouse"
  9. could not get driver version for /dev/input/mouse1, Not a typewriter
  10. add device 4: /dev/input/event4
  11.   name:     "USB USB Keykoard"
  12. add device 5: /dev/input/event3
  13.   name:     "USB USB Keykoard"
  14. add device 6: /dev/input/event2
  15.   name:     "sunxi-ths"
  16. add device 7: /dev/input/event1
  17.   name:     "sunxi-gpiokey"
  18. could not get driver version for /dev/input/mouse0, Not a typewriter
  19. add device 8: /dev/input/event0
  20.   name:     "vmouse"
  21. could not get driver version for /dev/input/mice, Not a typewriter
  22. /dev/input/event3: 0004 0004 00070028
  23. /dev/input/event3: 0001 001c 00000000
  24. /dev/input/event3: 0000 0000 00000000
  25. /dev/input/event6: 0001 0012 00000001
  26. /dev/input/event6: 0000 0000 00000000
  27. ^@/dev/input/event6: 0001 0012 00000000
  28. /dev/input/event6: 0000 0000 00000000
  29. /dev/input/event6: 0001 000b 00000001
Copy code
Notice the first two lines "add device 1: /dev/input/event6" and "name: "sunxi-ir"". This tels us the IR reciever is event6. Now dont press anything on the keyboard or mouse because that will be shown as an event as you can see the event3 lines are from the mouse. Point the remote at the OrangePI and press any button. If youre remote is using a compatible portocol the button press will appear as a new event6 line (usually 2 lines one on button press and one on button release) example:
  1. /dev/input/event6: 0001 0012 00000001
  2. /dev/input/event6: 0000 0000 00000000
Copy code
The code that we need is the second number from the first line in this case it is 0012. The problem is this is in hex and the config file needs it in decimal so we have to cenvert it with a calculator. I used this online one HEX to DEC convertor. 0012 converted is 18 so this is our button kode. Now you must repeat this for all the buttons on youre remote that you want to use. After you gathere all the button codes of youre remote you can stop getevent by pressing ctrl+c.
In total commander open the new config file that we made in the first step (/system/usr/keylayout/sunxi-ir.kl) and add all the key codes each on a new line like this: key "keycode" android command
  1. key    18  POWER WAKE
  2. key    19  MUTE
  3. key    14  MEDIA_STOP
  4. key    31  MEDIA_PLAY
  5. key    30  MEDIA_PAUSE
  6. key    15  MEDIA_PREVIOUS
  7. key    26  MEDIA_NEXT
  8. key    11  DPAD_UP
  9. key    21  DPAD_DOWN
  10. key    24  DPAD_LEFT
  11. key    12  DPAD_RIGHT
  12. key    22  ENTER
  13. key    13  BACK
  14. key    25  VOLUME_UP
  15. key    29  VOLUME_DOWN
Copy code
This is my config and it only uses some basic buttons. You can open the original config file that we made a backup of (/system/usr/keylayout/sunxi-ir.kl.bak) and look at all the available android commands. There may be more command but i dont know where to get a full list. After we have the ready config file with our chosen commands linked to our remote keycodes we need to just reload the ir driver again so it can load the new config and we are done.
  1. rmmod sunxi_ir_rx
  2. insmod /vendor/modules/sunxi-ir-rx.ko
Copy code
If nothing has gone wrong youre remote should work.

0

threads

1

posts

34

credits

Novice

Rank: 1

credits
34
Published in 2016-4-5 00:34:41 | Show all floors
Fantastic post, and I've found it worked well. This option is better than using the LIRC.

Does anyone know if you can use remote IR than not use NEC code? I would not have achieved

0

threads

3

posts

44

credits

Novice

Rank: 1

credits
44
Published in 2016-7-26 20:51:44 | Show all floors
Edited by Sputk1n at 2016-7-26 20:58

unfortunately in my case does not go , the file seems to have no effect on the system . tips?

3

threads

38

posts

1036

credits

Gold member

Rank: 6Rank: 6

credits
1036
Published in 2016-11-6 23:52:27 | Show all floors
my remote controller works. But it will stop working after reboot. How to make it work after reboot automatically?

0

threads

10

posts

56

credits

Registered member

Rank: 2

credits
56
Published in 2016-11-18 12:39:40 | Show all floors
Didn't work for me. think my rom looks at a different file. So I used total commander to mod Generic.kl file, it worked great but also when reboot the system the remote wont work again

0

threads

10

posts

56

credits

Registered member

Rank: 2

credits
56
Published in 2016-11-21 21:49:34 | Show all floors
To keep setting after restart/reboot you need to make a script, save it somewhere you can find it and run it at start up.

First use your favourite editor to create a script. (I named mine startup.sh and saved it to /sdcard/download. It really does not matter much where you store your script and what name you give to it, as long as you can find it and the android can access it at boot.

Here is mine:
#!/system/bin/sh
mount -o remount,rw /system
rmmod sunxi_ir_rx
insmod /system/vendor/modules/sunxi-ir-rx.ko


You need to give you script proper premissions.
chmod 777 /sdcard/download/startup.sh


Then I used Script Manager to run my script after boot. Now remote works after reboot

6

threads

135

posts

692

credits

Senior member

Rank: 4

credits
692
Published in 2024-3-11 17:46:47 | Show all floors
This is certainly additionally an exceedingly wonderful offer everyone truly qualified on the lookout with. It's always not likely everyday there is chances read a little something. Sobha Crystal Meadows
Published in 2024-3-16 18:44:44 | Show all floors
Heya i¡¯m for the first time here. I found this board and I find It truly helpful & it helped me out much. I’m hoping to present something again and aid others such as you aided me.        gutter cleaning grimsby
Published in 2024-3-20 19:38:18 | Show all floors
Super-Duper site! I am Loving it!! Will come back again, Im taking your feed also, Thanks.        ae888bet1.com
Published in 2024-3-20 19:45:07 | Show all floors
Promptly the internet site could possibly irrefutably receive credited extremely connected with placing people, to its diligent articles and reviews or maybe vital opinions.        free trial
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list