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

OrangePi

 Login            
 Register            
Search
Hot search: orangepi
View: 20662|Reply: 52

How to: setup wakeup with your IR remote control

[Copy link]

1

Threads

2

Posts

13

Credits

Novice

Rank: 1

Credits
13
Post time 2016-10-12 23:02:46 | Show all posts |Read mode
The only thing missing for me on OE on a NanoPI-M1 (identical to the OPi One) was being able to wake up the board with the IR remote (a brandless one I bought on Ebay). The procedure I used to set it up was as follows:

1. Setup lirc as indicated on the FAQ. Make sure you set up the POWER button on your remote to the KEY_SLEEP code.
2. At this point you should be able to put the board to sleep using the POWER button on the remote, but will need to press the K1 button on the board to wake it up.
3. Power off the board and put the SD card on your work computer. I'm using Kubuntu on it but anything Linux will do (not sure the FEX tools needed are available for Windows).
4. The SD card has two partitions on it; one 512 MB (system) and another larger one (OE data). Mount both on your system; on mine they show up under /media/<username>/<id>.
5. Open your lircd.conf file at /media/<username>/<id of larger partition>/.config. This is an excerpt of mime:

  1. begin remote

  2.   name  /storage/.config/lircd.conf
  3.   bits           16
  4.   flags SPACE_ENC|CONST_LENGTH
  5.   eps            30
  6.   aeps          100

  7.   header       9032  4520
  8.   one           546  1709
  9.   zero          546   583
  10.   ptrail        546
  11.   repeat       9032  2266
  12.   pre_data_bits   16
  13.   pre_data       0x205D
  14.   gap          141638
  15.   toggle_bit_mask 0x0

  16.       begin codes
  17.           KEY_SLEEP                0x38C7
Copy the Code

6. It was reported that the ARISC firmware only recognizes NEC encoding from the remote. Assuming that, you must generate the correct values, as expressed in NEC encoding, to put on the script.bin file so that the POWER key can be decoded by the ARISC processor built-in to the H3. A NEC-encoded button press has the following format:

  • a 9ms leading pulse burst (16 times the pulse burst length used for a logical data bit)
  • a 4.5ms space
  • the 8-bit address for the receiving device (A1)
  • the 8-bit logical inverse of the address (A2)
  • the 8-bit command (B1)
  • the 8-bit logical inverse of the command (B2)
  • a final 562.5µs pulse burst to signify the end of message transmission.

  • Logical '0' – a 562.5µs pulse burst followed by a 562.5µs space, with a total transmit time of 1.125ms
  • Logical '1' – a 562.5µs pulse burst followed by a 1.6875ms space, with a total transmit time of 2.25ms

The values A2 and B2 should be the logical inversion (0->1, 1->0) of A1 and B1, respectively, but most remotes use both A1 and A2 to differentiate model and make.
7. Looking at the values on lircd.conf you may notice that the 'header', 'one' and 'zero' keys have values that approximately match the NEC encoding; 'header' is the 9ms leading pulse + the 4.5ms space and 'one' and 'zero' also match the symbols for 0 and 1. If that's the case the remote is compatible enough to the NEC encoding to use.
8. Now convert your 'script.bin' file to textual representation with this:

  1. bin2fex /media/<username>/<id of 512MB partition>/script.bin ~/script.fex
Copy the Code

9. Open the 'script.fex' file and look for a line with '[s_cir0]'. Below it you'll find several pairs 'ir_power_key_code<order> = X' and 'ir_addr_code<order> = Y', being 'order' consecutive numbers starting from 0 and X/Y being the codes as seen by the ARISC firmware. But those codes are bit-reversed in regards to the lirc definitions. So Y is the same as 'pre_data' but bit-reversed' like this:

pre_data = 0x205D = 0010 0000 0101 1101 => (bit-reversed) => 1011 1010 0000 0100 = 0xBA04 = Y

Given that the key code is sent as a code and its logical inversion you'll notice that the code for the POWER key is composed of one byte (0x38) and its inverse (0xC7). So X should be the bit-reversal of the top 8 bits of the word like this:

KEY_SLEEP = 0x38C7 => code = 0x38 = 0011 1000 => (bit-reversed) => 0001 1100 = 0x1C = X

10. Add those codes to the [s_cir0] section, either by adding a new pair (make sure the order is consecutive and without duplicate numbers) or by just removing all existing pairs and adding this new one. I did it the second way and ended up with a section like this:

  1. [s_cir0]
  2. ir_used = 1
  3. ir_rx = port:PL11<2><1><default><default>
  4. ir_power_key_code0  = 0x1C
  5. ir_addr_code0       = 0xBA04
Copy the Code

11. Now convert the FEX file back using this:

  1. fex2bin ~/script.fex /media/<username>/<id of 512MB partition>/script.bin
Copy the Code

12. Un-mount the partitions, put the SD card back on the board and enjoy.

NOTE: If your lircd.conf file has the same values as mine on the 'bits' and  'pre_data_bits' you can follow the procedure above. If not you'll have to adapt it knowing that lirc records the bitstream frame from the remote like this:

<header> <plead> <pre_data> <pre> <data> <post> <post_data> <ptrail> <foot> <gap>

The default value (if missing from lircd.conf) for these keys is 0 and while 'pre_data' and 'post_data' are actual values from the bitstream the rest of the keys are durations in uS. As long as the values for 'header', 'one' and 'zero' are similar to mine it should be just question of finding out how to map the actual frame from the remote as detailed on lircd.conf into a NEC encoding as explained above.


0

Threads

19

Posts

425

Credits

Intermediate member

Rank: 3Rank: 3

Credits
425
Post time 2018-1-22 19:27:46 | Show all posts
Levitsky86 replied at 2018-1-19 01:22
Can someone answer me, please???

You read forum?
LibreElec 03/2017 - power off
LibreElec 02/2017 - suspend
OpenElec 02/2017 - suspend
use KEY_POWER
PS: yes, have problem with wi-fi(MT7601) after wake up, use wired LAN port - work correct after wake up.

4

Threads

1128

Posts

7382

Credits

Moderator

Rank: 7Rank: 7Rank: 7

Credits
7382
Post time 2017-1-10 05:14:37 | Show all posts
Your conversion is ok, except one slight detail. pre_data_bits is 16, which meanst you have to take into account 16 bit value not 8 bit.
Try with this conversion:
0x00BF => 0xFD00

  1. [s_cir0]
  2. ir_used = 1
  3. ir_power_key_code0  = 0x12
  4. ir_addr_code0       = 0xFD00
Copy the Code

4

Threads

1128

Posts

7382

Credits

Moderator

Rank: 7Rank: 7Rank: 7

Credits
7382
Post time 2016-10-20 13:26:56 | Show all posts
andreq replied at 2016-10-19 23:29
I'd be interested in knowning those other ways as I just installed everything on the build-in emmc ...

First make flash folder writable:
  1. mount -o remount,rw /flash
Copy the Code
and then copy script.bin with scp, for which you have to have ssh enabled. For example, on host PC for command line tool on Linux:
  1. scp script.bin root@192.168.0.10:/flash
Copy the Code
For Windows, there is graphical tool WinSCP.

4

Threads

1128

Posts

7382

Credits

Moderator

Rank: 7Rank: 7Rank: 7

Credits
7382
Post time 2016-10-15 18:23:24 | Show all posts
bir8339e,

although I didn't try your HOWTO yet, I'm glad that you figure it out. I spent quiet some time on this issue without any success. I will link your post in FAQ.

0

Threads

19

Posts

425

Credits

Intermediate member

Rank: 3Rank: 3

Credits
425
Post time 2016-10-15 21:24:08 | Show all posts
bir8339e,
Yes, this work, thank you.

3

Threads

165

Posts

1203

Credits

Gold member

Rank: 6Rank: 6

Credits
1203
Post time 2016-10-15 23:47:00 From the mobile phone | Show all posts
Thank you for the awesome guide. I'll try to check if I can get this working on Windows 10 with bash.

4

Threads

1128

Posts

7382

Credits

Moderator

Rank: 7Rank: 7Rank: 7

Credits
7382
Post time 2016-10-16 20:57:42 | Show all posts
I also confirm that it is working. Small addition: it is not required to set power button to "KEY_SLEEP", for me it also works set to "KEY_POWER".  fex2bin and bin2fex are now also inside OE, but there is no image yet released with those tools. It will be in next release.

13

Threads

199

Posts

791

Credits

Senior member

Rank: 4

Credits
791
Post time 2016-10-19 01:50:33 | Show all posts
Great news.
Reply

Use magic Report

0

Threads

19

Posts

345

Credits

Intermediate member

Rank: 3Rank: 3

Credits
345
Post time 2016-10-19 08:35:06 | Show all posts
What a good timing! I was digging online for any answer and didn't realize everything was lay right here on the forum .

Thanks, it worked after a couple of try as my pre_data was 0xFF  but actualy it's 0xFF00 which ended up being 65280 (decimal). I'm using a cheap A20 android box remote control, so I was able to fetch the script.bin in there and find out the needed power key and addr_code!

13

Threads

199

Posts

791

Credits

Senior member

Rank: 4

Credits
791
Post time 2016-10-20 00:14:56 | Show all posts
Edited by giaur500 at 2016-10-20 00:22

Not working for me. My pre_data from lircd.conf = 0x202, so:
  1. pre_data 0x202 = 000 0010 0000 0010 => bit_reversed 0100 0000 0100 0000 => 0x4040
Copy the Code


KEY_POWER is 0xB24D, so:
  1. KEY_POWER 0xB24D => code 0xB2 => 1011 0010 => bit_reversed 0100 1101 => 0x4D
Copy the Code
fex:
  1. [s_cir0]
  2. ir_used = 1
  3. ir_rx = port:PL11<2><1><default><default>
  4. ir_power_key_code0 = 0x4D
  5. ir_addr_code0 = 0x4040
Copy the Code


I converted it back to script.bin, replaced original file and nope, my device won't wake up on power key press. Also tried to change KEY_POWER to KEY_SLEEP, still not working. I have OrangePI PC. Any ideas? Should it be working on OrangePI PC?

4

Threads

1128

Posts

7382

Credits

Moderator

Rank: 7Rank: 7Rank: 7

Credits
7382
Post time 2016-10-20 00:24:03 | Show all posts
giaur500 replied at 2016-10-19 17:14
Not working for me. My pre_data from lircd.conf = 0x202, so:

Your math seems ok. Just one stupid question, did you reboot it first? Those settings are transfered to ARISC only at boot. Otherwise please post full lircd.conf.

13

Threads

199

Posts

791

Credits

Senior member

Rank: 4

Credits
791
Post time 2016-10-20 00:31:31 | Show all posts
Edited by giaur500 at 2016-10-20 00:37

What do you mean by reboot? It was booted after sd card inserted after replacing script.bin on PC. My lirc.conf:


  1. # Please make this file available to others
  2. # by sending it to <lirc@bartelmus.de>
  3. #
  4. # this config file was automatically generated
  5. # using lirc-0.9.1-git(default) on Sun Jun 12 13:38:31 2016
  6. #
  7. # contributed by
  8. #
  9. # brand:                       /storage/.config/lircd.conf
  10. # model no. of remote control:
  11. # devices being controlled by this remote:
  12. #

  13. begin remote

  14.   name  /storage/.config/lircd.conf
  15.   bits           16
  16.   flags SPACE_ENC
  17.   eps            30
  18.   aeps          100

  19.   header       8979  4495
  20.   one           555  1696
  21.   zero          555   571
  22.   ptrail        555
  23.   repeat       8980  2260
  24.   pre_data_bits   16
  25.   pre_data       0x202
  26.   gap          79385
  27.   repeat_gap   129096
  28.   toggle_bit_mask 0x0

  29.       begin codes
  30.           KEY_SLEEP                0xB24D
  31.           KEY_VOLUMEUP             0xA857
  32.           KEY_VOLUMEDOWN           0x38C7
  33.           KEY_MUTE                 0xC23D
  34.           KEY_E                    0xCA35
  35.           KEY_O                    0x58A7
  36.           KEY_LEFT                 0x08F7
  37.           KEY_UP                   0xD02F
  38.           KEY_RIGHT                0x8877
  39.           KEY_DOWN                 0x708F
  40.           KEY_ENTER                0xB04F
  41.           KEY_ESC                  0x42BD
  42.           KEY_I                    0xA25D
  43.           KEY_PREVIOUS             0x9A65
  44.           KEY_SPACE                0x1AE5
  45.           KEY_NEXT                 0xB847
  46.           KEY_STOP                 0x22DD
  47.           KEY_0                    0x00FF
  48.           KEY_1                    0x807F
  49.           KEY_BACKSPACE            0xC837
  50.           KEY_2                    0x40BF
  51.           KEY_3                    0xC03F
  52.           KEY_4                    0x20DF
  53.           KEY_5                    0xA05F
  54.           KEY_6                    0x609F
  55.           KEY_7                    0xE01F
  56.           KEY_8                    0x10EF
  57.           KEY_9                    0x906F
  58.       end codes

  59. end remote
Copy the Code

Also, to be sure I tried to decode back my new script.bin and I can see my new values are there (but provided in dec, not hex).
You have to log in before you can reply Login | Register

Points Rules

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

2019-8-22 04:44 GMT+8 , Processed in 0.110993 second(s), 33 queries .

Powered by Discuz! X3.2

© 2014-2015 orangepibbs en.

Quick Reply To Top Return to the list