Newer
Older
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
#include "clock.h"
#include "asservissement/odometrie.h"
#include "asservissement/asservissement.h"
#include "hardware/tourelle.h"
#include "hardware/leds.h"
void Clock::everyTick()
{
}
void Clock::every5ms()
{
#ifndef STM32F40_41xxx
Odometrie::odometrie->update();
Asservissement::asservissement->update();
Tourelle::getSingleton()->update();
//StrategieV2::update();
#endif
}
void Clock::everySecond()
{
Led::toggle(0);
}
Clock* Clock::getInstance()
{
static Clock* instance = 0;
if(instance == 0)
instance = new Clock();
return instance;
}
Clock::Clock()
{
m_tickCount = 0;
m_last5msTick = 0;
m_matchStartTime = 0;
m_matchStarted = false;
}
void Clock::tick()
{
++m_tickCount;
everyTick();
if((m_tickCount - m_last5msTick) * Clock::MS_PER_TICK > 5)
{
every5ms();
m_last5msTick = m_tickCount;
}
if((m_tickCount - m_last5msTick) * Clock::MS_PER_TICK > 1000)
{
everySecond();
m_last1sTick = m_tickCount;
}
}
unsigned long Clock::elapsedSinceStartup() const
{
return m_tickCount * Clock::MS_PER_TICK;
}
void Clock::matchStart()
{
if(isMatchStarted())
return;
m_matchStarted = true;
m_matchStartTime = m_tickCount;
}
unsigned long Clock::elapsedSinceMatchStart() const
{
if(isMatchStarted())
return (m_tickCount - m_matchStartTime) * Clock::MS_PER_TICK;
return 0;
}
bool Clock::isMatchStarted() const
{
return m_matchStarted;
}
bool Clock::hasMatchEnded() const
{
return isMatchStarted() && (elapsedSinceMatchStart() >= Clock::MATCH_DURATION_MS);
}
unsigned int Clock::delay(unsigned int duration)
{
unsigned int start = Clock::getInstance()->elapsedSinceStartup();
while(duration > (Clock::getInstance()->elapsedSinceStartup()-start));
return Clock::getInstance()->elapsedSinceStartup()-start;
}
extern "C" void SysTick_Handler()
{
Clock::getInstance()->tick();
}