core/health/goals.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * @file goals.c | ||
| 3 | * @brief The daily goal tables, host-testable off-device. | ||
| 4 | * | ||
| 5 | * goal-rows.spec.ts reads these tables as text and checks them against the page's, so each one | ||
| 6 | * stays a plain list of numbers. | ||
| 7 | * | ||
| 8 | * @ingroup lib_core | ||
| 9 | */ | ||
| 10 | #include "health/goals.h" | ||
| 11 | |||
| 12 | /** @cond */ | ||
| 13 | #define GOALS_LENGTH(table) (sizeof(table) / sizeof((table)[0])) | ||
| 14 | /** @endcond */ | ||
| 15 | |||
| 16 | static const int16_t s_steps[] = {5000, 7500, 10000, 12500, 15000, 20000, 25000}; ///< step goals | ||
| 17 | static const int16_t s_distance_m[] = {2000, 3000, 5000, 8000, 10000, 15000, 20000}; ///< distance goals in metres, from the page's km | ||
| 18 | static const int16_t s_calories[] = {500, 1000, 1500, 2000, 2500, 3000}; ///< active calorie goals in kcal | ||
| 19 | static const int16_t s_active_min[] = {15, 30, 45, 60, 90}; ///< active minute goals | ||
| 20 | static const int16_t s_sleep_h[] = {6, 7, 8, 9, 10}; ///< sleep goals in hours | ||
| 21 | static const int16_t s_hr_limits[] = {150, 160, 170, 180, 190, 200}; ///< heart rate limits in bpm | ||
| 22 | |||
| 23 | // each count is what a KNOWN_GOAL_* entry holds the page to, so it has to be the table's real length | ||
| 24 | _Static_assert(GOALS_LENGTH(s_steps) == GOALS_STEPS_COUNT, "GOALS_STEPS_COUNT is not the step table's length"); | ||
| 25 | _Static_assert(GOALS_LENGTH(s_distance_m) == GOALS_DISTANCE_COUNT, "GOALS_DISTANCE_COUNT is not the distance table's length"); | ||
| 26 | _Static_assert(GOALS_LENGTH(s_calories) == GOALS_CALORIES_COUNT, "GOALS_CALORIES_COUNT is not the calorie table's length"); | ||
| 27 | _Static_assert(GOALS_LENGTH(s_active_min) == GOALS_ACTIVE_COUNT, "GOALS_ACTIVE_COUNT is not the active table's length"); | ||
| 28 | _Static_assert(GOALS_LENGTH(s_sleep_h) == GOALS_SLEEP_COUNT, "GOALS_SLEEP_COUNT is not the sleep table's length"); | ||
| 29 | _Static_assert(GOALS_LENGTH(s_hr_limits) == GOALS_HR_COUNT, "GOALS_HR_COUNT is not the heart rate table's length"); | ||
| 30 | |||
| 31 | /** | ||
| 32 | * @brief A table's entry for a menu choice, or its first entry for a choice past the end. | ||
| 33 | * | ||
| 34 | * @param table The goals, in menu order. | ||
| 35 | * @param count How many the table holds. | ||
| 36 | * @param index The saved choice. | ||
| 37 | * @return The goal. | ||
| 38 | */ | ||
| 39 | 2 | static int goal_at(const int16_t *table, uint8_t count, uint8_t index) | |
| 40 | { | ||
| 41 |
2/2✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 4 taken 1 time.
|
2 | return table[index < count ? index : 0]; |
| 42 | } | ||
| 43 | |||
| 44 | 1 | int goals_steps(uint8_t index) | |
| 45 | { | ||
| 46 | 1 | return goal_at(s_steps, GOALS_STEPS_COUNT, index); | |
| 47 | } | ||
| 48 | |||
| 49 | ✗ | int goals_distance_m(uint8_t index) | |
| 50 | { | ||
| 51 | ✗ | return goal_at(s_distance_m, GOALS_DISTANCE_COUNT, index); | |
| 52 | } | ||
| 53 | |||
| 54 | ✗ | int goals_calories(uint8_t index) | |
| 55 | { | ||
| 56 | ✗ | return goal_at(s_calories, GOALS_CALORIES_COUNT, index); | |
| 57 | } | ||
| 58 | |||
| 59 | ✗ | int goals_active_min(uint8_t index) | |
| 60 | { | ||
| 61 | ✗ | return goal_at(s_active_min, GOALS_ACTIVE_COUNT, index); | |
| 62 | } | ||
| 63 | |||
| 64 | 1 | int goals_sleep_min(uint8_t index) | |
| 65 | { | ||
| 66 | 1 | return goal_at(s_sleep_h, GOALS_SLEEP_COUNT, index) * 60; | |
| 67 | } | ||
| 68 | |||
| 69 | ✗ | int goals_hr_limit(uint8_t index) | |
| 70 | { | ||
| 71 | ✗ | return goal_at(s_hr_limits, GOALS_HR_COUNT, index); | |
| 72 | } | ||
| 73 |