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

The health store's heart rate day: today's heart rate by the hour, filled from the watch's minute log at launch and from each reading after. A face turns it on with HEALTH_HR_DAY, and one that never names it carries none of this. More...

#include "io/stores/health_store.h"
#include "io/stores/health_store_parts.h"
#include "io/stores/store_sum.h"
#include <time.h>

Functions

static void hr_day_roll (void)
 Empties the hours once midnight has passed since they were filled.
static void add_record_hr (int hour, const HealthMinuteData *record, void *context)
 Adds a record's heart rate to its hour, for the read of the log.
static bool read_hr_day (void)
 Fills today's hours from the watch's minute log, from midnight up to the minute the store started.
static void hr_day_first_read (void *data)
 The first read of today's heart rate from the log, once the face is up.
static void hr_day_start (const HealthConfig *cfg, const HealthSeed *seed)
 Empties the day, then takes the seed, or queues the read of the log for a live store.
static void hr_day_heart_rate (int hr, bool from_event)
 Adds a new reading to its hour, at most one a minute.
static void hr_day_poll (void)
 Empties the day at midnight even with no reading to bring it, and tries again on a launch read that found no room.
static uint32_t hr_day_sum (void)
 The day summed, so the store can tell when it moved.
const HrDay * health_store_hr_day (void)
 Today's heart rate by the hour, for a face that named HEALTH_HR_DAY. Read each hour and the day's low, average, and high from it with the hr_day.h getters. Empty for a face that did not.

Variables

static HrDay s_day
 Today's heart rate by the hour.
const HealthPart health_part_hr_day
 Today's heart rate by the hour. Name it as HEALTH_HR_DAY.
Filling the day

The minute log fills the day up to the minute the store started, once the face has painted. Each reading after that is added as it arrives, so the two never count the same minute.

static time_t s_day_start
 The midnight the kept hours belong to.
static time_t s_from_min
 The minute the store started. The log fills before it, live readings from it on.
static time_t s_last_min
 The minute of the last live reading added, so a burst adds one a minute.
static bool s_pending
 True between a live start and its read of the log.

Detailed Description

The health store's heart rate day: today's heart rate by the hour, filled from the watch's minute log at launch and from each reading after. A face turns it on with HEALTH_HR_DAY, and one that never names it carries none of this.

Function Documentation

◆ hr_day_first_read()

void hr_day_first_read ( void * data)
static

The first read of today's heart rate from the log, once the face is up.

Parameters
dataThe timer context (unused).

◆ hr_day_heart_rate()

void hr_day_heart_rate ( int hr,
bool from_event )
static

Adds a new reading to its hour, at most one a minute.

Only a heart rate event brings a new reading. A peek on the cadence can hand back the same one for up to fifteen minutes, which would count it many times. While HRV holds the sensor on, a reading lands about once a second, and keeping one a minute weighs those minutes the same as the rest of the day, where the watch logs one now and then.

Parameters
hrThe reading in beats per minute, or -1 for none.
from_eventTrue when a heart rate event brought it.

◆ hr_day_start()

void hr_day_start ( const HealthConfig * cfg,
const HealthSeed * seed )
static

Empties the day, then takes the seed, or queues the read of the log for a live store.

Parameters
cfgThe store's rules.
seedThe store's seed, or NULL.

◆ hr_day_sum()

uint32_t hr_day_sum ( void )
static

The day summed, so the store can tell when it moved.

Returns
The sum.

◆ read_hr_day()

bool read_hr_day ( void )
static

Fills today's hours from the watch's minute log, from midnight up to the minute the store started.

The log holds a reading for each minute the sensor took one, the same as it holds the steps, so the hours before launch read the same as they would have live. It is a blocking scan of the log, so it runs once, after the face has painted.

Returns
False when there was no room for the records, so the read is still owed.