Method reference

The current IRremote libraries require modifications to the library code, when only a specific receiver protocol shall be used. The bottleneck is the decode() method, that tries all decoders which are not disabled by modified #defines. This requires that the user moves the library to his private library folder, with one copy for each configuration.

That’s why I want to make the IRrecv class configurable in user code. In a first step I moved the problematic decode() method into a derived IRRecvAll class, so that not all decoders are linked to a sketch when the base library IRrecv is used, and made all decodeXXX methods public. Similar classes could be derived for specific decoders, e.g. class IRrecvNEC for use with the NEC protocol.

In the next step I want to add a method reference to the base class, that allows the user to specify a specific decode method. What’s the C++ syntax for such a field?

Together with some more (simple) modifications the new class shall be usable like this:

#include <IRreceive.h>

IRreceive irrecv(IR_PIN);

void setup() {

void loop() {
  if (irrecv.available) {
    irvalue =;
    ... //process irvalue

How do I implement such a reference field to a specific method, and use it in begin() and available()?

What you describe cries out for adding an IRdecoder class. The most important method being a virtual named decode.

The IRremote stuff would work through a chain (think "linked list") of IRdecoder instances when there is something to decode.

Sorry, what you describe is just the approach in current IRremote libraries, which results in a waste of flash memory and decoding time. Adding dedicated classes were one solution, of course, but I want to implement some simpler approach.

Most applications will be bound to one specific remote control, so that only this specific protocol should be accepted and decoded. This is configurable in the libraries, but at the cost described above. Please don't try to change my mind, I only look for the right syntax for the implementation of my library model.

DrDiettrich: Please don't try to change my mind, I only look for the right syntax for the implementation of my library model.

Okay, I will obey. But how would you select multiple protocols using this method? You might want to use two remotes, or one "universal" remote that sends multiple protocols.

Also, your implementation looks like a run time method. How could you then guarantee the flash saving that you mentioned (conditional compilation)?

I'm willing to answer all your questions, once I got the answer to my question.

Now I could make the modified library work :-)

It allows to use the standard methods begin(), available() and read() instead of all that strange stuff before. In begin() the user specifies the decoder to use, whereupon only that decoder is added to the program, without any further modification to the library.

The original interface is usable as well, so that multiple remote controls can be used at the same time, if somebody really needs such a feature. For that purpose I added a class IRrecvAll, but I'm not sure whether this was a good idea. Should I preserve the old class name, and instead rename the single-decoder (base) class into IRrcv?