-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLapTimer.cpp
58 lines (52 loc) · 1.1 KB
/
LapTimer.cpp
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
/*
* Chrono.cpp
*
* Created on: 10/lug/2014
* Author: Tongo
*/
#include "Arduino.h"
#include "LapTimer.h"
LapTimer::LapTimer() {
lapCounter = 0;
startLapTimestamp = 0;
finishLapTimestamp = 0;
bestLapTime = 0;
bestLapTimeDelay = 0;
previousLapTime = 0;
previousLapTimeDelay = 0;
}
int LapTimer::getLapNumber() {
return lapCounter;
}
long LapTimer::getCurrentLapTime() {
return millis() - startLapTimestamp;
}
void LapTimer::startTimer() {
startLapTimestamp = millis();
}
void LapTimer::stopTimer() {
finishLapTimestamp = millis();
}
void LapTimer::newLap() {
stopTimer();
long lapTime = finishLapTimestamp - startLapTimestamp;
// calculating delay
bestLapTimeDelay = lapTime - bestLapTime;
previousLapTimeDelay = lapTime - previousLapTime;
previousLapTime = lapTime;
if(lapTime < bestLapTime || bestLapTime == 0) {
bestLapTime = lapTime;
}
startTimer();
lapCounter ++;
}
void LapTimer::sector() { }
long LapTimer::getBestLapDelay() {
return bestLapTimeDelay;
}
long LapTimer::getLastLapDelay() {
return previousLapTimeDelay;
}
long LapTimer::getLastLapTime() {
return previousLapTime;
}