/
TTimelineT.h
114 lines (98 loc) · 3.39 KB
/
TTimelineT.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
Copyright © 2018 - Torben Bruchhaus
TDuino.bruchhaus.dk - github.com/bswebdk/TDuino
File: TTimelineT.h
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef TTIMELINET_H
#define TTIMELINET_H
#include "TTimeline.h"
/**
* \brief 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.
*
* \code
* void TimelineCallback(byte slot, <DATATYPE> value)
* {
* // "slot" is the index of the slot in the time line.
* // value is mapped progress in the wanted data type.
* }
*
* TTimelineT<byte> tline(TimelineCallback, 2); //Two slots
*
* //Set the mapped value to be between 0 and 255
* tline.setMinMax(0, 255);
*
* //Set first slot to start after 5 seconds with a duration of 1 second
* tline.set(0, 1000, 5000);
*
* //Set the second slot to start after 10 seconds with a duration of 5 seconds
* tline.set(1, 5000, 10000);
* \endcode
*
* \see TTimeline
*/
template <class DATATYPE> class TTimelineT : public TTimeline
{
private:
void (*callback)(byte, DATATYPE);
DATATYPE mapMin, mapMax;
public:
/**
* \brief The constructor for a TTimelineT.
*
* See \ref TTimeline::TTimeline for more information.
*/
TTimelineT(void(*callback)(byte, DATATYPE), byte numSlots = 1);
using TTimeline::firstActive;
using TTimeline::firstInactive;
using TTimeline::getSize;
using TTimeline::hasOverlap;
using TTimeline::isActive;
using TTimeline::isStarted;
using TTimeline::restart;
using TTimeline::restartAll;
/**
* \brief Set the minimum and maximum values for progress.
* \param minValue The minimum progress value.
* \param 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 setMinMax(DATATYPE minValue, DATATYPE maxValue);
using TTimeline::set;
using TTimeline::stop;
using TTimeline::stopAll;
/**
* \brief The TTimelineT's loop phase.
*
* Must be called for each loop in the sketch.
*
* \see TTimeline::loop()
*/
virtual void loop();
};
#endif //TTIMELINET_H