Call functor with IntervalTimer

Status
Not open for further replies.

jdpeiffer

New member
Hi all,

I am really enjoying the teensy 4.0 using teensyduino and arduino 1.8.13.

I am looking to use IntervalTimer to call a functor. There may be some ways around this that I am currently exploring, but I am thinking simply changing the argument on lines 50, 56 etc of IntervalTimer.h to accept functors will be the easiest.

Any thoughts about how to put a template in the .h file so

Code:
bool begin(void (*funct)(), unsigned long microseconds) {
		return begin(funct, (unsigned int)microseconds);
	}


can be something like

Code:
bool begin(FunctorType functor, unsigned long microseconds) {
		return begin(funct, (unsigned int)microseconds);
	}

??
or pass functor as f-pointer?

Thanks,

JD
 
A couple of weeks ago I did IntervalTimerEx which is a very shallow wrapper around the stock IntervalTimer providing std::function<> callbacks. I.e., you can attach pretty much anything callable, including functors to it without changing the library function. See here: https://github.com/luni64/TeensyHelpers

Alternatively you can use the TeensyTimerTool which provides a generic interface to a couple of Teensy Hardware timers (PIT, GPT, TMR(aka QUAD), FTM) and 32/64bit software timers (TCK, TCK64). All of them can be used in periodic and one-shot mode and all of them accept std::function<> callbacks. https://github.com/luni64/TeensyTimerTool/wiki/Callbacks
 
Status
Not open for further replies.
Back
Top