-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.cpp
77 lines (67 loc) · 1.24 KB
/
timer.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "timer.h"
void Timer::startTimer()
{
qtimer.start();
state = STATE_RUNNING;
}
void Timer::stopTimer()
{
time.time = qtimer.elapsed();
state = STATE_FINAL;
qtimer.invalidate();
}
void Timer::startInspection()
{
state = STATE_INSPECTING;
qtimer.start();
}
void Timer::stopInspection()
{
state = STATE_STOPPED;
qtimer.invalidate();
time.time = 0;
}
void Timer::setInspection(int i)
{
if(i >= 0)
inspection = i;
}
void Timer::reset()
{
qtimer.invalidate();
state = STATE_INITIAL;
time.time = 0;
}
TimeState Timer::getState()
{
return state;
}
TimeC Timer::getTime()
{
time.state = state;
switch(state)
{
case STATE_INITIAL:
time.state = STATE_INITIAL;
time.time = 0;
break;
case STATE_INSPECTING:
if(inspection * 1000 > qtimer.elapsed())
{
time.state = STATE_INSPECTING;
time.time = inspection - (qtimer.elapsed() / 1000);
}
else
{
stopInspection();
startTimer();
return getTime();
}
break;
case STATE_RUNNING:
time.state = STATE_RUNNING;
time.time = qtimer.elapsed();
break;
}
return time;
}