Please select To the mobile version | Continue to access the desktop computer version

OrangePi

 Login            
 Register            
Search
Hot search: orangepi
View: 10610|Reply: 5

Tutorial: How to add IR Remote in Android

[Copy link]

2

Threads

11

Posts

74

Credits

Registered member

Rank: 2

Credits
74
Post time 2016-3-26 23:00:08 | Show all posts |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 the Code
Now open terminal emulator and enter the command:
  1. su
Copy the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the Code
If nothing has gone wrong youre remote should work.

0

Threads

1

Posts

34

Credits

Novice

Rank: 1

Credits
34
Post time 2016-4-5 00:34:41 | Show all posts
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
Post time 2016-7-26 20:51:44 | Show all posts
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

620

Credits

Senior member

Rank: 4

Credits
620
Post time 2016-11-6 23:52:27 | Show all posts
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
Post time 2016-11-18 12:39:40 | Show all posts
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
Post time 2016-11-21 21:49:34 | Show all posts
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

You have to log in before you can reply Login | Register

Points Rules

Archiver|Mobile edition|Darkroom|OrangePi En ( 粤ICP备14086627号-2

2018-12-19 12:16 GMT+8 , Processed in 0.030025 second(s), 22 queries .

Powered by Discuz! X3.2

© 2014-2015 orangepibbs en.

Quick Reply To Top Return to the list