Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions include/mgos_timers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
11 changes: 10 additions & 1 deletion src/mgos_timers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Timer *>(arg);
Expand Down