utils.cpp 1.05 KB
Newer Older
Poseidon's avatar
Poseidon committed
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
#include "utils.h"

Polling::Polling(){
    this->period = 0;
}

Polling::Polling(int period){
    this->period = period;
}

bool Polling::test(){
    if(millis() - this->time_last  >= this->period)
        return true;
    else
        return false; 
}

void Polling::executed(){
    this->time_last = millis();
} 

void Polling::setPeriod(int period){
    this->period = period;
}

int Polling::getPeriod(){
    return this->period;
}



Interface::Interface(void (*callback)(void), int period){
    this->callback = callback;
    this->state = true;
    this->_interval.setPeriod(period);
    this->_interval.executed();
}

bool Interface::running(){
    return this->state;
}

void Interface::setState(){
    this->state = !this->state;
}

void Interface::run(){
    if(this->state == true){
        if(this->_interval.test()){
            this->callback();
            this->_interval.executed();
        }
    }
}

void Interface::setPeriod(int period){
    this->_interval.setPeriod(period);
}

int Interface::getPeriod(){
    return this->_interval.getPeriod();
}