Software-Timer hinzugefügt
This commit is contained in:
parent
ecaaa18286
commit
3d9322c7f3
48
Source/Timer.cpp
Normal file
48
Source/Timer.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Timer.cpp
|
||||
*
|
||||
* Created on: Jun 7, 2024
|
||||
* Author: Carst
|
||||
*/
|
||||
|
||||
#include "Timer.hpp"
|
||||
namespace ElektronischeLast
|
||||
{
|
||||
Timer::Timer()
|
||||
{
|
||||
this->isRunning = false;
|
||||
}
|
||||
|
||||
void Timer::start(uint32_t durationMs)
|
||||
{
|
||||
this->timerValue = durationMs;
|
||||
this->isRunning = true;
|
||||
}
|
||||
|
||||
void Timer::stop(void)
|
||||
{
|
||||
this->isRunning = false;
|
||||
}
|
||||
|
||||
bool Timer::elapsed(void)
|
||||
{
|
||||
return !this->isRunning;
|
||||
}
|
||||
|
||||
void Timer::tick(void)
|
||||
{
|
||||
if (this->isRunning)
|
||||
{
|
||||
if (this->timerValue > 0)
|
||||
{
|
||||
this->timerValue--;
|
||||
}
|
||||
else
|
||||
{
|
||||
this-> isRunning = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
31
Source/Timer.hpp
Normal file
31
Source/Timer.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Timer.hpp
|
||||
*
|
||||
* Created on: Jun 7, 2024
|
||||
* Author: Carst
|
||||
*/
|
||||
|
||||
#ifndef TIMER_HPP_
|
||||
#define TIMER_HPP_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace ElektronischeLast
|
||||
{
|
||||
class Timer
|
||||
{
|
||||
private:
|
||||
volatile uint32_t timerValue;
|
||||
volatile bool isRunning;
|
||||
public:
|
||||
Timer();
|
||||
void start(uint32_t durationMs);
|
||||
void stop(void);
|
||||
bool elapsed(void);
|
||||
void tick(void);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* TIMER_HPP_ */
|
Loading…
x
Reference in New Issue
Block a user