Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
Classes | Functions | Variables
lampda::component::time Namespace Reference

Handle the platform realtime functions. More...

Classes

struct  RealTime
 Store a real time reference. More...
 

Functions

bool set_real_time (const RealTime &realTime)
 Set the real time in the lamp, only valid until the next shutdown.
 
void clear_real_time ()
 Forget the real time set by set_real_time(), as after a shutdown. The real time functions then behave as if it was never set.
 
RealTime convert_to_real_time (const uint32_t time_s)
 Convert a platform time in seconds to a real time value.
 
RealTime get_real_time ()
 Return a real time value, only valid if it was set first.
 
uint32_t get_platform_time_from_target_time (const RealTime &time)
 Given a real time, return the expected platform time in seconds at wich it will be reached. This is the next occurrence of this day of the week and time, at most a week from now. If the given time is the current time, the current platform time is returned.
 
int8_t get_next_enabled_day (const uint8_t daysMask, const uint8_t hour, const uint8_t minutes, const uint8_t seconds)
 Among the days enabled in daysMask, return the one with the soonest next occurrence of the given time.
 

Variables

static constexpr uint32_t secondsPerMinutes = 60
 
static constexpr uint32_t MinutesPerHours = 60
 
static constexpr uint32_t hoursPerDays = 24
 
static constexpr uint32_t daysPerWeeks = 7
 
static constexpr uint32_t secondsPerHours = secondsPerMinutes * MinutesPerHours
 
static constexpr uint32_t secondsPerDays = secondsPerHours * hoursPerDays
 
static constexpr uint32_t secondsPerWeeks = secondsPerDays * daysPerWeeks
 

Detailed Description

Handle the platform realtime functions.

Function Documentation

◆ convert_to_real_time()

RealTime lampda::component::time::convert_to_real_time ( const uint32_t  time_s)

Convert a platform time in seconds to a real time value.

Returns
if the global time is unset, the function return an invalid time

◆ get_next_enabled_day()

int8_t lampda::component::time::get_next_enabled_day ( const uint8_t  daysMask,
const uint8_t  hour,
const uint8_t  minutes,
const uint8_t  seconds 
)

Among the days enabled in daysMask, return the one with the soonest next occurrence of the given time.

Parameters
[in]daysMaskbit i enables the day of the week i (bit 0 is monday). Bits above 6 are ignored.
[in]hour,minutes,secondsThe target time of the day
Returns
The day of the week [0; 6], or -1 if no day is enabled. If the real time is unset, return the first enabled day.

◆ get_platform_time_from_target_time()

uint32_t lampda::component::time::get_platform_time_from_target_time ( const RealTime &  time)

Given a real time, return the expected platform time in seconds at wich it will be reached. This is the next occurrence of this day of the week and time, at most a week from now. If the given time is the current time, the current platform time is returned.

Warning
The returned time in seconds is only valid if the real time was set before.
The returned time could be greater than the maximum platform time.
Returns
if the global time is unset, the function return 0