Loading...
Searching...
No Matches
hrv_run.h File Reference

Turns the beat gaps the watch reports into heart rate variability, as RMSSD in ms. More...

#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  HrvRun
 One run of beats being added up. Start it with hrv_run_reset. More...

Macros

#define HRV_PPI_MIN_MS   300
 The shortest gap kept, a heart rate of 200.
#define HRV_PPI_MAX_MS   2000
 The longest gap kept, a heart rate of 30.
#define HRV_JUMP_PCT   20
 A gap further than this percent from the one before it is dropped.
#define HRV_QUIET_SEC   15
 A pause this long with no gap ends the run.
#define HRV_DIFFS_MIN   20
 Differences a run needs before its answer means anything.
#define HRV_DIFFS_FULL   60
 A run this long is finished, and the next gap starts a new one.
#define HRV_STALE_PERIODS   3
 A reading is stale once this many sample periods pass without a new one.
#define HRV_STALE_MIN_SEC   1800
 A reading is never stale sooner than this, however short the period.
#define HRV_HOLD_PERIOD_SEC   1
 The period asked for while a burst is measured, which keeps the sensor on.
#define HRV_HOLD_MAX_SEC   90
 The longest the sensor is held on for one burst.
#define HRV_SETTLE_GAPS   10
 Gaps left out at the start of each burst while the sensor settles, when a face sets none.
#define HRV_SETTLE_GAPS_MAX   20
 The most gaps a face can have left out, which still leaves a slow heart time for a run.

Functions

void hrv_run_reset (HrvRun *run)
 Empties a run, so the next gap starts it.
int hrv_run_push (HrvRun *run, uint16_t ppi_ms, uint32_t now_sec)
 Adds one gap from the watch.
bool hrv_run_quiet (const HrvRun *run, uint32_t now_sec)
 Whether a run has gone quiet, so it is finished and waiting to be read.
int hrv_run_finish (HrvRun *run)
 Ends a run and empties it. How many differences it held stays in finished_diffs, so a caller can say how much of the burst went into the reading.
bool hrv_reading_stale (uint32_t measured_at, uint32_t now_sec, uint16_t period_sec)
 Whether a reading is too old to show.
bool hrv_should_ask (bool sampling, uint32_t gap_at, uint32_t asked_at, uint32_t now_sec, uint16_t period_sec)
 Whether to ask the watch for beat gaps again.
bool hrv_hold_over (uint32_t held_since, uint32_t now_sec)
 Whether the sensor has been held on for a burst as long as it may be.
uint8_t hrv_settle_gaps (uint16_t asked)
 How many gaps to leave out at the start of a burst, from the count a face asked for.

Detailed Description

Turns the beat gaps the watch reports into heart rate variability, as RMSSD in ms.

The watch hands over one gap between two heartbeats at a time. One gap is just the heart rate said another way, so the number worth showing is how much each gap differs from the one before it, taken over a run of clean beats. That is RMSSD, the square root of the mean of the squared differences. Plain C with no SDK, so its specs run on a PC.

Apps never see the sensor's own quality grade, so the rules for which beats count are here. A gap outside a heart rate of 30 to 200 is dropped, and so is one that jumps too far from the one before, which is what a missed or doubled beat looks like. A dropped gap also breaks the chain, so the next difference is only taken between the two good gaps after it, which really are neighbours.