-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclsFuncTimer.h
93 lines (70 loc) · 1.86 KB
/
clsFuncTimer.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
#if !defined(_CLS_FUNC_TIMER_H_)
#define _CLS_FUNC_TIMER_H_
#include "Arduino.h"
typedef void (*FuncaoTick)(void);
class clsFuncTimer
{
private:
bool _bAtivo = false;
long _lUltimoMillis = 0;
long _iIntervalo = 1000;
FuncaoTick _aFuncaoExterna = nullptr;
void _callExternalFunc(void);
public:
clsFuncTimer(bool timerAtivo, unsigned int intervalo);
~clsFuncTimer();
void startTimer(void);
void stopTimer(void);
bool getTimerStatus(void);
unsigned int getInterval(void);
void setInterval(unsigned int aNewInterval);
void setFuncaoExterna(FuncaoTick aFuncao);
void clearFuncaoExterna(void);
void tick();
};
/*
Implementação da classe
=====================================================================
*/
clsFuncTimer::clsFuncTimer(bool timerAtivo, unsigned int intervalo)
{
this->_bAtivo = timerAtivo;
this->_iIntervalo = intervalo;
}
clsFuncTimer::~clsFuncTimer()
{
}
void clsFuncTimer::_callExternalFunc(){
if (this->_aFuncaoExterna != nullptr){
this->_aFuncaoExterna();
}
}
void clsFuncTimer::startTimer(void){
this->_bAtivo = true;
}
void clsFuncTimer::stopTimer(void){
this->_bAtivo = false;
}
bool clsFuncTimer::getTimerStatus(void){
return this->_bAtivo;
}
unsigned int clsFuncTimer::getInterval(void){
return this->_iIntervalo;
}
void clsFuncTimer::setInterval(unsigned int aNewInterval){
this->_iIntervalo = aNewInterval;
}
void clsFuncTimer::setFuncaoExterna(FuncaoTick aFuncao){
this->_aFuncaoExterna = aFuncao;
}
void clsFuncTimer::clearFuncaoExterna(void){
this->_aFuncaoExterna = nullptr;
}
void clsFuncTimer::tick(){
long duracao = millis() - this->_lUltimoMillis;
if ((this->_bAtivo) and (duracao >= this->_iIntervalo)){
this->_callExternalFunc();
this->_lUltimoMillis = millis();
}
}
#endif // _CLS_FUNC_TIMER_H_