I'm not sure if they are same. Question is, how to write handler function outside of the class that would work with thesse attachInterrupt() functions?
It's probably not going to be lost forever, unless something silly happens. But the shared_ptr might be cached inside some library data structure for an unknown length of time.
For platform I am using (Arduino IDE) std::make_shared<>() doesn't work. This is what I tried to do
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <HardwareTimer.h>
HardwareTimer T1(TIM1);
void handler(void){/*do something*/}
void setup(){
T1.pause(); // Disable all microcontroler's counters
// Set timer1 to run handler function every 100ms
T1.setOverflow(10, HERTZ_FORMAT);
T1.attachInterrupt(channel, handler); // here I have an error
T1.resume(); // Resume all counters
}
and my error message looks like this:
invalid conversion from 'void (*)()' to 'void (*)(HardwareTimer*)' [-fpermissive]
I suspect handler function to be in different form because handler function should be of type "std::function<void(void)>". I do not quite understand this type. Can anybody explain it to me? And how I can implement my handler function correctly?