nerves_time v0.4.0 NervesTime.RealTimeClock behaviour View Source

Behaviour for real-time clocks implementations.

Link to this section Summary

Types

Internal state of the hardware clock

Callbacks

Get the time from the clock

Initialize the clock

Set the clock

Clean up the clock state

Link to this section Types

Internal state of the hardware clock

Link to this section Callbacks

Link to this callback

get_time(state)

View Source
get_time(state()) :: {:ok, NaiveDateTime.t(), state()} | {:unset, state()}

Get the time from the clock

This is called after init/1 returns successfully to see if the system clock should be updated.

If the time isn't set, the implementation should return :unset. set_time/2 will be called when the time is known.

Link to this callback

init(args)

View Source
init(args :: any()) :: {:ok, state()} | {:error, reason :: any()}

Initialize the clock

This is called when nerves_time starts. If it fails, nerves_time won't call any of the other functions.

Link to this callback

set_time(state, arg2)

View Source
set_time(state(), NaiveDateTime.t()) :: state()

Set the clock

This is called if nerves_time determines that the implementation is out of sync with the true time and at regular intervals (usually 11 minutes) as updates come in from NTP.

If the time can't be set, the implementation can either wait to be called the next time or take some other action.

Link to this callback

terminate(state)

View Source
terminate(state()) :: :ok

Clean up the clock state

This is called when nerves_time terminates. It's not guaranteed to be called, but if it is, it should clean up or do any final operations on the RTC.