Go Down

Topic: Using DueTimer lib inside another class (Read 31 times) previous topic - next topic



I am trying to integrate the beautiful DueTimer library into my project, where I need to attach an interrupt to one of the timers, within the class I am trying to write. Particularly I need to set a timer with a callback to a (non-static) method of my class.

Unfortunately the structure of the DueTimer class is a bit different than those I am more familiar with, and as far as I understand, instances for all 9 timers are pre-set, so the usual ways of creating an instance within the class does not seem to be of any use here. No matter what I try I am getting errors...  I am pretty sure I am doing some newbie faults here.

I tried putting this in the .cpp on the class level:

Code: [Select]

Which results in the following errors:

Timer0' does not name a type
cannot declare member function 'void MyClass::testCallback()' to have static linkage [-fpermissive]
And if i put the above code in the construct of MyClass, the I get this error, among others:

no matching function for call to 'DueTimer::attachInterrupt(<unresolved overloaded function type>)'
So I guess if used in the construct, the scope of DueTimer is different, and if it is outside the class, it cannot use a non-static method as a callback. Am I right so far?
I also tried with passing pointers and references, also trying to make DueTimer methods "friends", but with no success.

Is there any solution for having the Timer0 call a non-static method of my class?

Many thanks in advance, folks.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131