How to call private function in attachInterrupt()

I have a working sketch that I want to split up in a state machine part and a separate class.

The class makes use of an external interrupt which, when triggered, calls a function using attachInterrupt(). I want that function to be private to the class, but I guess my syntax is wrong because the compiler says:

path/OpTh/OpTh.cpp: In member function 'void OpTh::measure_ot_period()':

path/OpTh/OpTh.cpp:79: error: argument of type 'void (OpTh::)()' does not match 'void (*)()'

Line 79 is the line where attachInterrupt is, see code below.

The relevant code looks like this:

In OpTh.h:

class OpTh {
   public:
      OpTh();
      void init();                // initialise timer and input pin
      void measure_ot_period();   // measure the signal period
   private:
      void _ISRsync();
};

And in OpTh.cpp:

void OpTh::measure_ot_period() {

   /* attach _ISR sync() to INT0, digital pin 2 */
   attachInterrupt(0, _ISRsync, RISING);

}


void OpTh::_ISRsync() {
   // do stuff
}

Can someone tell me what I'm doing wrong?

TIA,

Martijn

Because the attatchInterrupt is not a templated function, you can not call functions within a namespace.

I usually make the function public, and create a wrapper in global space in the sketch.

void myWrapper(){
  myObject.myFunction();
}

Now, use myWrapper with attatchInterrupt.

Hm, that means that attachInterrupt and all its associated functionality has to move from the class to the sketch. :-/

Have you tried declaring _ISRsync as a static method?

Ha, that does work. At least, it doesn't give compile errors :wink:
Thanks!