TDuino
Convenient functionality for Arduino
Public Member Functions | Protected Member Functions | Protected Attributes | Friends
TBase Class Reference

Base class for all classes in TDuino. More...

#include <TBase.h>

Public Member Functions

 TBase ()
 Constructor for class TBase. More...
 
virtual ~TBase ()
 Destructor for class TBase. More...
 
virtual void loop ()
 The loop method for TBase and all subclasses. More...
 

Protected Member Functions

virtual void defaults ()
 Method used to reset all class internal variables. More...
 

Protected Attributes

unsigned long loopMillis
 The value of millis() to be used within loop()
 

Friends

class TList
 

Detailed Description

Base class for all classes in TDuino.

Used as a base class for all classes in TDuino. If you want to extend TDuino with extra classes you should use TBase as a base class for your new classes.

TBase is only intended as a "common root" and cannot be instantiated.

A minimal, valid subclass of TBase class would look something like this:

// Header
TMyClass : public TBase
{
...
public:
virtual void loop();
};
// Source
void TMyClass::loop()
{
TBase::loop(); // Call loop of base class
// Your own loop code goes here and you should use the protected
// field "loopMillis" for timing.
}

Constructor & Destructor Documentation

◆ TBase()

TBase::TBase ( )

Constructor for class TBase.

Initializes private and protected fields.

◆ ~TBase()

TBase::~TBase ( )
virtual

Destructor for class TBase.

Does nothing else than implement a virtual destructor.

Member Function Documentation

◆ defaults()

void TBase::defaults ( )
protectedvirtual

Method used to reset all class internal variables.

Implemented to avoid inheritance issues when overriding constructors who needs to change the default values of their parent classes. Instead of overriding a constructor like this:

TMyClass::TMyClass() : TBase()
{
this->some_value = 0;
}

You should override defaults() and call it in your constructor like this:

TMyClass::defaults()
{
this->some_value = 0;
}
TMyClass::TMyClass()
{
}

Doing it this way will ensure that all class internal variables are initialized to their default values in the right order. It will also allow any child classes to modify the default values of their parents in the construction phase.

◆ loop()

void TBase::loop ( )
virtual

The loop method for TBase and all subclasses.

Updates loopMillis to the current value of millis()

Reimplemented in TTimeline, TTimer, TPinInput, TPinOutput, TButton, and TTimelineT< DATATYPE >.