luni64 / TeensyTimerTool

Generic Interface to Teensy Timers
MIT License
82 stars 18 forks source link

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

Open christophepersoz opened 8 months ago

christophepersoz commented 8 months ago

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

luni64 commented 8 months ago

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;
...
}
christophepersoz commented 8 months ago

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

Thanks a lot!