The health store's heart rate graph: the last hour of heart rate, a reading a minute, saved to flash so a relaunch shows it straight away. A face turns it on with HEALTH_HR_HISTORY, 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_persist.h"
#include "health/minute_window.h"
#include <stdlib.h>
#include <string.h>
#include <time.h>
|
| static void | read_hr_history (time_t now_min) |
| | Fill the empty minutes of the heart rate window from the watch's own minute log.
|
| static void | persist_save (void) |
| | Stash the heart rate graph so a relaunch can restore it.
|
| static void | hr_history_advance (time_t now_min) |
| | Slide the rolling heart rate window forward to now_min, zeroing any minutes that passed with no reading. The last slot always holds the current minute, so the chart reads oldest on the left and newest on the right.
|
| static void | hr_history_start (const HealthConfig *cfg, const HealthSeed *seed) |
| | Empties the window, then takes the seed, or restores the saved window and fills the time away from the log for a live store.
|
| static void | hr_history_heart_rate (int hr, bool from_event) |
| | Slides the window to now and puts a new reading in its last slot.
|
| static uint32_t | hr_history_sum (void) |
| | The window summed, so the store can tell when it moved.
|
|
const uint8_t * | health_store_hr_history (void) |
| | The last hour of heart rate readings, one per minute (a 60 slot buffer), for a face that named HEALTH_HR_HISTORY. The little charts read it back out. Empty for a face that did not.
|
|
|
static struct | s_window |
| | The rolling window and the minute its last slot holds.
|
|
static bool | s_live |
| | True for a live store, so seed mode never writes to flash.
|
|
static uint32_t | s_persist_key |
| | The persist slot the face handed us for the saved window.
|
| const HealthPart | health_part_hr_history |
| | The last hour of heart rate. Name it as HEALTH_HR_HISTORY.
|
The health store's heart rate graph: the last hour of heart rate, a reading a minute, saved to flash so a relaunch shows it straight away. A face turns it on with HEALTH_HR_HISTORY, and one that never names it carries none of this.
◆ HR_HISTORY_MINUTES
| #define HR_HISTORY_MINUTES 60 |
How many minutes of heart rate the graph shows.
It has nothing to do with an hour having 60 minutes, even though it lands on the same number.
◆ hr_history_advance()
| void hr_history_advance |
( |
time_t | now_min | ) |
|
|
static |
Slide the rolling heart rate window forward to now_min, zeroing any minutes that passed with no reading. The last slot always holds the current minute, so the chart reads oldest on the left and newest on the right.
- Parameters
-
| now_min | The current wall-clock minute (time / SECONDS_PER_MINUTE). |
◆ hr_history_heart_rate()
| void hr_history_heart_rate |
( |
int | hr, |
|
|
bool | from_event ) |
|
static |
Slides the window to now and puts a new reading in its last slot.
The chart reads from this window rather than the minute history: the watch only logs a per-minute heart_rate_bpm now and then in the background, so the minute history is mostly empty, while peeking the live value on each event fills the window with real readings.
- Parameters
-
| hr | The reading in beats per minute, or -1 for none. |
| from_event | Unused, since a peek is as good as an event for the graph. |
◆ hr_history_start()
Empties the window, then takes the seed, or restores the saved window and fills the time away from the log for a live store.
- Parameters
-
| cfg | The store's rules. |
| seed | The store's seed, or NULL. |
◆ hr_history_sum()
| uint32_t hr_history_sum |
( |
void | | ) |
|
|
static |
The window summed, so the store can tell when it moved.
- Returns
- The sum.
◆ persist_save()
| void persist_save |
( |
void | | ) |
|
|
static |
Stash the heart rate graph so a relaunch can restore it.
Only a live face writes, so seed mode never touches storage. A burst can land a reading a second and a flash write blocks, so the saves are held to one a minute, which is all the graph gains anyway.
One a minute is the rate to keep, not one to trim. The save runs from whichever comes first in a new minute, the face's cadence turn or a health event that refreshes the heart rate. Either way the CPU is already awake for it, so no extra wake is spent. The face is closed whenever the wearer opens a watchapp, even for a moment, and a graph saved less often comes back missing its last minutes every time.
◆ read_hr_history()
| void read_hr_history |
( |
time_t | now_min | ) |
|
|
static |
Fill the empty minutes of the heart rate window from the watch's own minute log.
Used at launch, on an empty window or on a restored one slid forward over the time the face was away, so the minutes spent in a watchapp show what the watch logged. A minute that already holds a reading keeps it, since the live readings can be more frequent than the log. Each reading lands in the slot for its own minute.
- Parameters
-
| now_min | The minute the window's last slot holds, the same one the live readings write. |