diff --git a/include/mgos_timers.hpp b/include/mgos_timers.hpp index ba987b1b6..54b6a609a 100644 --- a/include/mgos_timers.hpp +++ b/include/mgos_timers.hpp @@ -38,9 +38,11 @@ class Timer { bool Reset(int msecs, int flags); - bool IsValid(); + bool IsValid() const; - private: + int GetMsecsLeft() const; + + protected: static void HandlerCB(void *arg); Handler handler_; diff --git a/src/mgos_timers.cpp b/src/mgos_timers.cpp index 692909b87..e947b19dc 100644 --- a/src/mgos_timers.cpp +++ b/src/mgos_timers.cpp @@ -51,10 +51,19 @@ bool Timer::Reset(int msecs, int flags) { return IsValid(); } -bool Timer::IsValid() { +bool Timer::IsValid() const { return (id_ != MGOS_INVALID_TIMER_ID); } +int Timer::GetMsecsLeft() const { + if (!IsValid()) return 0; + struct mgos_timer_info ti; + if (mgos_get_timer_info(id_, &ti)) { + return ti.msecs_left; + } + return 0; +} + // static void Timer::HandlerCB(void *arg) { auto *st = static_cast(arg);