core/health/goal_latch.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * @file goal_latch.c | ||
| 3 | * @brief The goal-met latch, host-testable off-device. | ||
| 4 | * | ||
| 5 | * @ingroup lib_core | ||
| 6 | */ | ||
| 7 | #include "health/goal_latch.h" | ||
| 8 | |||
| 9 | 41 | uint8_t goal_latch_update(GoalLatch *latch, int day, const int readings[GOAL_LATCH_COUNT], | |
| 10 | const int targets[GOAL_LATCH_COUNT]) | ||
| 11 | { | ||
| 12 | // a new day, or the very first look, forgets yesterday's goals | ||
| 13 |
2/2✓ Branch 2 → 3 taken 20 times.
✓ Branch 2 → 4 taken 21 times.
|
41 | if (day != latch->day) |
| 14 | { | ||
| 15 | 20 | latch->below = 0; | |
| 16 | 20 | latch->met = 0; | |
| 17 | 20 | latch->day = day; | |
| 18 | } | ||
| 19 | |||
| 20 | 41 | uint8_t crossed = 0; | |
| 21 |
2/2✓ Branch 14 → 5 taken 164 times.
✓ Branch 14 → 15 taken 41 times.
|
205 | for (int goal = 0; goal < GOAL_LATCH_COUNT; goal++) |
| 22 | { | ||
| 23 | 164 | uint8_t bit = GOAL_LATCH_BIT(goal); | |
| 24 | |||
| 25 | // no goal, or no reading yet, so this goal waits | ||
| 26 | // a reading of 0 waits too, since the store reads a missing distance as 0 and every day | ||
| 27 | // passes through readings above 0 and below its goal before it meets it | ||
| 28 |
4/4✓ Branch 5 → 6 taken 162 times.
✓ Branch 5 → 7 taken 2 times.
✓ Branch 6 → 7 taken 17 times.
✓ Branch 6 → 8 taken 145 times.
|
164 | if (targets[goal] <= 0 || readings[goal] <= 0) |
| 29 | { | ||
| 30 | 19 | continue; | |
| 31 | } | ||
| 32 | |||
| 33 |
2/2✓ Branch 8 → 9 taken 117 times.
✓ Branch 8 → 10 taken 28 times.
|
145 | if (readings[goal] < targets[goal]) |
| 34 | { | ||
| 35 | 117 | latch->below |= bit; | |
| 36 | 117 | continue; | |
| 37 | } | ||
| 38 | |||
| 39 | // past the goal counts only after a reading below it today | ||
| 40 | // a reading already past it may be yesterday's total, which the store still holds for up to a | ||
| 41 | // minute after midnight, or a goal met before the face opened. neither should buzz | ||
| 42 |
4/4✓ Branch 10 → 11 taken 14 times.
✓ Branch 10 → 13 taken 14 times.
✓ Branch 11 → 12 taken 12 times.
✓ Branch 11 → 13 taken 2 times.
|
28 | if ((latch->below & bit) && !(latch->met & bit)) |
| 43 | { | ||
| 44 | 12 | latch->met |= bit; | |
| 45 | 12 | crossed |= bit; | |
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | 41 | return crossed; | |
| 50 | } | ||
| 51 |