Go Down

Topic: Using an Interrupt from a method inside a class (Read 6458 times) previous topic - next topic

gfvalvo

For me the code compile without that bad change.
Bulldog's original code compiled for me too. I was just wondering if my use of casting:
(void (*)())(&fan2->handleInterrupt)
would function properly, not just compile without error.

Quote
There are some warnings...
The warnings depend on what processor I try to compile for. No warnings for Uno. Yes warning for Teensy. IDE 1.82.

Anyway, the warnings are just sprint() complaining. They're unrelated to Bulldog's technique for the interrupt attachment.
No technical questions via PM. They will be ignored. Post your questions in the forum so that all may learn.

Whandall

Bulldog's original code compiled for me too. I was just wondering if my use of casting:
(void (*)())(&fan2->handleInterrupt)
would function properly, not just compile without error.
The warnings depend on what processor I try to compile for. No warnings for Uno. Yes warning for Teensy. IDE 1.82.
No, your method can not work.

I got the warnings for a Mega.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

BulldogLowell


Whandall

Still errors (on 8-bit Arduinos). The second %d should print the high part of the first.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

septillion

Are there Arduino environments in which that matters?

Both variants compile (for a Mega and ESP32) without warnings.

The first notation will be at least legal for some years to come IMHO.
Might be, depends on the function you try to call.
have a look at https://www.cprogramming.com/c++11/c++11-nullptr-strongly-typed-enum-class.html

And its part of C++11 so it will be valid for a long long time as well :)
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

sdmetzger

Bulldog Lowell's answer #11 is still relevant today!   I stumbled on this while trying to encapsulate my stepper motor controller routines in a class for use on an ESP32.   I have found a lot of hackarounds and avoidance of the issue by doing the ISR callbacks outside a class because a member routine's address is kind-of tough to get to, but his solution did the trick.  Kudos.

Go Up