Loading...
Searching...
No Matches
hrv_run.h
Go to the documentation of this file.
1
18#pragma once
19#include <stdbool.h>
20#include <stdint.h>
21
26
27#define HRV_PPI_MIN_MS 300
28#define HRV_PPI_MAX_MS 2000
29#define HRV_JUMP_PCT 20
30#define HRV_QUIET_SEC 15
31#define HRV_DIFFS_MIN 20
32#define HRV_DIFFS_FULL 60
33#define HRV_STALE_PERIODS 3
34#define HRV_STALE_MIN_SEC 1800
35#define HRV_HOLD_PERIOD_SEC 1
36#define HRV_HOLD_MAX_SEC 90
37#define HRV_SETTLE_GAPS 10
38#define HRV_SETTLE_GAPS_MAX 20
39
43typedef struct
44{
45 uint16_t last_ms;
46 uint16_t diffs;
47 uint32_t sum_sq;
48 uint32_t last_at;
49 uint16_t finished_diffs;
50} HrvRun;
51
57void hrv_run_reset(HrvRun *run);
58
71int hrv_run_push(HrvRun *run, uint16_t ppi_ms, uint32_t now_sec);
72
83bool hrv_run_quiet(const HrvRun *run, uint32_t now_sec);
84
92int hrv_run_finish(HrvRun *run);
93
105bool hrv_reading_stale(uint32_t measured_at, uint32_t now_sec, uint16_t period_sec);
106
121bool hrv_should_ask(bool sampling, uint32_t gap_at, uint32_t asked_at, uint32_t now_sec, uint16_t period_sec);
122
134bool hrv_hold_over(uint32_t held_since, uint32_t now_sec);
135
145uint8_t hrv_settle_gaps(uint16_t asked);
146
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.
Definition hrv_run.c:159
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 ...
Definition hrv_run.c:52
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.
Definition hrv_run.c:173
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.
Definition hrv_run.c:78
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.
Definition hrv_run.c:152
bool hrv_reading_stale(uint32_t measured_at, uint32_t now_sec, uint16_t period_sec)
Whether a reading is too old to show.
Definition hrv_run.c:140
void hrv_run_reset(HrvRun *run)
Empties a run, so the next gap starts it.
Definition hrv_run.c:47
int hrv_run_push(HrvRun *run, uint16_t ppi_ms, uint32_t now_sec)
Adds one gap from the watch.
Definition hrv_run.c:85
One run of beats being added up. Start it with hrv_run_reset.
Definition hrv_run.h:44
uint32_t sum_sq
The squared differences added up.
Definition hrv_run.h:47
uint16_t last_ms
The gap before, or 0 when the next gap starts the chain over.
Definition hrv_run.h:45
uint16_t diffs
How many differences are summed.
Definition hrv_run.h:46
uint16_t finished_diffs
How many differences the last finished run held, kept across the reset.
Definition hrv_run.h:49
uint32_t last_at
When the last gap arrived, in seconds, or 0 before the first.
Definition hrv_run.h:48