TDuino
Convenient functionality for Arduino
|
Used to track actions on a virtual time line and map them to a value. More...
#include <TTimelineT.h>
Public Member Functions | |
TTimelineT (void(*callback)(byte, DATATYPE), byte numSlots=1) | |
The constructor for a TTimelineT. More... | |
void | setMinMax (DATATYPE minValue, DATATYPE maxValue) |
Set the minimum and maximum values for progress. More... | |
virtual void | loop () |
The TTimelineT's loop phase. More... | |
int | firstActive () |
Find index of the first active slot. More... | |
int | firstInactive () |
Find index of the first inactive slot. More... | |
byte | getSize () |
Get number of timeline slots. More... | |
char | hasOverlap (byte index1, byte index2, bool remove=false) |
Check if two slots has an overlap. More... | |
bool | isActive (byte index) |
Check if a slot is active. More... | |
bool | isStarted (byte index) |
Check if a slot is started. More... | |
void | restart (byte index) |
Used to restart a slot. More... | |
void | restartAll () |
Used to restart all slots. More... | |
void | set (byte index, unsigned long duration, unsigned long startAfter=0) |
Set a slot in the time line. More... | |
void | stop (byte index) |
Stop a slot. More... | |
void | stopAll () |
Stop all slots. More... | |
![]() | |
TTimeline (void(*callback)(byte, float), byte numSlots=1) | |
The constructor for a TTimeline. More... | |
~TTimeline () | |
The destuctor for a TTimeline. More... | |
int | firstActive () |
Find index of the first active slot. More... | |
int | firstInactive () |
Find index of the first inactive slot. More... | |
byte | getSize () |
Get number of timeline slots. More... | |
char | hasOverlap (byte index1, byte index2, bool remove=false) |
Check if two slots has an overlap. More... | |
bool | isActive (byte index) |
Check if a slot is active. More... | |
bool | isStarted (byte index) |
Check if a slot is started. More... | |
void | restart (byte index) |
Used to restart a slot. More... | |
void | restartAll () |
Used to restart all slots. More... | |
void | set (byte index, unsigned long duration, unsigned long startAfter=0) |
Set a slot in the time line. More... | |
void | stop (byte index) |
Stop a slot. More... | |
void | stopAll () |
Stop all slots. More... | |
![]() | |
TBase () | |
Constructor for class TBase. More... | |
virtual | ~TBase () |
Destructor for class TBase. More... | |
Additional Inherited Members | |
![]() | |
bool | badIndex (byte i, const char *token) |
void | checkMemError (const char *token) |
![]() | |
virtual void | defaults () |
Method used to reset all class internal variables. More... | |
![]() | |
const byte | numSlots = TDUINO_TIMELINE_SIZE |
TTIMELINE_SLOT | slots [TDUINO_TIMELINE_SIZE] |
byte | numSlots |
TTIMELINE_SLOT * | slots |
TTIMELINE_SLOT * | current |
byte | dummy |
byte | memError |
![]() | |
unsigned long | loopMillis |
The value of millis() to be used within loop() | |
Used to track actions on a virtual time line and map them to a value.
TTimelineT is usefull when you need to have sort of a virtual time line where different things are happening gradually in a period of time which can be postponed.
The difference between TTimeline and TTimelineT is that TTimelineT is a template class which allows you to map any progress to a certain data type. Since no floating point operations are used in TTimelineT it may in most cases be more efficient that the TTimeline class.
TTimelineT< DATATYPE >::TTimelineT | ( | void(*)(byte, DATATYPE) | callback, |
byte | numSlots = 1 |
||
) |
The constructor for a TTimelineT.
See TTimeline::TTimeline for more information.
int TTimeline::firstActive |
Find index of the first active slot.
If no slots are active, -1 will be returned.
int TTimeline::firstInactive |
Find index of the first inactive slot.
If no slots are inactive, -1 will be returned.
byte TTimeline::getSize |
Get number of timeline slots.
Used to get the number of timeline slots used with this instance of TTimeline.
char TTimeline::hasOverlap |
Check if two slots has an overlap.
index1 | The index of the first slot to check. |
index2 | The index of the second slot to check. |
remove | If true, the overlapping slot will be postponet until the overlap is removed. |
This method is used to examine wheter or not the actual transition of two slots are overlapping in a way that they may interfere with eachother. The overlapping slot is the slot that starts later and if both slots starts at the same time, the first slot will be returned.
In the example above, "ol" will be 2 because the second slot will start when the first slot is half done. Since "remove" is set to true, the second slot will be postponet with an additional 500 ms and this means that the code above will do exactely the same as the next example:
NOTE: By default hasOverlap() uses 32 bit integers for calculation and this will only work if the time line does not exceed ~24 days (or ~35 seconds if using micros() for timing) from start to end. This behaviour may be tweaked, read more about it in Tweaking TDuino.
bool TTimeline::isActive |
Check if a slot is active.
index | The index of the slot to check. |
Used to check if a slot is active or postponed (waiting to become active).
bool TTimeline::isStarted |
Check if a slot is started.
index | The index of the slot to check. |
Used to check if a slot is started (transition in progress).
|
virtual |
The TTimelineT's loop phase.
Must be called for each loop in the sketch.
Reimplemented from TTimeline.
void TTimeline::restart |
Used to restart a slot.
index | The index of the slot to restart. |
This method will restart the slot at index with the values previously set with set().
void TTimeline::restartAll |
Used to restart all slots.
This method will restart all slots in the time line.
void TTimeline::set |
Set a slot in the time line.
index | Index of the slot to set. |
duration | The duration of the slot. |
startAfter | The amount of time (milliseconds) to wait before starting the slot. |
Sets the slot at index to start after startAfter milliseconds with duration milliseconds. By default startAfter is set to 0, which means that the slot will start emmediately.
If duration is zero, the slot will act as a one-shot timer.
void TTimelineT< DATATYPE >::setMinMax | ( | DATATYPE | minValue, |
DATATYPE | maxValue | ||
) |
Set the minimum and maximum values for progress.
minValue | The minimum progress value. |
maxValue | The maximum progress. |
Must be called to set the range in which the progress should be mapped. The arguments must be within the template data types's boundaries, eg. a "byte" must use values between 0 and 255, a "int" must be between −32767 and 32767 and so on.
The default values for the mapping is 0..255 for single byte data types and 0..1023 for everything else.
void TTimeline::stop |
Stop a slot.
index | Index of the slot to stop. |
This will deactivate the slot at the specified index.
void TTimeline::stopAll |
Stop all slots.
This will deactivate all slots in the time line.