semf
softwaretimer.cpp
Go to the documentation of this file.
1
13
14namespace semf
15{
16SoftwareTimer::SoftwareTimer(uint32_t interval, bool start)
17: m_running(start),
18 m_interval(interval)
19{
20}
21
22SoftwareTimer::SoftwareTimer(app::TimeBase& timeBase, uint32_t interval, bool start)
23: m_running(start),
24 m_interval(interval)
25{
26 timeBase.add(*this);
27}
28
29void SoftwareTimer::setInterval(uint32_t interval)
30{
31 m_interval = interval;
32}
33
35{
36 return m_interval;
37}
38
40{
41 return m_counter;
42}
43
45{
46 m_counter = 0;
47}
48
50{
51 if (!m_running)
52 return;
53
54 ++m_counter;
55
56 if (m_counter >= m_interval)
57 {
58 SEMF_INFO("timeout");
59 timeout();
60 m_counter = 0;
61 }
62}
63
65{
66 SEMF_INFO("start");
67 m_running = true;
68}
69
71{
72 SEMF_INFO("stop");
73 m_running = false;
74}
75
77{
78 return m_running;
79}
80} /* namespace semf */
bool isRunning() const
Check if the timer is running.
SoftwareTimer(uint32_t interval=0, bool start=false)
Constructor using no timebase.
uint32_t interval() const
Get the timer interval.
uint32_t counterValue() const
Get the current counter value.
void setInterval(uint32_t interval)
Set the timer interval.
void tick() override
Counting the time. Must be called cyclically by a timer interrupt or similar.
void start() override
Start time counting.
void stop() override
void reset() override
A TimeBase is the bridge between e.g. a hardware timer (interrupt service routine) and TickReceiver o...
Definition: timebase.h:36
virtual void add(TickReceiver &tickReceiver)=0
Adds e.g. a timer to this timebase.
Signal timeout
Definition: timer.h:36
#define SEMF_INFO(...)
Definition: debug.h:41