PebbleOS
Loading...
Searching...
No Matches
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions
Activity

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.
 

Enumerations

enum  ActivityGender { ActivityGenderFemale = 0 , ActivityGenderMale = 1 , ActivityGenderOther = 2 }
 User gender, used by the calorie computations. More...
 
enum  HRMonitoringInterval {
  HRMonitoringInterval_10Min = 0 , HRMonitoringInterval_30Min , HRMonitoringInterval_1Hour , HRMonitoringInterval_Disabled ,
  HRMonitoringInterval_5Min , HRMonitoringIntervalCount
}
 Background measurement interval for heart rate and SpO2. More...
 
enum  ActivityMetric {
  ActivityMetricFirst = 0 , ActivityMetricStepCount = ActivityMetricFirst , ActivityMetricActiveSeconds , ActivityMetricRestingKCalories ,
  ActivityMetricActiveKCalories , ActivityMetricDistanceMeters , ActivityMetricSleepTotalSeconds , ActivityMetricSleepRestfulSeconds ,
  ActivityMetricSleepEnterAtSeconds , ActivityMetricSleepExitAtSeconds , ActivityMetricSleepState , ActivityMetricSleepStateSeconds ,
  ActivityMetricLastVMC , ActivityMetricHeartRateRawBPM , ActivityMetricHeartRateRawQuality , ActivityMetricHeartRateRawUpdatedTimeUTC ,
  ActivityMetricHeartRateFilteredBPM , ActivityMetricHeartRateFilteredUpdatedTimeUTC , ActivityMetricHeartRateZone1Minutes , ActivityMetricHeartRateZone2Minutes ,
  ActivityMetricHeartRateZone3Minutes , ActivityMetricNumMetrics , ActivityMetricInvalid = ActivityMetricNumMetrics
}
 Metrics returned by activity_get_metric(). More...
 
enum  ActivitySessionType {
  ActivitySessionType_None = 0 , ActivitySessionType_Sleep = 1 , ActivitySessionType_RestfulSleep = 2 , ActivitySessionType_Nap = 3 ,
  ActivitySessionType_RestfulNap = 4 , ActivitySessionType_Walk = 5 , ActivitySessionType_Run = 6 , ActivitySessionType_Open = 7 ,
  ActivitySessionTypeCount , ActivitySessionType_Invalid = ActivitySessionTypeCount
}
 Activity session types, used in ActivitySession. More...
 
enum  ActivitySleepState { ActivitySleepStateAwake = 0 , ActivitySleepStateRestfulSleep , ActivitySleepStateLightSleep , ActivitySleepStateUnknown }
 Sleep state. More...
 

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).
 

Detailed Description

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:

int32_t steps[7];
// steps[0] is today, steps[1] yesterday, ...; -1 where no data is available
}
int32_t sleep_s;
bool activity_get_metric(ActivityMetric metric, uint32_t history_len, int32_t *history)
Get the current and, optionally, past values of a metric.
@ ActivityMetricStepCount
Steps taken.
Definition activity.h:230
@ ActivityMetricSleepTotalSeconds
Seconds of sleep.
Definition activity.h:240
#define ARRAY_LENGTH(array)
Calculate the length of an array, based on the size of the element type.
Definition size.h:18

Sessions detected today:

uint32_t count = ARRAY_LENGTH(sessions);
if (activity_get_sessions(&count, sessions)) {
for (uint32_t i = 0; i < count; i++) {
if (sessions[i].type == ActivitySessionType_Walk) {
// sessions[i].length_min, sessions[i].step_data.steps, ...
}
}
}
A detected or manual activity session.
Definition activity.h:361
bool activity_get_sessions(uint32_t *session_entries, ActivitySession *sessions)
Get the cached activity sessions.
#define ACTIVITY_MAX_ACTIVITY_SESSIONS_COUNT
Maximum number of activity sessions cached at a time.
Definition activity.h:75
@ ActivitySessionType_Walk
Walk of significant length.
Definition activity.h:300

Data Structure Documentation

◆ ActivitySettings

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).

◆ HeartRatePreferences

struct HeartRatePreferences

Heart rate thresholds, in beats per minute, as stored in prefs.

Data Fields
uint8_t elevated_hr Heart rate at or above which the rate is considered elevated.
uint8_t max_hr Maximum heart rate.
uint8_t resting_hr Resting heart rate.
uint8_t zone1_threshold Lowest heart rate of zone 1.
uint8_t zone2_threshold Lowest heart rate of zone 2.
uint8_t zone3_threshold Lowest heart rate of zone 3.

◆ ActivityHRMSettings

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.

◆ ActivitySpO2Settings

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.

◆ ActivitySessionDataStepping

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.

◆ ActivitySessionDataSleeping

struct ActivitySessionDataSleeping

Data of sleep sessions (currently none).

Part of the data logging format: changing it requires bumping ACTIVITY_SESSION_LOGGING_VERSION.

◆ ActivitySession

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.

◆ ActivityRawSamplesRecord

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.

◆ ActivityMetricAverages

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.

◆ ActivitySession.__unnamed41__

union ActivitySession.__unnamed41__

Session flags.

Data Fields
struct ActivitySession.__unnamed41__.__unnamed45__ __unnamed__ Individual flags.
uint8_t flags All flags.

◆ ActivitySession.__unnamed41__.__unnamed45__

struct ActivitySession.__unnamed41__.__unnamed45__

Individual flags.

Data Fields
uint8_t manual: 1 Session was started manually (workout).
uint8_t ongoing: 1 Session is still ongoing.
uint8_t reserved: 6 Reserved.

◆ ActivitySession.__unnamed43__

union ActivitySession.__unnamed43__

Type specific data.

Data Fields
ActivitySessionDataSleeping sleep_data Data of sleep sessions.
ActivitySessionDataStepping step_data Data of step based sessions.

Macro Definition Documentation

◆ ACTIVITY_CALORIES_PER_KCAL

#define ACTIVITY_CALORIES_PER_KCAL   1000

Number of calories in a kilocalorie.

◆ ACTIVITY_DEFAULT_AGE_YEARS

#define ACTIVITY_DEFAULT_AGE_YEARS   30

Default user age, in years.

◆ ACTIVITY_DEFAULT_GENDER

#define ACTIVITY_DEFAULT_GENDER   ActivityGenderFemale

Default user gender.

◆ ACTIVITY_DEFAULT_HEIGHT_MM

#define ACTIVITY_DEFAULT_HEIGHT_MM   1620

Default user height, in millimeters (5'3.8", CDC average).

◆ ACTIVITY_DEFAULT_MAX_HR

#define ACTIVITY_DEFAULT_MAX_HR   200

Highest heart rate reading accepted as valid, in beats per minute.

◆ ACTIVITY_DEFAULT_MIN_HR

#define ACTIVITY_DEFAULT_MIN_HR   40

Lowest heart rate reading accepted as valid, in beats per minute.

◆ ACTIVITY_DEFAULT_PREFERENCES

#define ACTIVITY_DEFAULT_PREFERENCES
Value:
{ \
.tracking_enabled = false, \
.activity_insights_enabled = false, \
.sleep_insights_enabled = false, \
.weight_dag = ACTIVITY_DEFAULT_WEIGHT_DAG, \
}
#define ACTIVITY_DEFAULT_HEIGHT_MM
Default user height, in millimeters (5'3.8", CDC average).
Definition activity.h:166
#define ACTIVITY_DEFAULT_AGE_YEARS
Default user age, in years.
Definition activity.h:172
#define ACTIVITY_DEFAULT_WEIGHT_DAG
Default user weight, in decagrams (166.2 lbs, CDC average).
Definition activity.h:168
#define ACTIVITY_DEFAULT_GENDER
Default user gender.
Definition activity.h:170

Initializer for the default ActivitySettings.

◆ ACTIVITY_DEFAULT_WEIGHT_DAG

#define ACTIVITY_DEFAULT_WEIGHT_DAG   7539

Default user weight, in decagrams (166.2 lbs, CDC average).

◆ ACTIVITY_HEART_RATE_DEFAULT_PREFERENCES

#define ACTIVITY_HEART_RATE_DEFAULT_PREFERENCES
Value:
{ \
.resting_hr = 70, \
.elevated_hr = 100, \
.max_hr = 220 - ACTIVITY_DEFAULT_AGE_YEARS, \
.zone1_threshold = 130 /* 50% of HRR */, \
.zone2_threshold = 154 /* 70% of HRR */, \
.zone3_threshold = 172 /* 85% of HRR */, \
}

Initializer for the default HeartRatePreferences.

Zone thresholds are 50%, 70% and 85% of the heart rate reserve.

◆ ACTIVITY_HISTORY_DAYS

#define ACTIVITY_HISTORY_DAYS   30

Number of days of metric history kept, today included.

◆ ACTIVITY_HRM_DEFAULT_PREFERENCES

#define ACTIVITY_HRM_DEFAULT_PREFERENCES
Value:
{ \
.enabled = true, \
.measurement_interval = HRMonitoringInterval_10Min, \
.activity_tracking_enabled = false, \
}
@ HRMonitoringInterval_10Min
Every 10 minutes (default).
Definition activity.h:131

Initializer for the default ActivityHRMSettings.

◆ ACTIVITY_MAX_ACTIVITY_SESSIONS_COUNT

#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.

◆ ACTIVITY_METRIC_AVERAGES_UNKNOWN

#define ACTIVITY_METRIC_AVERAGES_UNKNOWN   0xFFFF

Step average value meaning unknown.

◆ ACTIVITY_NUM_METRIC_AVERAGES

#define ACTIVITY_NUM_METRIC_AVERAGES   (4 * 24)

Number of step averages per day, one per 15 minute interval.

◆ ACTIVITY_RAW_SAMPLE_ENCODE

#define ACTIVITY_RAW_SAMPLE_ENCODE (   run_size,
  x,
  y,
  z 
)
Value:
((run_size) << (3 * ACTIVITY_RAW_SAMPLE_VALUE_BITS)) | \
#define ACTIVITY_RAW_SAMPLE_VALUE_BITS
Bits per encoded axis value.
Definition activity.h:404
#define ACTIVITY_RAW_SAMPLE_VALUE_ENCODE(x)
Encode a raw axis value, rounding to nearest.
Definition activity.h:415

Encode a run of identical samples into an entry.

Parameters
run_sizeNumber of samples in the run, up to ACTIVITY_RAW_SAMPLE_MAX_RUN_SIZE.
xRaw x axis value, in mG.
yRaw y axis value, in mG.
zRaw z axis value, in mG.

◆ ACTIVITY_RAW_SAMPLE_FLAG_FIRST_RECORD

#define ACTIVITY_RAW_SAMPLE_FLAG_FIRST_RECORD   0x01

ActivityRawSamplesRecord flag: first record of a session.

◆ ACTIVITY_RAW_SAMPLE_FLAG_LAST_RECORD

#define ACTIVITY_RAW_SAMPLE_FLAG_LAST_RECORD   0x02

ActivityRawSamplesRecord flag: last record of a session.

◆ ACTIVITY_RAW_SAMPLE_GET_RUN_SIZE

#define ACTIVITY_RAW_SAMPLE_GET_RUN_SIZE (   s)    ((s) >> (3 * ACTIVITY_RAW_SAMPLE_VALUE_BITS))

Get the run size of an encoded entry.

Parameters
sEncoded entry.

◆ ACTIVITY_RAW_SAMPLE_GET_X

#define ACTIVITY_RAW_SAMPLE_GET_X (   s)
Value:
#define ACTIVITY_RAW_SAMPLE_SIGN_EXTEND(x)
Sign extend a decoded 13-bit axis value.
Definition activity.h:438
#define ACTIVITY_RAW_SAMPLE_SHIFT
Right shift applied to raw axis values before encoding.
Definition activity.h:409
#define ACTIVITY_RAW_SAMPLE_VALUE_MASK
Mask of an encoded axis value.
Definition activity.h:406

Decode the x axis of an encoded entry, in mG.

Parameters
sEncoded entry.

◆ ACTIVITY_RAW_SAMPLE_GET_Y

#define ACTIVITY_RAW_SAMPLE_GET_Y (   s)
Value:

Decode the y axis of an encoded entry, in mG.

Parameters
sEncoded entry.

◆ ACTIVITY_RAW_SAMPLE_GET_Z

#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.

Parameters
sEncoded entry.

◆ ACTIVITY_RAW_SAMPLE_MAX_RUN_SIZE

#define ACTIVITY_RAW_SAMPLE_MAX_RUN_SIZE   3

Maximum run size of an encoded entry.

◆ ACTIVITY_RAW_SAMPLE_SET_RUN_SIZE

#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.

Parameters
sEncoded entry (lvalue).
rRun size.

◆ ACTIVITY_RAW_SAMPLE_SHIFT

#define ACTIVITY_RAW_SAMPLE_SHIFT   3

Right shift applied to raw axis values before encoding.

◆ ACTIVITY_RAW_SAMPLE_SIGN_EXTEND

#define ACTIVITY_RAW_SAMPLE_SIGN_EXTEND (   x)    ((x) & 0x1000 ? -1 * (0x2000 - (x)) : (x))

Sign extend a decoded 13-bit axis value.

Parameters
xDecoded value, already shifted back left.

◆ ACTIVITY_RAW_SAMPLE_VALUE_BITS

#define ACTIVITY_RAW_SAMPLE_VALUE_BITS   (10)

Bits per encoded axis value.

◆ ACTIVITY_RAW_SAMPLE_VALUE_ENCODE

#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.

Parameters
xRaw axis value, in mG.

◆ ACTIVITY_RAW_SAMPLE_VALUE_MASK

#define ACTIVITY_RAW_SAMPLE_VALUE_MASK   (0x03FF)

Mask of an encoded axis value.

◆ ACTIVITY_RAW_SAMPLES_MAX_ENTRIES

#define ACTIVITY_RAW_SAMPLES_MAX_ENTRIES   25

Maximum number of encoded entries in a ActivityRawSamplesRecord.

◆ ACTIVITY_RAW_SAMPLES_VERSION

#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.

◆ ACTIVITY_SESSION_MAX_LENGTH_MIN

#define ACTIVITY_SESSION_MAX_LENGTH_MIN   PBL_MIN_PER_DAY

Maximum length of a session, in minutes (one day).

◆ ACTIVITY_SPO2_DEFAULT_PREFERENCES

#define ACTIVITY_SPO2_DEFAULT_PREFERENCES
Value:
{ \
.measurement_interval = HRMonitoringInterval_10Min, \
}

Initializer for the default ActivitySpO2Settings.

Typedef Documentation

◆ ActivationDelayInsightType

Forward declaration of ActivationDelayInsightType.

Enumeration Type Documentation

◆ ActivityGender

User gender, used by the calorie computations.

Enumerator
ActivityGenderFemale 

Female.

ActivityGenderMale 

Male.

ActivityGenderOther 

Other; calorie formulas use the midpoint between female and male.

◆ 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 HRMQuality value.

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.

◆ 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.

◆ ActivitySleepState

Sleep state.

Value of ActivityMetricSleepState.

Enumerator
ActivitySleepStateAwake 

Awake.

ActivitySleepStateRestfulSleep 

Restful (deep) sleep.

ActivitySleepStateLightSleep 

Light sleep.

ActivitySleepStateUnknown 

Unknown.

◆ HRMonitoringInterval

Background measurement interval for heart rate and SpO2.

Values are persisted: new ones go at the end.

Enumerator
HRMonitoringInterval_10Min 

Every 10 minutes (default).

HRMonitoringInterval_30Min 

Every 30 minutes.

HRMonitoringInterval_1Hour 

Every hour.

HRMonitoringInterval_Disabled 

No background measurements.

HRMonitoringInterval_5Min 

Every 5 minutes (heart rate only; SpO2 falls back to 10 minutes).

HRMonitoringIntervalCount 

Number of intervals.

Function Documentation

◆ activity_dump_sleep_log()

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.

Returns
true on success, false on error.

◆ activity_get_metric()

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.

Parameters
metricMetric to fetch.
history_lenNumber of entries in history. At most ACTIVITY_HISTORY_DAYS are used.
[out]historyValues: 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.
Returns
true on success, false on failure.

◆ activity_get_metric_monthly_avg()

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.

Parameters
metricMetric.
[out]value_outAverage value, 0 if unavailable.
Returns
true if a value was found.

◆ activity_get_metric_typical()

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.

Parameters
metricMetric.
dayDay of the week.
[out]value_outTypical value, 0 if unavailable.
Returns
true if a value was found.

◆ activity_get_minute_history()

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.

Parameters
[out]minute_dataArray filled with one record per minute.
[in,out]num_recordsOn entry, capacity of minute_data. On exit, number of records written, missing minutes included (marked with is_invalid).
[in,out]utc_startOn entry, UTC time of the first requested minute. On exit, UTC time of the first returned minute.
Returns
true on success, false on failure.

◆ activity_get_sessions()

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.

Parameters
[in,out]session_entriesOn entry, capacity of sessions in elements. On exit, number of sessions written.
[out]sessionsFilled with the sessions.
Returns
true on success, false on failure.

◆ activity_get_step_averages()

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.

Parameters
day_of_weekDay of the week.
[out]averagesStep averages; all unknown if unavailable.
Returns
true on success, false on failure.

◆ activity_init()

bool activity_init ( void  )

Initialize the activity service.

Does not start tracking, see activity_start_tracking().

Returns
true on success.

◆ activity_is_initialized()

bool activity_is_initialized ( void  )

Check whether the activity service is initialized.

Returns
true if activity_init() succeeded.

◆ activity_prefs_activity_insights_are_enabled()

bool activity_prefs_activity_insights_are_enabled ( void  )

Check whether activity insights are enabled.

Returns
true if enabled.

◆ activity_prefs_activity_insights_set_enabled()

void activity_prefs_activity_insights_set_enabled ( bool  enable)

Enable or disable activity insights.

Parameters
enableIf true, enable activity insights.

◆ activity_prefs_blood_oxygen_activity_tracking_is_enabled()

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.

Returns
true if enabled.

◆ activity_prefs_blood_oxygen_is_enabled()

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.

Returns
true if enabled.

◆ activity_prefs_get_activation_time()

time_t activity_prefs_get_activation_time ( void  )

Get the activation time.

Returns
UTC time of the first activity_prefs_set_activated() call, 0 if never called.

◆ activity_prefs_get_age_years()

uint8_t activity_prefs_get_age_years ( void  )

Get the user's age.

Returns
Age, in years.

◆ activity_prefs_get_gender()

ActivityGender activity_prefs_get_gender ( void  )

Get the user's gender.

Returns
Gender.

◆ activity_prefs_get_health_app_opened_version()

uint8_t activity_prefs_get_health_app_opened_version ( void  )

Get the version of the health app that was last opened.

Returns
Version, 0 if never opened.

◆ activity_prefs_get_height_mm()

uint16_t activity_prefs_get_height_mm ( void  )

Get the user's height.

Returns
Height, in millimeters.

◆ activity_prefs_get_hrm_measurement_interval()

HRMonitoringInterval activity_prefs_get_hrm_measurement_interval ( void  )

Get the background heart rate measurement interval.

Returns
Interval; HRMonitoringInterval_10Min if the stored value is invalid.

◆ activity_prefs_get_spo2_measurement_interval()

HRMonitoringInterval activity_prefs_get_spo2_measurement_interval ( void  )

Get the background SpO2 measurement interval.

Returns
Interval; HRMonitoringInterval_10Min if the stored value is invalid.

◆ activity_prefs_get_weight_dag()

uint16_t activity_prefs_get_weight_dag ( void  )

Get the user's weight.

Returns
Weight, in decagrams (10 g).

◆ activity_prefs_get_workout_app_opened_version()

uint8_t activity_prefs_get_workout_app_opened_version ( void  )

Get the version of the workout app that was last opened.

Returns
Version, 0 if never opened.

◆ activity_prefs_has_activation_delay_insight_fired()

bool activity_prefs_has_activation_delay_insight_fired ( ActivationDelayInsightType  type)

Check whether an activation delay insight has fired.

Parameters
typeInsight.
Returns
true if it has fired.

◆ activity_prefs_heart_get_elevated_hr()

uint8_t activity_prefs_heart_get_elevated_hr ( void  )

Get the heart rate at or above which the rate is considered elevated.

Returns
Heart rate, in beats per minute.

◆ activity_prefs_heart_get_max_hr()

uint8_t activity_prefs_heart_get_max_hr ( void  )

Get the user's maximum heart rate.

Returns
Heart rate, in beats per minute.

◆ activity_prefs_heart_get_resting_hr()

uint8_t activity_prefs_heart_get_resting_hr ( void  )

Get the user's resting heart rate.

Returns
Heart rate, in beats per minute.

◆ activity_prefs_heart_get_zone1_threshold()

uint8_t activity_prefs_heart_get_zone1_threshold ( void  )

Get the lowest heart rate of zone 1.

Returns
Heart rate, in beats per minute.

◆ activity_prefs_heart_get_zone2_threshold()

uint8_t activity_prefs_heart_get_zone2_threshold ( void  )

Get the lowest heart rate of zone 2.

Returns
Heart rate, in beats per minute.

◆ activity_prefs_heart_get_zone3_threshold()

uint8_t activity_prefs_heart_get_zone3_threshold ( void  )

Get the lowest heart rate of zone 3.

Returns
Heart rate, in beats per minute.

◆ activity_prefs_heart_rate_is_enabled()

bool activity_prefs_heart_rate_is_enabled ( void  )

Check whether heart rate monitoring is enabled.

Returns
true if enabled.

◆ activity_prefs_hrm_activity_tracking_is_enabled()

bool activity_prefs_hrm_activity_tracking_is_enabled ( void  )

Check whether heart rate tracking during detected walks and runs is enabled.

Returns
true if enabled.

◆ activity_prefs_set_activated()

void activity_prefs_set_activated ( void  )

Record the activation time, if not recorded yet.

Used to send insights a number of days after activation.

◆ activity_prefs_set_activation_delay_insight_fired()

void activity_prefs_set_activation_delay_insight_fired ( ActivationDelayInsightType  type)

Mark an activation delay insight as fired.

Parameters
typeInsight.

◆ activity_prefs_set_age_years()

void activity_prefs_set_age_years ( uint8_t  age_years)

Set the user's age.

Parameters
age_yearsAge, in years.

◆ activity_prefs_set_blood_oxygen_activity_tracking_enabled()

void activity_prefs_set_blood_oxygen_activity_tracking_enabled ( bool  enabled)

Enable or disable SpO2 sampling during detected activities.

Parameters
enabledIf true, enable it.

◆ activity_prefs_set_blood_oxygen_enabled()

void activity_prefs_set_blood_oxygen_enabled ( bool  enabled)

Enable or disable background blood oxygen (SpO2) monitoring.

The setting is synced to the phone.

Parameters
enabledIf true, enable it.

◆ activity_prefs_set_gender()

void activity_prefs_set_gender ( ActivityGender  gender)

Set the user's gender.

Parameters
genderGender.

◆ activity_prefs_set_health_app_opened_version()

void activity_prefs_set_health_app_opened_version ( uint8_t  version)

Record that the health app was opened.

Parameters
versionHealth app version.

◆ activity_prefs_set_height_mm()

void activity_prefs_set_height_mm ( uint16_t  height_mm)

Set the user's height.

Parameters
height_mmHeight, in millimeters.

◆ activity_prefs_set_hrm_activity_tracking_enabled()

void activity_prefs_set_hrm_activity_tracking_enabled ( bool  enabled)

Enable or disable heart rate tracking during detected walks and runs.

Parameters
enabledIf true, enable it.

◆ activity_prefs_set_hrm_measurement_interval()

void activity_prefs_set_hrm_measurement_interval ( HRMonitoringInterval  interval)

Set the background heart rate measurement interval.

Parameters
intervalInterval.

◆ activity_prefs_set_spo2_measurement_interval()

void activity_prefs_set_spo2_measurement_interval ( HRMonitoringInterval  interval)

Set the background SpO2 measurement interval.

Parameters
intervalInterval.

◆ activity_prefs_set_weight_dag()

void activity_prefs_set_weight_dag ( uint16_t  weight_dag)

Set the user's weight.

Parameters
weight_dagWeight, in decagrams (10 g).

◆ activity_prefs_set_workout_app_opened_version()

void activity_prefs_set_workout_app_opened_version ( uint8_t  version)

Record that the workout app was opened.

Parameters
versionWorkout app version.

◆ activity_prefs_sleep_insights_are_enabled()

bool activity_prefs_sleep_insights_are_enabled ( void  )

Check whether sleep insights are enabled.

Returns
true if enabled.

◆ activity_prefs_sleep_insights_set_enabled()

void activity_prefs_sleep_insights_set_enabled ( bool  enable)

Enable or disable sleep insights.

Parameters
enableIf true, enable sleep insights.

◆ activity_prefs_tracking_is_enabled()

bool activity_prefs_tracking_is_enabled ( void  )

Check whether activity tracking is enabled in prefs.

Returns
true if enabled.

◆ activity_prefs_tracking_set_enabled()

void activity_prefs_tracking_set_enabled ( bool  enable)

Persist whether activity tracking is enabled.

Parameters
enableIf true, enable activity tracking.

◆ activity_raw_sample_collection()

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.

Parameters
enableIf true, enable sample collection.
disableIf true, disable sample collection.
[out]enabledWhether sample collection is enabled.
[out]session_idCurrent session id, or the last one if collection is disabled.
[out]num_samplesSamples collected in the current, or last, session.
[out]secondsSeconds of data collected in the current, or last, session.
Returns
true on success, false on error.

◆ activity_set_enabled()

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.

Parameters
enableWhether the run level allows the service.

◆ activity_start_tracking()

bool activity_start_tracking ( bool  test_mode)

Start activity tracking, sampling the accelerometer.

Tracking starts asynchronously on KernelBG.

Parameters
test_modeIf true, the accelerometer is not used and samples must be fed with activity_test_feed_samples().
Returns
true if the start request was queued.

◆ activity_stop_tracking()

bool activity_stop_tracking ( void  )

Stop activity tracking.

Tracking stops asynchronously on KernelBG.

Returns
true if the stop request was queued.

◆ activity_test_feed_samples()

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.

Parameters
dataSamples.
num_samplesNumber of samples in data.
Returns
true on success, false on error.

◆ activity_test_fill_minute_file()

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.

Returns
true on success, false on error.

◆ activity_test_minute_file_info()

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).

Parameters
compact_firstIf true, compact the file first.
[out]num_recordsNumber of records in the file.
[out]data_bytesBytes of data in the file.
[out]minutesMinutes of data in the file.
Returns
true on success, false on error.

◆ activity_test_run_minute_callback()

bool activity_test_run_minute_callback ( void  )

Run the minute callback immediately (test apps).

Allows running tests faster than real time.

Returns
true on success, false on error.

◆ activity_test_send_fake_dls_records()

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.

Returns
true on success.

◆ activity_test_set_sleep_history()

void activity_test_set_sleep_history ( )

Fill the past days of sleep history with test data (test apps).

◆ activity_test_set_steps_and_avg()

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).

Parameters
new_stepsSteps taken today.
current_avgTypical steps up to the current time.
daily_avgTypical steps for the whole day.

◆ activity_test_set_steps_history()

void activity_test_set_steps_history ( )

Fill the past days of step history with test data (test apps).

◆ activity_tracking_on()

bool activity_tracking_on ( void  )

Check whether activity tracking is running.

Returns
true if tracking is currently running.