From 3d9322c7f32353d8880a9908b2ca90ad3faa1406 Mon Sep 17 00:00:00 2001 From: Carsten Keller Date: Sun, 9 Jun 2024 17:58:22 +0200 Subject: [PATCH] =?UTF-8?q?Software-Timer=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Timer.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ Source/Timer.hpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 Source/Timer.cpp create mode 100644 Source/Timer.hpp 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_ */