PebbleOS
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions
activity_private.h File Reference
#include "activity.h"
#include <pbl/kernel/sem.h>
#include "hr_util.h"
#include <applib/event_service_client.h>
#include <kernel/events.h>
#include <pbl/kernel/mutex.h>
#include <pbl/services/data_logging/data_logging_service.h>
#include <pbl/services/settings/settings_file.h>
#include <system/hexdump.h>
#include <pbl/logging/logging.h>
#include <pbl/kernel/compiler.h>
#include <stdbool.h>
#include <stdint.h>
#include <pbl/util/time.h>
#include <pbl/util/units.h>

Data Structures

struct  ActivitySettingsValueHistory
 History of a metric, as stored in the settings file. More...
 
struct  ActivityStepData
 Today's step metrics. More...
 
struct  ActivitySleepData
 Today's sleep metrics. More...
 
struct  ActivityHeartRateData
 Heart rate metrics. More...
 
struct  ActivityMetricInfo
 Storage information of a metric, filled by activity_metrics_prv_get_metric_info(). More...
 
struct  ActivityFeedSamples
 Samples fed by activity_test_feed_samples(). More...
 
struct  ActivityLegacySleepSessionDataLoggingRecord
 Legacy data logging record of a sleep session. More...
 
struct  ActivitySessionDataLoggingRecord
 Data logging record of an activity session. More...
 
struct  ActivitySampleCollectionData
 Raw accelerometer sample collection state. More...
 
struct  ActivityHRSupport
 Heart rate support state. More...
 
struct  ActivitySpO2Support
 Background SpO2 support state. More...
 
struct  ActivitySpO2ActivitySupport
 SpO2 reader state during detected activities. More...
 
struct  ActivityState
 Activity service state. More...
 
union  ActivitySessionDataLoggingRecord.__unnamed51__
 Type specific data (version 3). More...
 

Macros

#define ACTIVITY_SETTINGS_UPDATE_MIN   15
 Interval between saves of today's metrics to the settings file, in minutes.
 
#define ACTIVITY_SESSION_UPDATE_MIN   15
 Interval between recomputations of the activity sessions, in minutes.
 
#define ACTIVITY_SCALAR_MAX   UINT32_MAX
 Maximum value of ActivityScalarStore.
 
#define ACTIVITY_STEP_AVERAGES_MINUTES   (PBL_MIN_PER_DAY / ACTIVITY_NUM_METRIC_AVERAGES)
 Minutes covered by each step average.
 
#define ACTIVITY_STEP_AVERAGES_PER_KEY   4
 Step averages stored per settings key.
 
#define ACTIVITY_STEP_AVERAGES_KEYS_PER_DAY    (ACTIVITY_NUM_METRIC_AVERAGES / ACTIVITY_STEP_AVERAGES_PER_KEY)
 Settings keys holding one day of step averages.
 
#define ACTIVITY_ACTIVE_MINUTE_MIN_STEPS   40
 Minimum steps in a minute for it to be an active minute.
 
#define ACTIVITY_LAST_SLEEP_MINUTE_OF_DAY   (21 * PBL_MIN_PER_HOUR)
 Minute of the day (9pm) after which an ending sleep session counts as the next day's.
 
#define ACTIVITY_DEFAULT_HR_ON_TIME_SEC   (60)
 Default length of a background heart rate measurement window, in seconds.
 
#define ACTIVITY_HR_EARLY_ABORT_SEC   (40)
 Time into a heart rate window after which it is aborted without any valid reading, in seconds.
 
#define ACTIVITY_MIN_NUM_GOOD_SAMPLES_SHORT_CIRCUIT   (10)
 Good quality heart rate samples after which the window ends early.
 
#define ACTIVITY_MIN_NUM_EXCELLENT_SAMPLES_SHORT_CIRCUIT   (5)
 Excellent quality heart rate samples after which the window ends early.
 
#define ACTIVITY_MIN_NUM_GOOD_SPO2_SAMPLES_SHORT_CIRCUIT   (2)
 Good quality SpO2 samples after which the window ends early.
 
#define ACTIVITY_DEFAULT_SPO2_ON_TIME_SEC   (90)
 Maximum length of a background SpO2 measurement window, in seconds.
 
#define ACTIVITY_SPO2_EARLY_ABORT_SEC   (45)
 Time into a SpO2 window after which it is aborted if no sample was accepted, in seconds.
 
#define ACTIVITY_SPO2_ACTIVITY_INTERVAL_SEC   (5 * PBL_SEC_PER_MIN)
 Interval between SpO2 attempts during a detected activity, in seconds.
 
#define ACTIVITY_SPO2_ACTIVITY_ATTEMPT_SEC   (35)
 Duration of a SpO2 attempt during a detected activity, in seconds.
 
#define ACTIVITY_SPO2_ACTIVITY_BACKOFF_SEC   (PBL_SEC_PER_MIN)
 Heart rate time after a failed SpO2 attempt before retrying, in seconds.
 
#define ACTIVITY_MIN_NUM_SAMPLES_FOR_HR_ZONE   (5)
 Minimum heart rate samples in a minute to report a zone above zone 0.
 
#define ACTIVITY_HRM_SUBSCRIPTION_ON_PERIOD_SEC   (1)
 Heart rate subscription interval while sampling, in seconds.
 
#define ACTIVITY_HRM_SUBSCRIPTION_OFF_PERIOD_SEC   (PBL_SEC_PER_DAY)
 Heart rate subscription interval while idle, in seconds.
 
#define ACTIVITY_HRM_OFFWRIST_STALE_SEC   (15 * PBL_SEC_PER_MIN)
 Age after which the cached off-wrist status is stale, in seconds.
 
#define ACTIVITY_MAX_HR_SAMPLES   (3 * PBL_SEC_PER_MIN)
 Maximum number of heart rate samples kept to compute the median.
 
#define ACTIVITY_DAG_PER_KG   100
 Decagrams per kilogram.
 
#define ACTIVITY_SETTINGS_FILE_NAME   "activity"
 Name of the activity settings file.
 
#define ACTIVITY_SETTINGS_FILE_LEN   0x4000
 Size of the activity settings file, in bytes.
 
#define ACTIVITY_SETTINGS_CURRENT_VERSION   3
 Version of the activity settings file.
 
#define ACTIVITY_SLEEP_SESSION_LOGGING_VERSION   1
 Version of the legacy sleep session data logging records (before FW 3.11).
 
#define ACTIVITY_SESSION_LOGGING_VERSION   3
 Version of the activity session data logging records.
 

Typedefs

typedef uint32_t ActivityScalarStore
 Storage type of every scalar metric and setting, in RAM and in the settings file.
 
typedef uint32_t(* ActivityMetricConverter) (ActivityScalarStore storage_value)
 Convert a metric from its storage value to the activity_get_metric() value.
 
typedef void * ProtobufLogRef
 Measurements log handle.
 

Enumerations

enum  ActivitySettingsKey {
  ActivitySettingsKeyInvalid = 0 , ActivitySettingsKeyVersion , ActivitySettingsKeyUnused0 , ActivitySettingsKeyUnused1 ,
  ActivitySettingsKeyUnused2 , ActivitySettingsKeyUnused3 , ActivitySettingsKeyStepCountHistory , ActivitySettingsKeyStepMinutesHistory ,
  ActivitySettingsKeyUnused4 , ActivitySettingsKeyDistanceMetersHistory , ActivitySettingsKeySleepTotalMinutesHistory , ActivitySettingsKeySleepDeepMinutesHistory ,
  ActivitySettingsKeySleepEntryMinutesHistory , ActivitySettingsKeySleepEnterAtHistory , ActivitySettingsKeySleepExitAtHistory , ActivitySettingsKeySleepState ,
  ActivitySettingsKeySleepStateMinutes , ActivitySettingsKeyStepAveragesWeekdayFirst , ActivitySettingsKeyStepAveragesWeekdayLast , ActivitySettingsKeyStepAveragesWeekendFirst ,
  ActivitySettingsKeyStepAveragesWeekendLast , ActivitySettingsKeyAgeYears , ActivitySettingsKeyUnused5 , ActivitySettingsKeyInsightSleepRewardTime ,
  ActivitySettingsKeyInsightActivityRewardTime , ActivitySettingsKeyInsightActivitySummaryState , ActivitySettingsKeyInsightSleepSummaryState , ActivitySettingsKeyRestingKCaloriesHistory ,
  ActivitySettingsKeyActiveKCaloriesHistory , ActivitySettingsKeyLastSleepActivityUTC , ActivitySettingsKeyLastRestfulSleepActivityUTC , ActivitySettingsKeyLastStepActivityUTC ,
  ActivitySettingsKeyStoredActivities , ActivitySettingsKeyInsightNapSessionTime , ActivitySettingsKeyInsightActivitySessionTime , ActivitySettingsKeyLastVMC ,
  ActivitySettingsKeyRestingHeartRate , ActivitySettingsKeyHeartRateZone1Minutes , ActivitySettingsKeyHeartRateZone2Minutes , ActivitySettingsKeyHeartRateZone3Minutes
}
 Keys of the activity settings file. More...
 
enum  ActivitySpO2ActPhase { ActivitySpO2ActPhase_Idle = 0 , ActivitySpO2ActPhase_Wait , ActivitySpO2ActPhase_Sampling , ActivitySpO2ActPhase_Backoff }
 Phases of the SpO2 reader during detected activities. More...
 

Functions

ActivityState * activity_private_state (void)
 Get the activity state.
 
bool activity_is_hrm_present (void)
 Check whether a heart rate monitor is present.
 
SettingsFile * activity_private_settings_open (void)
 Open the activity settings file.
 
void activity_private_settings_close (SettingsFile *file)
 Close the activity settings file.
 
bool activity_test_reset (bool reset_settings, bool tracking_on, const ActivitySettingsValueHistory *sleep_history, const ActivitySettingsValueHistory *step_history)
 Reinitialize the activity service (test apps).
 
void activity_sessions_prv_init (SettingsFile *file, time_t utc_now)
 Load the stored activity sessions.
 
time_t activity_sessions_prv_get_sleep_window_start_utc (time_t now_utc)
 Get the start of the sleep day containing a time.
 
void activity_sessions_prv_get_sleep_bounds_utc (time_t now_utc, time_t *enter_utc, time_t *exit_utc)
 Get the sleep bounds of the current day.
 
void activity_sessions_prv_remove_out_of_range_activity_sessions (time_t utc_sec, bool remove_ongoing)
 Remove sessions older than today or in the future.
 
bool activity_sessions_prv_is_sleep_activity (ActivitySessionType activity_type)
 Check whether a session type is sleep related.
 
bool activity_sessions_is_session_type_ongoing (ActivitySessionType activity_type)
 Check whether a session of a type is ongoing.
 
void activity_sessions_prv_add_activity_session (ActivitySession *session)
 Register a new session, or update an existing one.
 
void activity_sessions_prv_delete_activity_session (ActivitySession *session)
 Delete a session.
 
void activity_sessions_prv_minute_handler (time_t utc_sec)
 Run the once a minute session maintenance.
 
void activity_sessions_prv_send_activity_session_to_data_logging (ActivitySession *session)
 Send a session to data logging.
 
void activity_metrics_prv_init (SettingsFile *file, time_t utc_now)
 Initialize all metrics from the settings file.
 
void activity_metrics_prv_get_metric_info (ActivityMetric metric, ActivityMetricInfo *info)
 Get the storage information of a metric.
 
void activity_metrics_prv_minute_handler (time_t utc_sec)
 Run the once a minute metrics maintenance.
 
uint32_t activity_metrics_prv_get_distance_mm (void)
 Get the distance covered today.
 
uint32_t activity_metrics_prv_get_resting_calories (void)
 Get the resting calories burned today.
 
uint32_t activity_metrics_prv_get_active_calories (void)
 Get the active calories burned today.
 
void activity_metrics_prv_get_median_hr_bpm (int32_t *median_out, int32_t *heart_rate_total_weight_x100_out)
 Get the median heart rate since the last reset.
 
HRZone activity_metrics_prv_get_hr_zone (void)
 Get the heart rate zone since the last reset.
 
void activity_metrics_prv_reset_hr_stats (void)
 Reset the median heart rate and the heart rate zone.
 
void activity_metrics_prv_get_spo2_sample (uint8_t *percent_out, uint8_t *quality_out)
 Consume the pending SpO2 reading for the current minute record.
 
void activity_metrics_prv_add_median_hr_sample (PebbleHRMEvent *hrm_event, time_t now_utc, time_t now_uptime)
 Add a heart rate sample to the median.
 
void activity_metrics_prv_set_hrm_worn_status (time_t now_utc, bool is_offwrist)
 Record the worn status reported by the HRM.
 
bool activity_metrics_prv_is_hrm_offwrist (time_t now_utc)
 Check whether the HRM recently reported the watch off-wrist.
 
uint32_t activity_metrics_prv_get_steps (void)
 Get the steps taken today.
 
ActivityScalarStore activity_metrics_prv_steps_per_minute (void)
 Get the steps taken in the past minute.
 
void activity_metrics_prv_set_metric (ActivityMetric metric, enum pbl_weekday day, int32_t value)
 Set a metric's value, on behalf of the phone (health database).
 
void activity_metrics_set_metric_exact (ActivityMetric metric, int32_t value)
 Force today's value of a metric, possibly decreasing it (QEMU and test injection).