Need to call an uninstantiated method from object method

Hi,
I am using the PinChangeInt library to set up a number of interrupts for a (relatively) arbitrary number of rotary encoders on my Arduino Uno.

I am creating my own Encoder library, which relies on the PinChangeInt library.

I have a call in my Encoder library that looks like this:

void AdaEncoder::attachInterrupt(int pinA, int pinB) {
    PCintPort::attachInterrupt(pinA, encoderInterrupt, CHANGE);
}

Note the AdaEncoder::attachInterrupt() method, above, is not static. But the PCintPort::attachInterrupt() method is. I have a stub encoderInterrupt() method:

void encoderInterrupt() {}

The error I get is this:

/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp:65: error: no matching function for call to 'PCintPort::attachInterrupt(int&, <unresolved overloaded function type>, int)'
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/../PinChangeInt/PinChangeInt.h:87: note: candidates are: static void PCintPort::attachInterrupt(uint8_t, void (*)(), int)

I think what I have to do is make the encoderInterrupt() method static, but I'd like to avoid that. Is there any way I can do so? Or do I need to make encoderInterrupt() static, then solve my problem by utilizing static pointers or arrays?

Thanks.

I think what I have to do is make the encoderInterrupt() method static

Yes. C++ nonstatic member functions have a different function signature - they have an 'invisible' extra parameter, the 'this' pointer.

Page 5 of this has an example of the sort of thing you need to do (make a wrapper). You will need a static entry point, but that function can bounce to the handler specified for the individual object.

Thanks, that helps. But now I need to pass "this" as an argument to my function.

The function is specified in the PinChangeInt.h like this:

typedef void (*PCIntvoidFuncPtr)(void);

So I have tried to do this:

typedef void (*PCIntvoidFuncPtr)(void *);

So that I can do this in my Class:

PCintPort::attachInterrupt(pinA, interruptWrapper((void *) this), CHANGE);

but I get this error:

/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp: In member function 'void AdaEncoder::attachInterrupt(int, int)':
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp:68: error: invalid use of void expression

if I do:

PCintPort::attachInterrupt(pinA, &interruptWrapper((void *) this), CHANGE);

I get this:

/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp: In member function 'void AdaEncoder::attachInterrupt(int, int)':
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp:68: error: lvalue required as unary '&' operand

I can't figure out how to pass this through my static wrapper so as to open up the world of possibilities to me! I need it so that I know which object the interrupt applies to.

Thanks again.

I can't figure out how to pass this through my static wrapper so as to open up the world of possibilities to me! I need it so that I know which object the interrupt applies to.

You can't. Something external to the Arduino generated an interrupt. How is that external device supposed to know which object should react?

What you are trying to do makes little sense, as I understand what you are trying to do.

Perhaps if you explained just what you want to do, without code. Just the basic idea.