Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
TimerService.cpp File Reference
#include "events/TimerService.h"
#include <cstdio>
#include "time/PicoTime.h"
#include "events/EventManager.h"
#include "framework/AppContext.h"
+ Include dependency graph for TimerService.cpp:

Go to the source code of this file.

Functions

static uint32_t toSeconds (const TimeOfDay &tod)
 
static uint32_t secondsUntilNextMatch (const TimeOfDay &tod, DaysOfWeek mask, time_t currentTime)
 

Function Documentation

◆ secondsUntilNextMatch()

static uint32_t secondsUntilNextMatch ( const TimeOfDay tod,
DaysOfWeek  mask,
time_t  currentTime 
)
static

Definition at line 65 of file TimerService.cpp.

66{
67 struct tm now;
68 localtime_r(&currentTime, &now);
69 uint8_t today = now.tm_wday;
70 uint32_t nowSec = toSeconds({(uint8_t)now.tm_hour, (uint8_t)now.tm_min, (uint8_t)now.tm_sec});
71 uint32_t targetSec = toSeconds(tod);
72
73 for (int offset = 0; offset < 7; ++offset)
74 {
75 uint8_t checkDay = (today + offset) % 7;
76 if (mask & (1 << checkDay))
77 {
78 if (offset == 0 && targetSec <= nowSec)
79 continue;
80 return offset * 86400 + ((offset == 0) ? (targetSec - nowSec) : (targetSec + 86400 - nowSec));
81 }
82 }
83
84 return 86400;
85}
static uint32_t toSeconds(const TimeOfDay &tod)

References toSeconds().

Referenced by TimerService::scheduleDailyAt(), and TimerService::scheduleDuration().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toSeconds()

static uint32_t toSeconds ( const TimeOfDay tod)
static

Definition at line 60 of file TimerService.cpp.

61{
62 return tod.hour * 3600 + tod.minute * 60 + tod.second;
63}
uint8_t hour
Definition TimeOfDay.h:23
uint8_t minute
Definition TimeOfDay.h:24
uint8_t second
Definition TimeOfDay.h:25

References TimeOfDay::hour, TimeOfDay::minute, and TimeOfDay::second.

Referenced by TimerService::scheduleDailyAt(), and secondsUntilNextMatch().

+ Here is the caller graph for this function: