Loading...
Searching...
No Matches
time_store.c File Reference

The active time store: holds the current time and owns the tickers that update it. More...

#include "io/stores/time_store.h"
#include "io/stores/store_cadence.h"
#include <time.h>
#include "system/units/units.h"

Functions

static void tick_handler (struct tm *tick_time, TimeUnits units_changed)
 Minute or hour tick handler: feed the tick straight in.
static void set (const struct tm *t)
 Save the new time and tell whoever is listening.
static void beats_fire (void *data)
 .beats ticker: refresh the time and re-arm for the next beat boundary.
static void start_ticker (void)
 Run the tickers the config asks for. The minute tick and the .beats timer are independent, so a face can have either or both (a clock and .beats can run together). With the minute tick off, hourly subscribes the hour tick instead.
static void stop_ticker (void)
 Stop both tickers (seed mode / teardown).
void time_store_subscribe (void(*cb)(void))
 Hand it the function to call when the time changes (the screen redraw).
void time_store_init (TimeConfig cfg, const struct tm *seed)
 Start the store with its rules. Pass seed = NULL to start from the current time.
void time_store_reconfigure (TimeConfig cfg)
 Re-apply the rules (e.g. the time format changed). Swaps the ticker to match.
const struct tm * time_store_tm (void)
 The time we hold right now.

Variables

static struct tm s_tm
 The current time, as of the last tick.
static void(*) s_cb (void)
 Called whenever the time moves, so the face can redraw.
static AppTimer * s_beats_timer
 The .beats ticker. NULL when it isn't running.
static bool s_minute
 Whether the minute tick is on.
static bool s_beats
 Whether the .beats timer is on.
static bool s_hourly
 Whether to wake on the hour when the minute tick is off.

Detailed Description

The active time store: holds the current time and owns the tickers that update it.

Function Documentation

◆ beats_fire()

void beats_fire ( void * data)
static

.beats ticker: refresh the time and re-arm for the next beat boundary.

Parameters
dataThe timer context (unused).

◆ set()

void set ( const struct tm * t)
static

Save the new time and tell whoever is listening.

Parameters
tThe new time.

◆ tick_handler()

void tick_handler ( struct tm * tick_time,
TimeUnits units_changed )
static

Minute or hour tick handler: feed the tick straight in.

Parameters
tick_timeThe new time.
units_changedWhich units changed (unused, the store always takes the whole tick).