AnaviTechnology / anavi-docs

Documents for all ANAVI open source hardware products
http://anavi.technology/
65 stars 35 forks source link

Sending and receiving IR data at the same time #31

Open CRogers opened 4 years ago

CRogers commented 4 years ago

First of - thanks for making the ANAVI Infrared hat - it's made it so easy to get into sending/receiving IR using a rpi zero!

By following the [ANAVI instructions for setting up transmitting with LIRC](), and then using the "using multiple devices" part of the LIRC docs, I have managed to get two instances of LIRC running, the normal one for sending on /dev/lirc0 and the new socket at /var/run/lirc/lircd-lirc1 for receiving on /dev/lirc1. They work when I use them at different times:

# Works! Sends IR signal to disable my hifi
$ irsend SEND_ONCE logitech_z906 POWER POWER
$ irw /var/run/lirc/lircd-lirc1
00000000e0e0a659 00 KEY_LEFT SAMSUNG_BN59-01178B
00000000e0e046b9 00 KEY_RIGHT SAMSUNG_BN59-01178B
00000000e0e006f9 00 KEY_UP SAMSUNG_BN59-01178B
00000000e0e006f9 01 KEY_UP SAMSUNG_BN59-01178B
00000000e0e08679 00 KEY_DOWN SAMSUNG_BN59-01178B
00000000e0e08679 01 KEY_DOWN SAMSUNG_BN59-01178B

However, something seems to go wrong when I try to receive and send at the the same time. If I run irw to receive in the background:

$ irw /var/run/lirc/lircd-lirc1 &
[1] 3111

And then try and send a command:

# Does nothing! Not recognised.
$ irsend SEND_ONCE logitech_z906 POWER POWER
# Also doesn't work
$ irsend SEND_ONCE SAMSUNG_BN59-01178B KEY_RIGHT KEY_RIGHT

However, if I then kill the background irw receiving process:

$ kill -15 %1
[1]+  Terminated              irw /var/run/lirc/lircd-lirc1

Sending works again!

# Works again!
$ irsend SEND_ONCE logitech_z906 POWER POWER

Weirdly enough, in this "broken" state of sending and receiving at the same time, the IR leds still flash (checked with my phone camera) and if you run mode2 in the background:

$ mode2 -d /dev/lirc1 & 
[2] 3121
Trying device: /dev/lirc1
Using device: /dev/lirc1

you get the pulse/space data:

space 14962268
space 2053667
pulse 114
space 14454
pulse 207

but nothing shows up from the irw process in the background (and my hifi/tv do not recognise the signals either).


I assume the two instances of lirc are interfering with each other somehow. The LIRC docs say you may need to have two kernel drivers with different names, if the driver can only handle one device at a time:

The only situation where the described procedure will not work is when you have two devices that both use a kernel driver that can only handle one device at once like e.g. lirc_serial, lirc_sir or lirc_parallel. Resolving this requires recompiling the kernel drivers with different names and device numbers. Lifting this limitation is one of the todo items for future releases.

I also found this wiki page about rebuilding a separate version of the backing driver for LIRC.

But both are referring to the lirc_serial driver that I can't find with lsmod, where as the phat uses the default driver.


Any idea what's going wrong?

leon-anavi commented 4 years ago

Hi @CRogers,

Thank you for the detailed report. Unfortunately, this is a very specific use case and I don't know the exact answer how to set it up properly.

Regarding the kernel drivers, please keep in mind that with the release of Raspberry Pi OS Buster gpio-ir and gpio-ir-tx replaced the old Linux kernel module lirc_rpi. Details are about the switch are explained here.

Have you tried contacting LIRC developers about the issue in your use case? Btw there is an open bug in the upstream of LIRC regarding the patches that we apply manually in our user's manual: https://sourceforge.net/p/lirc/tickets/359/

Best regards, Leon