Class TimeManager

Nested Relationships

Nested Types

Class Documentation

class TimeManager

The TimeManager is responsible for synchronizing the time to the NTP servers and keeping track of it offline if the WIFI connection was lost. Also manages alarms and timers.

Public Types

enum Weekdays

Definition of weekdays ids.

Values:

enumerator NONE
enumerator MONDAY
enumerator TUESDAY
enumerator WEDNESDAY
enumerator THURSDAY
enumerator FRIDAY
enumerator SATURDAY
enumerator SUNDAY
typedef void (*TimerCallBack)(void)

Timer callback function type which is called if a timer ticks or is elapsed or an alrm is triggered.

Public Functions

~TimeManager()

Destroy the Time Manager object.

bool init()

Initialize the time manager and synchronize to ntp for the first time.

Pre:

prerequisite is that WIFI is already up and running

Returns:

true if init was successful

void handle()

Handle any Time manager tasks that need to be handled outside of interrupts.

void disableTimer()

Disable the timer and deactivate the interrupt.

bool synchronize()

Synchronize the time with the NTP server.

TimeInfo getCurrentTime()

get the current time in a struct for displaying it on the clock

TimeInfo getRemainingTimerTime()

get the remaining time of the active timer

String getCurrentTimeString()

get the current time as a string

void setTimerDuration(TimeInfo newTimerDuration)

Set the duration for the Timer.

void startTimer()

Start the timer.

void stopTimer()

Stop the timer.

bool isInBetween(TimeInfo timeStart, TimeInfo timeStop)

Check if the current time is in a given time period.

Parameters:
  • timeStart – Start of the time period

  • timeStop – End of the time period

Returns:

true is returned if the current time is in between the two specified times

Returns:

false is returned if the current time is not in between the two specified times

TimeInfo addSeconds(TimeInfo time, uint16_t secondsToAdd)

Adds the specified amount of seconds to a given time.

Parameters:
  • time – Base time element

  • secondsToAdd – Seconds that should be added to the base time

Returns:

TimeInfo Time struct with the new time where the seconds were already added

void setTimerTickCallback(TimerCallBack callback)

Set the Timer Tick Callback function.

Parameters:

callback – Function which shall be called every time a timer ticks (once every second)

void setTimerDoneCallback(TimerCallBack callback)

Set the Timer Done Callback function.

Parameters:

callback – Function which shall be called once a timer has fired

void setAlarmTime(TimeInfo alarmTime, Weekdays activeDays)

Set the time at which an alarm shall be triggered.

Parameters:
  • alarmTime – Time of the alarm

  • activeDays – Weekdays on which the alarm shall be triggered

void setAlarmMode(bool active)

Set if the alarm is active or not.

Parameters:

active – set to true if the alarm is supposed to be active, set to false to deactivate

void setAlarmCallback(TimerCallBack callback)

Set the Alarm Callback function which is called once an alarm fired.

Parameters:

callback – Function to call if the alarm was triggered

bool isAlarmActive()

check if the alarm is active

Returns:

true if the alarm is active

Returns:

false if the alarm is deactivated

void clearAlarm()

Clear a currently triggered alarm without disabling it.

Public Static Functions

static TimeManager *getInstance()

Get the singelton instance ot the Time Manager.

struct TimeInfo

Saves a time in hours, minutes and seconds.

Public Members

uint8_t hours
uint8_t minutes
uint8_t seconds