TeensyTimerTool icon indicating copy to clipboard operation
TeensyTimerTool copied to clipboard

Blinker.h - How to Encapsulate a Timer and its Callback in a Class / How to choose the right timer?

Open christophepersoz opened this issue 2 years ago • 2 comments

Hi Luna,

Thanks for your TeensyTimerTool, this is a super library.

I was reading your callback examples and discovered the part where you are encapsulating and use this library in an another class, Blinker.h as an example. Is that possible to specify in a such use the kind of timer you want to use for each blinker? (TCK, TCK_RTC, and so...).

Thanks a lot, Christophe

christophepersoz avatar Feb 01 '24 21:02 christophepersoz

To call the constructor of a variable that is a member of a class, pass the constructor parameters in the member initialization list. For example, if you want to use the GPT1 module, it would look like this

class Blinker
{
 public:
    Blinker(unsigned _pin, unsigned _period) // add blink period to the constructor
        : timer(GPT1) //<<====
    {
        pin    = _pin;
        period = _period;
    }`
...
protected:
    PeriodicTimer timer;
...
}

luni64 avatar Feb 02 '24 07:02 luni64

Hi Luna, Thanks a lot. I dis found that much later yesterday.

Thanks a lot!

christophepersoz avatar Feb 02 '24 07:02 christophepersoz