PebbleOS
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions
activity.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <applib/accel_service_private.h>
#include <applib/health_service.h>
#include <pbl/kernel/compiler.h>
#include <pbl/util/time.h>
#include <pbl/util/units.h>

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