Software-Timer hinzugefügt

This commit is contained in:
Carsten Keller 2024-06-09 17:58:22 +02:00
parent ecaaa18286
commit 3d9322c7f3
Signed by: carsten
GPG Key ID: DF06343A3A9B8868
2 changed files with 79 additions and 0 deletions

48
Source/Timer.cpp Normal file
View 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
View 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_ */