From 0dedcc9f824283e3d41f50468cc40607ff4d5eec Mon Sep 17 00:00:00 2001 From: "@CarlWachter" Date: Sat, 1 Jun 2024 13:01:49 +0200 Subject: [PATCH] timer type as boolean --- include/sta/rtos/timer.hpp | 6 ++---- src/timer.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/sta/rtos/timer.hpp b/include/sta/rtos/timer.hpp index 644d6fe..70ba816 100644 --- a/include/sta/rtos/timer.hpp +++ b/include/sta/rtos/timer.hpp @@ -30,11 +30,9 @@ namespace sta * * @param callback The callback function to call upon timer timeout. * @param arg The argument to pass to the callback function. - * @param type The type of timer to create. The Options are: - * - osTimerOnce: One-shot timer. - * - osTimerPeriodic: Repeating timer. + * @param repeating True if the timer should repeat. False if it should only run once. */ - RtosTimer(std::function, void *arg, osTimerType_t type = osTimerOnce); + RtosTimer(std::function, void *arg, bool repeating = false); /** * @brief Initializes the timer with a callback that has no effect. diff --git a/src/timer.cpp b/src/timer.cpp index d372294..33ff80b 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -5,13 +5,15 @@ #include "cmsis_os2.h" namespace sta { - RtosTimer::RtosTimer(std::function callback, void *arg, osTimerType_t type /*= osTimerOnce */) + RtosTimer::RtosTimer(std::function callback, void *arg, bool repeating /*= false */) : timer_id_{NULL}, - timer_attr_{.name="Timer", .attr_bits=type}, + timer_attr_{.name="Timer", .attr_bits=repeating ? osTimerPeriodic : osTimerOnce}, callback_{callback}, callbackArg_{arg}, running_{false} { + osTimerType_t type = repeating ? osTimerPeriodic : osTimerOnce; + // Pass an anonymous function as the callback which will invoke the currently registered callback. timer_id_ = osTimerNew(timeoutHandler, type, this, &timer_attr_);