diff --git a/Source/Timer.cpp b/Source/Timer.cpp new file mode 100644 index 0000000..48cb42a --- /dev/null +++ b/Source/Timer.cpp @@ -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; + } + } + } +} + + diff --git a/Source/Timer.hpp b/Source/Timer.hpp new file mode 100644 index 0000000..13634ba --- /dev/null +++ b/Source/Timer.hpp @@ -0,0 +1,31 @@ +/* + * Timer.hpp + * + * Created on: Jun 7, 2024 + * Author: Carst + */ + +#ifndef TIMER_HPP_ +#define TIMER_HPP_ + +#include + +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_ */