|
PebbleOS
|
Step counting, sleep tracking, activity sessions and health metrics. More...
Modules | |
| Activity algorithm interface | |
| Interface between the activity service and the step/sleep algorithm. | |
| Activity calculators | |
| Distance and calorie estimates from steps and the user profile. | |
| Activity insights | |
| Sleep and activity rewards, summary pins and session notifications. | |
| Activity service internals | |
| State, storage formats and helpers shared by the activity service sources. | |
| Health formatting helpers | |
| Formatting of durations, distances and paces for the health UI. | |
| Heart rate zones | |
| Heart rate zone classification using the user's heart rate preferences. | |
| Insights settings | |
| Tunable parameters of the activity insights. | |
| Kraepelin algorithm | |
| Step counting, sleep and activity session detection. | |
| Workout service | |
| Manually started and stopped activity sessions. | |
Data Structures | |
| struct | ActivitySettings |
| User profile and activity preferences, as stored in prefs. More... | |
| struct | HeartRatePreferences |
| Heart rate thresholds, in beats per minute, as stored in prefs. More... | |
| struct | ActivityHRMSettings |
| Heart rate monitor preferences, as stored in prefs. More... | |
| struct | ActivitySpO2Settings |
| Blood oxygen (SpO2) preferences, as stored in prefs. More... | |
| struct | ActivitySessionDataStepping |
| Data of step based sessions (walk, run, open workout). More... | |
| struct | ActivitySessionDataSleeping |
| Data of sleep sessions (currently none). More... | |
| struct | ActivitySession |
| A detected or manual activity session. More... | |
| struct | ActivityRawSamplesRecord |
| Data logging record of raw accelerometer sample collection. More... | |
| struct | ActivityMetricAverages |
| Typical steps for each 15 minute interval of a day. More... | |
| union | ActivitySession.__unnamed41__ |
| Session flags. More... | |
| struct | ActivitySession.__unnamed41__.__unnamed45__ |
| Individual flags. More... | |
| union | ActivitySession.__unnamed43__ |
| Type specific data. More... | |
Macros | |
| #define | ACTIVITY_HISTORY_DAYS 30 |
| Number of days of metric history kept, today included. | |
| #define | ACTIVITY_MAX_ACTIVITY_SESSIONS_COUNT 32 |
| Maximum number of activity sessions cached at a time. | |
| #define | ACTIVITY_CALORIES_PER_KCAL 1000 |
| Number of calories in a kilocalorie. | |
| #define | ACTIVITY_DEFAULT_HEIGHT_MM 1620 |
| Default user height, in millimeters (5'3.8", CDC average). | |
| #define | ACTIVITY_DEFAULT_WEIGHT_DAG 7539 |
| Default user weight, in decagrams (166.2 lbs, CDC average). | |
| #define | ACTIVITY_DEFAULT_GENDER ActivityGenderFemale |
| Default user gender. | |
| #define | ACTIVITY_DEFAULT_AGE_YEARS 30 |
| Default user age, in years. | |
| #define | ACTIVITY_DEFAULT_PREFERENCES |
| Initializer for the default ActivitySettings. | |
| #define | ACTIVITY_HEART_RATE_DEFAULT_PREFERENCES |
| Initializer for the default HeartRatePreferences. | |
| #define | ACTIVITY_HRM_DEFAULT_PREFERENCES |
| Initializer for the default ActivityHRMSettings. | |
| #define | ACTIVITY_SPO2_DEFAULT_PREFERENCES |
| Initializer for the default ActivitySpO2Settings. | |
| #define | ACTIVITY_DEFAULT_MIN_HR 40 |
| Lowest heart rate reading accepted as valid, in beats per minute. | |
| #define | ACTIVITY_DEFAULT_MAX_HR 200 |
| Highest heart rate reading accepted as valid, in beats per minute. | |
| #define | ACTIVITY_SESSION_MAX_LENGTH_MIN PBL_MIN_PER_DAY |
| Maximum length of a session, in minutes (one day). | |
| #define | ACTIVITY_RAW_SAMPLES_VERSION 2 |
| Version of ActivityRawSamplesRecord. | |
| #define | ACTIVITY_RAW_SAMPLES_MAX_ENTRIES 25 |
| Maximum number of encoded entries in a ActivityRawSamplesRecord. | |
| #define | ACTIVITY_RAW_SAMPLE_VALUE_BITS (10) |
| Bits per encoded axis value. | |
| #define | ACTIVITY_RAW_SAMPLE_VALUE_MASK (0x03FF) |
| Mask of an encoded axis value. | |
| #define | ACTIVITY_RAW_SAMPLE_SHIFT 3 |
| Right shift applied to raw axis values before encoding. | |
| #define | ACTIVITY_RAW_SAMPLE_VALUE_ENCODE(x) ((((x) + 4) >> ACTIVITY_RAW_SAMPLE_SHIFT) & ACTIVITY_RAW_SAMPLE_VALUE_MASK) |
| Encode a raw axis value, rounding to nearest. | |
| #define | ACTIVITY_RAW_SAMPLE_MAX_RUN_SIZE 3 |
| Maximum run size of an encoded entry. | |
| #define | ACTIVITY_RAW_SAMPLE_GET_RUN_SIZE(s) ((s) >> (3 * ACTIVITY_RAW_SAMPLE_VALUE_BITS)) |
| Get the run size of an encoded entry. | |
| #define | ACTIVITY_RAW_SAMPLE_SET_RUN_SIZE(s, r) (s |= (r) << (3 * ACTIVITY_RAW_SAMPLE_VALUE_BITS)) |
| Set the run size of an encoded entry. | |
| #define | ACTIVITY_RAW_SAMPLE_SIGN_EXTEND(x) ((x) & 0x1000 ? -1 * (0x2000 - (x)) : (x)) |
| Sign extend a decoded 13-bit axis value. | |
| #define | ACTIVITY_RAW_SAMPLE_GET_X(s) |
| Decode the x axis of an encoded entry, in mG. | |
| #define | ACTIVITY_RAW_SAMPLE_GET_Y(s) |
| Decode the y axis of an encoded entry, in mG. | |
| #define | ACTIVITY_RAW_SAMPLE_GET_Z(s) ACTIVITY_RAW_SAMPLE_SIGN_EXTEND((s & ACTIVITY_RAW_SAMPLE_VALUE_MASK) << ACTIVITY_RAW_SAMPLE_SHIFT) |
| Decode the z axis of an encoded entry, in mG. | |
| #define | ACTIVITY_RAW_SAMPLE_ENCODE(run_size, x, y, z) |
| Encode a run of identical samples into an entry. | |
| #define | ACTIVITY_RAW_SAMPLE_FLAG_FIRST_RECORD 0x01 |
| ActivityRawSamplesRecord flag: first record of a session. | |
| #define | ACTIVITY_RAW_SAMPLE_FLAG_LAST_RECORD 0x02 |
| ActivityRawSamplesRecord flag: last record of a session. | |
| #define | ACTIVITY_NUM_METRIC_AVERAGES (4 * 24) |
| Number of step averages per day, one per 15 minute interval. | |
| #define | ACTIVITY_METRIC_AVERAGES_UNKNOWN 0xFFFF |
| Step average value meaning unknown. | |
Typedefs | |
| typedef enum ActivationDelayInsightType | ActivationDelayInsightType |
| Forward declaration of ActivationDelayInsightType. | |
Functions | |
| bool | activity_init (void) |
| Initialize the activity service. | |
| bool | activity_is_initialized (void) |
| Check whether the activity service is initialized. | |
| bool | activity_start_tracking (bool test_mode) |
| Start activity tracking, sampling the accelerometer. | |
| bool | activity_stop_tracking (void) |
| Stop activity tracking. | |
| bool | activity_tracking_on (void) |
| Check whether activity tracking is running. | |
| void | activity_set_enabled (bool enable) |
| Enable or disable the activity service for the current run level. | |
| void | activity_prefs_tracking_set_enabled (bool enable) |
| Persist whether activity tracking is enabled. | |
| bool | activity_prefs_tracking_is_enabled (void) |
| Check whether activity tracking is enabled in prefs. | |
| void | activity_prefs_set_activated (void) |
| Record the activation time, if not recorded yet. | |
| time_t | activity_prefs_get_activation_time (void) |
| Get the activation time. | |
| bool | activity_prefs_has_activation_delay_insight_fired (ActivationDelayInsightType type) |
| Check whether an activation delay insight has fired. | |
| void | activity_prefs_set_activation_delay_insight_fired (ActivationDelayInsightType type) |
| Mark an activation delay insight as fired. | |
| uint8_t | activity_prefs_get_health_app_opened_version (void) |
| Get the version of the health app that was last opened. | |
| void | activity_prefs_set_health_app_opened_version (uint8_t version) |
| Record that the health app was opened. | |
| uint8_t | activity_prefs_get_workout_app_opened_version (void) |
| Get the version of the workout app that was last opened. | |
| void | activity_prefs_set_workout_app_opened_version (uint8_t version) |
| Record that the workout app was opened. | |
| void | activity_prefs_activity_insights_set_enabled (bool enable) |
| Enable or disable activity insights. | |
| bool | activity_prefs_activity_insights_are_enabled (void) |
| Check whether activity insights are enabled. | |
| void | activity_prefs_sleep_insights_set_enabled (bool enable) |
| Enable or disable sleep insights. | |
| bool | activity_prefs_sleep_insights_are_enabled (void) |
| Check whether sleep insights are enabled. | |
| void | activity_prefs_set_height_mm (uint16_t height_mm) |
| Set the user's height. | |
| uint16_t | activity_prefs_get_height_mm (void) |
| Get the user's height. | |
| void | activity_prefs_set_weight_dag (uint16_t weight_dag) |
| Set the user's weight. | |
| uint16_t | activity_prefs_get_weight_dag (void) |
| Get the user's weight. | |
| void | activity_prefs_set_gender (ActivityGender gender) |
| Set the user's gender. | |
| ActivityGender | activity_prefs_get_gender (void) |
| Get the user's gender. | |
| void | activity_prefs_set_age_years (uint8_t age_years) |
| Set the user's age. | |
| uint8_t | activity_prefs_get_age_years (void) |
| Get the user's age. | |
| uint8_t | activity_prefs_heart_get_resting_hr (void) |
| Get the user's resting heart rate. | |
| uint8_t | activity_prefs_heart_get_elevated_hr (void) |
| Get the heart rate at or above which the rate is considered elevated. | |
| uint8_t | activity_prefs_heart_get_max_hr (void) |
| Get the user's maximum heart rate. | |
| uint8_t | activity_prefs_heart_get_zone1_threshold (void) |
| Get the lowest heart rate of zone 1. | |
| uint8_t | activity_prefs_heart_get_zone2_threshold (void) |
| Get the lowest heart rate of zone 2. | |
| uint8_t | activity_prefs_heart_get_zone3_threshold (void) |
| Get the lowest heart rate of zone 3. | |
| bool | activity_prefs_heart_rate_is_enabled (void) |
| Check whether heart rate monitoring is enabled. | |
| bool | activity_prefs_blood_oxygen_is_enabled (void) |
| Check whether background blood oxygen (SpO2) monitoring is enabled. | |
| bool | activity_prefs_blood_oxygen_activity_tracking_is_enabled (void) |
| Check whether SpO2 sampling during detected activities is enabled. | |
| HRMonitoringInterval | activity_prefs_get_hrm_measurement_interval (void) |
| Get the background heart rate measurement interval. | |
| void | activity_prefs_set_hrm_measurement_interval (HRMonitoringInterval interval) |
| Set the background heart rate measurement interval. | |
| bool | activity_prefs_hrm_activity_tracking_is_enabled (void) |
| Check whether heart rate tracking during detected walks and runs is enabled. | |
| void | activity_prefs_set_hrm_activity_tracking_enabled (bool enabled) |
| Enable or disable heart rate tracking during detected walks and runs. | |
| void | activity_prefs_set_blood_oxygen_enabled (bool enabled) |
| Enable or disable background blood oxygen (SpO2) monitoring. | |
| void | activity_prefs_set_blood_oxygen_activity_tracking_enabled (bool enabled) |
| Enable or disable SpO2 sampling during detected activities. | |
| HRMonitoringInterval | activity_prefs_get_spo2_measurement_interval (void) |
| Get the background SpO2 measurement interval. | |
| void | activity_prefs_set_spo2_measurement_interval (HRMonitoringInterval interval) |
| Set the background SpO2 measurement interval. | |
| bool | activity_get_metric (ActivityMetric metric, uint32_t history_len, int32_t *history) |
| Get the current and, optionally, past values of a metric. | |
| bool | activity_get_metric_typical (ActivityMetric metric, enum pbl_weekday day, int32_t *value_out) |
| Get the typical value of a metric for a day of the week. | |
| bool | activity_get_metric_monthly_avg (ActivityMetric metric, int32_t *value_out) |
| Get the average value of a metric over the last 4 weeks. | |
| bool | activity_get_sessions (uint32_t *session_entries, ActivitySession *sessions) |
| Get the cached activity sessions. | |
| bool | activity_get_minute_history (HealthMinuteData *minute_data, uint32_t *num_records, time_t *utc_start) |
| Get historical minute data. | |
| bool | activity_get_step_averages (enum pbl_weekday day_of_week, ActivityMetricAverages *averages) |
| Get the typical step counts of a day of the week. | |
| bool | activity_raw_sample_collection (bool enable, bool disable, bool *enabled, uint32_t *session_id, uint32_t *num_samples, uint32_t *seconds) |
| Control raw accelerometer sample collection. | |
| bool | activity_dump_sleep_log (void) |
| Dump the minute data used for sleep base64-encoded with PBL_LOG. | |
| bool | activity_test_feed_samples (AccelRawData *data, uint32_t num_samples) |
| Feed accelerometer samples, bypassing the accelerometer (test apps). | |
| bool | activity_test_run_minute_callback (void) |
| Run the minute callback immediately (test apps). | |
| bool | activity_test_minute_file_info (bool compact_first, uint32_t *num_records, uint32_t *data_bytes, uint32_t *minutes) |
| Get information on the minute data file (test apps). | |
| bool | activity_test_fill_minute_file (void) |
| Fill the minute data file (test apps). | |
| bool | activity_test_send_fake_dls_records (void) |
| Send fake records to data logging (test apps). | |
| void | activity_test_set_steps_and_avg (int32_t new_steps, int32_t current_avg, int32_t daily_avg) |
| Set the current step count and averages (test apps). | |
| void | activity_test_set_steps_history () |
| Fill the past days of step history with test data (test apps). | |
| void | activity_test_set_sleep_history () |
| Fill the past days of sleep history with test data (test apps). | |
Step counting, sleep tracking, activity sessions and health metrics.
The activity service samples the accelerometer at 25 Hz and feeds the samples to the activity algorithm (see Kraepelin algorithm) on KernelBG. The algorithm counts steps over 5 second epochs and, once a minute, produces a minute record (steps, VMC, orientation, light, heart rate, SpO2) that is stored in a minute file and sent to the phone through data logging. From the minute data it detects sleep, restful sleep, walks and runs, reported as ActivitySession entries.
Daily metrics are reset at midnight and the last ACTIVITY_HISTORY_DAYS days are kept in the activity settings file. Units used across the service:
Today's step count and the previous days:
Sessions detected today:
| struct ActivitySettings |
User profile and activity preferences, as stored in prefs.
| Data Fields | ||
|---|---|---|
| bool | activity_insights_enabled | Activity insights enabled. |
| int8_t | age_years | Age, in years. |
| int8_t | gender | ActivityGender value. |
| int16_t | height_mm | Height, in millimeters. |
| bool | sleep_insights_enabled | Sleep insights enabled. |
| bool | tracking_enabled | Activity tracking enabled. |
| int16_t | weight_dag | Weight, in decagrams (10 g). |
| struct HeartRatePreferences |
Heart rate thresholds, in beats per minute, as stored in prefs.
| struct ActivityHRMSettings |
Heart rate monitor preferences, as stored in prefs.
| Data Fields | ||
|---|---|---|
| bool | activity_tracking_enabled | Continuous heart rate tracking during detected walks and runs. |
| bool | enabled | Heart rate monitoring enabled. |
| uint8_t | measurement_interval | HRMonitoringInterval value. |
| struct ActivitySpO2Settings |
Blood oxygen (SpO2) preferences, as stored in prefs.
The on/off setting is synced from the phone under its own key (PREF_KEY_BLOOD_OXYGEN_PREFERENCES); only the watch-local interval lives here.
| Data Fields | ||
|---|---|---|
| uint8_t | measurement_interval | HRMonitoringInterval value. |
| struct ActivitySessionDataStepping |
Data of step based sessions (walk, run, open workout).
Part of the data logging format: changing it requires bumping ACTIVITY_SESSION_LOGGING_VERSION.
| Data Fields | ||
|---|---|---|
| uint16_t | active_kcalories | Active kcal burned. |
| uint16_t | distance_meters | Distance covered, in meters. |
| uint16_t | resting_kcalories | Resting kcal burned. |
| uint16_t | steps | Steps taken. |
| struct ActivitySessionDataSleeping |
Data of sleep sessions (currently none).
Part of the data logging format: changing it requires bumping ACTIVITY_SESSION_LOGGING_VERSION.
| struct ActivitySession |
A detected or manual activity session.
| Data Fields | ||
|---|---|---|
| union ActivitySession.__unnamed41__ | __unnamed__ | Session flags. |
| union ActivitySession.__unnamed43__ | __unnamed__ | Type specific data. |
| uint16_t | length_min | Length, in minutes. |
| int32_t | start_utc | Start time, UTC. |
| ActivitySessionType | type: 8 | Session type. |
| struct ActivityRawSamplesRecord |
Data logging record of raw accelerometer sample collection.
See ACTIVITY_RAW_SAMPLES_VERSION for the entry encoding.
| Data Fields | ||
|---|---|---|
| uint32_t | entries[ACTIVITY_RAW_SAMPLES_MAX_ENTRIES] | Encoded entries, each representing a run of up to 3 identical samples. |
| uint8_t | flags | ACTIVITY_RAW_SAMPLE_FLAG_* flags. |
| uint8_t | len | Length of this record in bytes, header included. |
| uint8_t | num_entries | Number of valid elements in entries. |
| uint8_t | num_samples | Number of samples the entries expand to. |
| uint16_t | session_id | Raw sample collection session id. |
| uint32_t | time_local | Local time. |
| uint16_t | version | ACTIVITY_RAW_SAMPLES_VERSION. |
| struct ActivityMetricAverages |
Typical steps for each 15 minute interval of a day.
| Data Fields | ||
|---|---|---|
| uint16_t | average[ACTIVITY_NUM_METRIC_AVERAGES] | Typical steps per interval from midnight, ACTIVITY_METRIC_AVERAGES_UNKNOWN if unknown. |
| union ActivitySession.__unnamed41__ |
Session flags.
| Data Fields | ||
|---|---|---|
| struct ActivitySession.__unnamed41__.__unnamed45__ | __unnamed__ | Individual flags. |
| uint8_t | flags | All flags. |
| struct ActivitySession.__unnamed41__.__unnamed45__ |
| union ActivitySession.__unnamed43__ |
Type specific data.
| Data Fields | ||
|---|---|---|
| ActivitySessionDataSleeping | sleep_data | Data of sleep sessions. |
| ActivitySessionDataStepping | step_data | Data of step based sessions. |
| #define ACTIVITY_CALORIES_PER_KCAL 1000 |
Number of calories in a kilocalorie.
| #define ACTIVITY_DEFAULT_AGE_YEARS 30 |
Default user age, in years.
| #define ACTIVITY_DEFAULT_GENDER ActivityGenderFemale |
Default user gender.
| #define ACTIVITY_DEFAULT_HEIGHT_MM 1620 |
Default user height, in millimeters (5'3.8", CDC average).
| #define ACTIVITY_DEFAULT_MAX_HR 200 |
Highest heart rate reading accepted as valid, in beats per minute.
| #define ACTIVITY_DEFAULT_MIN_HR 40 |
Lowest heart rate reading accepted as valid, in beats per minute.
| #define ACTIVITY_DEFAULT_PREFERENCES |
Initializer for the default ActivitySettings.
| #define ACTIVITY_DEFAULT_WEIGHT_DAG 7539 |
Default user weight, in decagrams (166.2 lbs, CDC average).
| #define ACTIVITY_HEART_RATE_DEFAULT_PREFERENCES |
Initializer for the default HeartRatePreferences.
Zone thresholds are 50%, 70% and 85% of the heart rate reserve.
| #define ACTIVITY_HISTORY_DAYS 30 |
Number of days of metric history kept, today included.
| #define ACTIVITY_HRM_DEFAULT_PREFERENCES |
Initializer for the default ActivityHRMSettings.
| #define ACTIVITY_MAX_ACTIVITY_SESSIONS_COUNT 32 |
Maximum number of activity sessions cached at a time.
A night usually produces 4 or 5 sleep sessions (one container plus restful periods), plus a handful of walks and runs.
| #define ACTIVITY_METRIC_AVERAGES_UNKNOWN 0xFFFF |
Step average value meaning unknown.
| #define ACTIVITY_NUM_METRIC_AVERAGES (4 * 24) |
Number of step averages per day, one per 15 minute interval.
| #define ACTIVITY_RAW_SAMPLE_ENCODE | ( | run_size, | |
| x, | |||
| y, | |||
| z | |||
| ) |
Encode a run of identical samples into an entry.
| run_size | Number of samples in the run, up to ACTIVITY_RAW_SAMPLE_MAX_RUN_SIZE. |
| x | Raw x axis value, in mG. |
| y | Raw y axis value, in mG. |
| z | Raw z axis value, in mG. |
| #define ACTIVITY_RAW_SAMPLE_FLAG_FIRST_RECORD 0x01 |
ActivityRawSamplesRecord flag: first record of a session.
| #define ACTIVITY_RAW_SAMPLE_FLAG_LAST_RECORD 0x02 |
ActivityRawSamplesRecord flag: last record of a session.
| #define ACTIVITY_RAW_SAMPLE_GET_RUN_SIZE | ( | s | ) | ((s) >> (3 * ACTIVITY_RAW_SAMPLE_VALUE_BITS)) |
Get the run size of an encoded entry.
| s | Encoded entry. |
| #define ACTIVITY_RAW_SAMPLE_GET_X | ( | s | ) |
Decode the x axis of an encoded entry, in mG.
| s | Encoded entry. |
| #define ACTIVITY_RAW_SAMPLE_GET_Y | ( | s | ) |
Decode the y axis of an encoded entry, in mG.
| s | Encoded entry. |
| #define ACTIVITY_RAW_SAMPLE_GET_Z | ( | s | ) | ACTIVITY_RAW_SAMPLE_SIGN_EXTEND((s & ACTIVITY_RAW_SAMPLE_VALUE_MASK) << ACTIVITY_RAW_SAMPLE_SHIFT) |
Decode the z axis of an encoded entry, in mG.
| s | Encoded entry. |
| #define ACTIVITY_RAW_SAMPLE_MAX_RUN_SIZE 3 |
Maximum run size of an encoded entry.
| #define ACTIVITY_RAW_SAMPLE_SET_RUN_SIZE | ( | s, | |
| r | |||
| ) | (s |= (r) << (3 * ACTIVITY_RAW_SAMPLE_VALUE_BITS)) |
Set the run size of an encoded entry.
| s | Encoded entry (lvalue). |
| r | Run size. |
| #define ACTIVITY_RAW_SAMPLE_SHIFT 3 |
Right shift applied to raw axis values before encoding.
| #define ACTIVITY_RAW_SAMPLE_SIGN_EXTEND | ( | x | ) | ((x) & 0x1000 ? -1 * (0x2000 - (x)) : (x)) |
Sign extend a decoded 13-bit axis value.
| x | Decoded value, already shifted back left. |
| #define ACTIVITY_RAW_SAMPLE_VALUE_BITS (10) |
Bits per encoded axis value.
| #define ACTIVITY_RAW_SAMPLE_VALUE_ENCODE | ( | x | ) | ((((x) + 4) >> ACTIVITY_RAW_SAMPLE_SHIFT) & ACTIVITY_RAW_SAMPLE_VALUE_MASK) |
Encode a raw axis value, rounding to nearest.
| x | Raw axis value, in mG. |
| #define ACTIVITY_RAW_SAMPLE_VALUE_MASK (0x03FF) |
Mask of an encoded axis value.
| #define ACTIVITY_RAW_SAMPLES_MAX_ENTRIES 25 |
Maximum number of encoded entries in a ActivityRawSamplesRecord.
| #define ACTIVITY_RAW_SAMPLES_VERSION 2 |
Version of ActivityRawSamplesRecord.
Each 32-bit entry of a record encodes a run of identical samples: bits 31-30 hold the run size, then 10 bits per axis for x, y and z (most to least significant). An axis value is the 16-bit raw value (mG) rounded and shifted right by 3 bits, since the dynamic range is +/-4000 mG and the 3 least significant bits are mostly noise.
| #define ACTIVITY_SESSION_MAX_LENGTH_MIN PBL_MIN_PER_DAY |
Maximum length of a session, in minutes (one day).
| #define ACTIVITY_SPO2_DEFAULT_PREFERENCES |
Initializer for the default ActivitySpO2Settings.
| typedef enum ActivationDelayInsightType ActivationDelayInsightType |
Forward declaration of ActivationDelayInsightType.
| enum ActivityGender |
| enum ActivityMetric |
Metrics returned by activity_get_metric().
Unless noted, values are totals for the current day (since local midnight). Only metrics marked as such have history.
| Enumerator | |
|---|---|
| ActivityMetricFirst | First metric. |
| ActivityMetricStepCount | Steps taken. Has history. |
| ActivityMetricActiveSeconds | Seconds spent in active minutes (40 steps or more). Has history. |
| ActivityMetricRestingKCalories | Resting kcal burned. Has history. |
| ActivityMetricActiveKCalories | Active kcal burned. Has history. |
| ActivityMetricDistanceMeters | Distance walked or run, in meters. Has history. |
| ActivityMetricSleepTotalSeconds | Seconds of sleep. Has history. |
| ActivityMetricSleepRestfulSeconds | Seconds of restful (deep) sleep. Has history. |
| ActivityMetricSleepEnterAtSeconds | Time the user fell asleep, in seconds after midnight. Has history. |
| ActivityMetricSleepExitAtSeconds | Time the user woke up, in seconds after midnight. Has history. |
| ActivityMetricSleepState | Current ActivitySleepState value. |
| ActivityMetricSleepStateSeconds | Seconds spent so far in the current ActivityMetricSleepState. |
| ActivityMetricLastVMC | VMC (vector magnitude counts) of the last processed minute. |
| ActivityMetricHeartRateRawBPM | Most recent heart rate reading, in beats per minute. |
| ActivityMetricHeartRateRawQuality | Quality of the most recent heart rate reading, an |
| ActivityMetricHeartRateRawUpdatedTimeUTC | UTC time of the most recent heart rate reading. |
| ActivityMetricHeartRateFilteredBPM | Most recent stable heart rate (median over a minute), in beats per minute. |
| ActivityMetricHeartRateFilteredUpdatedTimeUTC | UTC time of the most recent stable heart rate. |
| ActivityMetricHeartRateZone1Minutes | Minutes spent in heart rate zone 1 today. |
| ActivityMetricHeartRateZone2Minutes | Minutes spent in heart rate zone 2 today. |
| ActivityMetricHeartRateZone3Minutes | Minutes spent in heart rate zone 3 today. |
| ActivityMetricNumMetrics | Number of metrics. |
| ActivityMetricInvalid | Invalid metric. |
| enum ActivitySessionType |
Activity session types, used in ActivitySession.
Values are logged to the phone.
| Enumerator | |
|---|---|
| ActivitySessionType_None | No session. |
| ActivitySessionType_Sleep | Entire sleep session from falling asleep to waking up, containing both light and restful periods. |
| ActivitySessionType_RestfulSleep | Restful period, always inside an ActivitySessionType_Sleep session. |
| ActivitySessionType_Nap | Like ActivitySessionType_Sleep, but labeled a nap because of its duration and time. |
| ActivitySessionType_RestfulNap | Restful period, always inside an ActivitySessionType_Nap session. |
| ActivitySessionType_Walk | Walk of significant length. |
| ActivitySessionType_Run | Run. |
| ActivitySessionType_Open | Open (generic) workout. |
| ActivitySessionTypeCount | Number of session types. |
| ActivitySessionType_Invalid | Invalid session type. |
| enum ActivitySleepState |
Sleep state.
Value of ActivityMetricSleepState.
| Enumerator | |
|---|---|
| ActivitySleepStateAwake | Awake. |
| ActivitySleepStateRestfulSleep | Restful (deep) sleep. |
| ActivitySleepStateLightSleep | Light sleep. |
| ActivitySleepStateUnknown | Unknown. |
| enum HRMonitoringInterval |
Background measurement interval for heart rate and SpO2.
Values are persisted: new ones go at the end.
| bool activity_dump_sleep_log | ( | void | ) |
Dump the minute data used for sleep base64-encoded with PBL_LOG.
Used to extract it through a support request. Blocks on KernelBG, so only callable from the app or worker task.
| bool activity_get_metric | ( | ActivityMetric | metric, |
| uint32_t | history_len, | ||
| int32_t * | history | ||
| ) |
Get the current and, optionally, past values of a metric.
Metrics without history only fill index 0.
| metric | Metric to fetch. | |
| history_len | Number of entries in history. At most ACTIVITY_HISTORY_DAYS are used. | |
| [out] | history | Values: today at index 0, yesterday at index 1, etc. Days without data, and entries past index 0 for metrics without history, are set to -1. |
| bool activity_get_metric_monthly_avg | ( | ActivityMetric | metric, |
| int32_t * | value_out | ||
| ) |
Get the average value of a metric over the last 4 weeks.
Only ActivityMetricStepCount and ActivityMetricSleepTotalSeconds are available, as stored in the health database by the phone.
| metric | Metric. | |
| [out] | value_out | Average value, 0 if unavailable. |
| bool activity_get_metric_typical | ( | ActivityMetric | metric, |
| enum pbl_weekday | day, | ||
| int32_t * | value_out | ||
| ) |
Get the typical value of a metric for a day of the week.
Typical values are computed by the phone and stored in the health database. Only sleep metrics (total, restful, enter and exit times) are available.
| metric | Metric. | |
| day | Day of the week. | |
| [out] | value_out | Typical value, 0 if unavailable. |
| bool activity_get_minute_history | ( | HealthMinuteData * | minute_data, |
| uint32_t * | num_records, | ||
| time_t * | utc_start | ||
| ) |
Get historical minute data.
Blocks on KernelBG, so only callable from the app or worker task.
| [out] | minute_data | Array filled with one record per minute. |
| [in,out] | num_records | On entry, capacity of minute_data. On exit, number of records written, missing minutes included (marked with is_invalid). |
| [in,out] | utc_start | On entry, UTC time of the first requested minute. On exit, UTC time of the first returned minute. |
| bool activity_get_sessions | ( | uint32_t * | session_entries, |
| ActivitySession * | sessions | ||
| ) |
Get the cached activity sessions.
Sessions older than the current day are pruned once a minute, so these are today's sessions.
| [in,out] | session_entries | On entry, capacity of sessions in elements. On exit, number of sessions written. |
| [out] | sessions | Filled with the sessions. |
| bool activity_get_step_averages | ( | enum pbl_weekday | day_of_week, |
| ActivityMetricAverages * | averages | ||
| ) |
Get the typical step counts of a day of the week.
Read from the health database, populated by the phone.
| day_of_week | Day of the week. | |
| [out] | averages | Step averages; all unknown if unavailable. |
| bool activity_init | ( | void | ) |
Initialize the activity service.
Does not start tracking, see activity_start_tracking().
| bool activity_is_initialized | ( | void | ) |
Check whether the activity service is initialized.
| bool activity_prefs_activity_insights_are_enabled | ( | void | ) |
Check whether activity insights are enabled.
| void activity_prefs_activity_insights_set_enabled | ( | bool | enable | ) |
Enable or disable activity insights.
| enable | If true, enable activity insights. |
| bool activity_prefs_blood_oxygen_activity_tracking_is_enabled | ( | void | ) |
Check whether SpO2 sampling during detected activities is enabled.
Opt-in, only meaningful with heart rate tracking during activities. Allows the SpO2 path even when background SpO2 monitoring is off. Declared regardless of CONFIG_HRM.
| bool activity_prefs_blood_oxygen_is_enabled | ( | void | ) |
Check whether background blood oxygen (SpO2) monitoring is enabled.
Declared regardless of CONFIG_HRM since the HRM manager gates sensor power on it.
| time_t activity_prefs_get_activation_time | ( | void | ) |
Get the activation time.
| uint8_t activity_prefs_get_age_years | ( | void | ) |
Get the user's age.
| ActivityGender activity_prefs_get_gender | ( | void | ) |
Get the user's gender.
| uint8_t activity_prefs_get_health_app_opened_version | ( | void | ) |
Get the version of the health app that was last opened.
| uint16_t activity_prefs_get_height_mm | ( | void | ) |
Get the user's height.
| HRMonitoringInterval activity_prefs_get_hrm_measurement_interval | ( | void | ) |
Get the background heart rate measurement interval.
| HRMonitoringInterval activity_prefs_get_spo2_measurement_interval | ( | void | ) |
Get the background SpO2 measurement interval.
| uint16_t activity_prefs_get_weight_dag | ( | void | ) |
Get the user's weight.
| uint8_t activity_prefs_get_workout_app_opened_version | ( | void | ) |
Get the version of the workout app that was last opened.
| bool activity_prefs_has_activation_delay_insight_fired | ( | ActivationDelayInsightType | type | ) |
Check whether an activation delay insight has fired.
| type | Insight. |
| uint8_t activity_prefs_heart_get_elevated_hr | ( | void | ) |
Get the heart rate at or above which the rate is considered elevated.
| uint8_t activity_prefs_heart_get_max_hr | ( | void | ) |
Get the user's maximum heart rate.
| uint8_t activity_prefs_heart_get_resting_hr | ( | void | ) |
Get the user's resting heart rate.
| uint8_t activity_prefs_heart_get_zone1_threshold | ( | void | ) |
Get the lowest heart rate of zone 1.
| uint8_t activity_prefs_heart_get_zone2_threshold | ( | void | ) |
Get the lowest heart rate of zone 2.
| uint8_t activity_prefs_heart_get_zone3_threshold | ( | void | ) |
Get the lowest heart rate of zone 3.
| bool activity_prefs_heart_rate_is_enabled | ( | void | ) |
Check whether heart rate monitoring is enabled.
| bool activity_prefs_hrm_activity_tracking_is_enabled | ( | void | ) |
Check whether heart rate tracking during detected walks and runs is enabled.
| void activity_prefs_set_activated | ( | void | ) |
Record the activation time, if not recorded yet.
Used to send insights a number of days after activation.
| void activity_prefs_set_activation_delay_insight_fired | ( | ActivationDelayInsightType | type | ) |
Mark an activation delay insight as fired.
| type | Insight. |
| void activity_prefs_set_age_years | ( | uint8_t | age_years | ) |
Set the user's age.
| age_years | Age, in years. |
| void activity_prefs_set_blood_oxygen_activity_tracking_enabled | ( | bool | enabled | ) |
Enable or disable SpO2 sampling during detected activities.
| enabled | If true, enable it. |
| void activity_prefs_set_blood_oxygen_enabled | ( | bool | enabled | ) |
Enable or disable background blood oxygen (SpO2) monitoring.
The setting is synced to the phone.
| enabled | If true, enable it. |
| void activity_prefs_set_gender | ( | ActivityGender | gender | ) |
Set the user's gender.
| gender | Gender. |
| void activity_prefs_set_health_app_opened_version | ( | uint8_t | version | ) |
Record that the health app was opened.
| version | Health app version. |
| void activity_prefs_set_height_mm | ( | uint16_t | height_mm | ) |
Set the user's height.
| height_mm | Height, in millimeters. |
| void activity_prefs_set_hrm_activity_tracking_enabled | ( | bool | enabled | ) |
Enable or disable heart rate tracking during detected walks and runs.
| enabled | If true, enable it. |
| void activity_prefs_set_hrm_measurement_interval | ( | HRMonitoringInterval | interval | ) |
Set the background heart rate measurement interval.
| interval | Interval. |
| void activity_prefs_set_spo2_measurement_interval | ( | HRMonitoringInterval | interval | ) |
Set the background SpO2 measurement interval.
| interval | Interval. |
| void activity_prefs_set_weight_dag | ( | uint16_t | weight_dag | ) |
Set the user's weight.
| weight_dag | Weight, in decagrams (10 g). |
| void activity_prefs_set_workout_app_opened_version | ( | uint8_t | version | ) |
Record that the workout app was opened.
| version | Workout app version. |
| bool activity_prefs_sleep_insights_are_enabled | ( | void | ) |
Check whether sleep insights are enabled.
| void activity_prefs_sleep_insights_set_enabled | ( | bool | enable | ) |
Enable or disable sleep insights.
| enable | If true, enable sleep insights. |
| bool activity_prefs_tracking_is_enabled | ( | void | ) |
Check whether activity tracking is enabled in prefs.
| void activity_prefs_tracking_set_enabled | ( | bool | enable | ) |
Persist whether activity tracking is enabled.
| enable | If true, enable activity tracking. |
| bool activity_raw_sample_collection | ( | bool | enable, |
| bool | disable, | ||
| bool * | enabled, | ||
| uint32_t * | session_id, | ||
| uint32_t * | num_samples, | ||
| uint32_t * | seconds | ||
| ) |
Control raw accelerometer sample collection.
Collected samples are sent to data logging as ActivityRawSamplesRecord records and also logged base64-encoded with PBL_LOG, so they can be retrieved through a support request. Each enable starts a new session id, which can be shown to the user to identify the session.
| enable | If true, enable sample collection. | |
| disable | If true, disable sample collection. | |
| [out] | enabled | Whether sample collection is enabled. |
| [out] | session_id | Current session id, or the last one if collection is disabled. |
| [out] | num_samples | Samples collected in the current, or last, session. |
| [out] | seconds | Seconds of data collected in the current, or last, session. |
| void activity_set_enabled | ( | bool | enable | ) |
Enable or disable the activity service for the current run level.
Only for the service manager's services_set_runlevel(). While disabled, tracking is off regardless of activity_start_tracking() and activity_stop_tracking(), and resumes when re-enabled if it was started.
| enable | Whether the run level allows the service. |
| bool activity_start_tracking | ( | bool | test_mode | ) |
Start activity tracking, sampling the accelerometer.
Tracking starts asynchronously on KernelBG.
| test_mode | If true, the accelerometer is not used and samples must be fed with activity_test_feed_samples(). |
| bool activity_stop_tracking | ( | void | ) |
Stop activity tracking.
Tracking stops asynchronously on KernelBG.
| bool activity_test_feed_samples | ( | AccelRawData * | data, |
| uint32_t | num_samples | ||
| ) |
Feed accelerometer samples, bypassing the accelerometer (test apps).
Requires tracking started with activity_start_tracking() in test mode.
| data | Samples. |
| num_samples | Number of samples in data. |
| bool activity_test_fill_minute_file | ( | void | ) |
Fill the minute data file (test apps).
Used to test compaction performance and watchdog timeouts with a large file.
| bool activity_test_minute_file_info | ( | bool | compact_first, |
| uint32_t * | num_records, | ||
| uint32_t * | data_bytes, | ||
| uint32_t * | minutes | ||
| ) |
Get information on the minute data file (test apps).
| compact_first | If true, compact the file first. | |
| [out] | num_records | Number of records in the file. |
| [out] | data_bytes | Bytes of data in the file. |
| [out] | minutes | Minutes of data in the file. |
| bool activity_test_run_minute_callback | ( | void | ) |
Run the minute callback immediately (test apps).
Allows running tests faster than real time.
| bool activity_test_send_fake_dls_records | ( | void | ) |
Send fake records to data logging (test apps).
Sends an AlgMinuteDLSRecord, an ActivityLegacySleepSessionDataLoggingRecord and an ActivitySessionDataLoggingRecord for each session type. Useful for mobile app testing.
| void activity_test_set_sleep_history | ( | ) |
Fill the past days of sleep history with test data (test apps).
| void activity_test_set_steps_and_avg | ( | int32_t | new_steps, |
| int32_t | current_avg, | ||
| int32_t | daily_avg | ||
| ) |
Set the current step count and averages (test apps).
| new_steps | Steps taken today. |
| current_avg | Typical steps up to the current time. |
| daily_avg | Typical steps for the whole day. |
| void activity_test_set_steps_history | ( | ) |
Fill the past days of step history with test data (test apps).
| bool activity_tracking_on | ( | void | ) |
Check whether activity tracking is running.