|
PebbleOS
|
Interface between the activity service and the step/sleep algorithm. More...
Data Structures | |
| struct | AlgMinuteFileSampleV5 |
| Minute file sample, version 5 fields. More... | |
| struct | AlgMinuteFileSample |
| Minute file sample. More... | |
| struct | AlgMinuteDLSSample |
| Data logging minute sample. More... | |
| struct | AlgMinuteRecord |
| Minute record in the circular buffer. More... | |
| struct | AlgMinuteRecordHdr |
| Header of minute file and data logging minute records. More... | |
| struct | AlgMinuteDLSRecord |
| Data logging minute record. More... | |
| struct | AlgMinuteFileRecord |
| Minute file record. More... | |
| union | AlgMinuteFileSampleV5.__unnamed47__ |
| Minute flags. More... | |
| struct | AlgMinuteFileSampleV5.__unnamed47__.__unnamed49__ |
| Individual flags. More... | |
Macros | |
| #define | ALG_MINUTE_FILE_RECORD_VERSION 6 |
| Version of the minute file records. | |
| #define | ALG_DLS_MINUTES_RECORD_VERSION 14 |
| Version of the data logging minute records. | |
| #define | ALG_MINUTES_PER_DLS_RECORD 15 |
| Number of minutes in a data logging minute record. | |
| #define | ALG_MINUTES_PER_FILE_RECORD 15 |
| Number of minutes in a minute file record. | |
| #define | ALG_MINUTE_DATA_FILE_LEN 0x20000 |
| Size quota of the minute file, in bytes. | |
| #define | ALG_MINUTE_FILE_MAX_ENTRIES (ALG_MINUTE_DATA_FILE_LEN / sizeof(AlgMinuteFileRecord)) |
| Upper bound of the number of records in the minute file. | |
Functions | |
| bool | activity_algorithm_init (AccelSamplingRate *sampling_rate) |
| Initialize the algorithm. | |
| void | activity_algorithm_early_deinit (void) |
| Start tearing down: end all ongoing sessions. | |
| bool | activity_algorithm_deinit (void) |
| Deinitialize the algorithm. | |
| bool | activity_algorithm_set_user (uint32_t height_mm, uint32_t weight_g, ActivityGender gender, uint32_t age_years) |
| Set the user metrics used for the calorie computations. | |
| void | activity_algorithm_handle_accel (AccelRawData *data, uint32_t num_samples, uint64_t timestamp_ms) |
| Process accelerometer samples. | |
| void | activity_algorithm_minute_handler (time_t utc_sec, AlgMinuteRecord *record_out) |
| Collect and log the stats of the last minute. | |
| bool | activity_algorithm_get_steps (uint32_t *steps) |
| Get the number of steps counted today. | |
| void | activity_algorithm_enable_activity_tracking (bool enable) |
| Enable or disable automatic activity session detection. | |
| bool | activity_algorithm_activity_hrm_is_active (void) |
| Check whether a continuous heart rate session is active for a detected activity. | |
| void | activity_algorithm_activity_hrm_set_paused (bool paused) |
| Pause or resume the heart rate session of a detected activity. | |
| bool | activity_algorithm_get_step_rate (uint16_t *steps, uint32_t *elapsed_ms, time_t *end_sec) |
| Get the most recent stepping rate. | |
| bool | activity_algorithm_metrics_changed_notification (void) |
| Notify the algorithm that the metrics changed. | |
| time_t | activity_algorithm_get_last_sleep_utc (void) |
| Get the last minute processed by the sleep detector. | |
| void | activity_algorithm_send_minutes (void) |
| Send the buffered minute data to data logging now. | |
| void | activity_algorithm_post_process_sleep_sessions (uint16_t num_sessions, ActivitySession *sessions) |
| Relabel sleep sessions that should be naps. | |
| bool | activity_algorithm_get_minute_history (HealthMinuteData *minute_data, uint32_t *num_records, time_t *utc_start) |
| Get historical minute data. | |
| bool | activity_algorithm_dump_minute_data_to_log (void) |
| Dump the minute file base64-encoded with PBL_LOG. | |
| bool | activity_algorithm_minute_file_info (bool compact_first, uint32_t *num_records, uint32_t *data_bytes, uint32_t *minutes) |
| Get information on the minute file. | |
| bool | activity_algorithm_test_fill_minute_file (void) |
| Fill the minute file (test apps). | |
| bool | activity_algorithm_test_send_fake_minute_data_dls_record (void) |
| Send a fake minute record to data logging (mobile app testing). | |
Interface between the activity service and the step/sleep algorithm.
The activity service calls these from KernelBG. The algorithm consumes accelerometer samples at the rate returned by activity_algorithm_init(), keeps the running step count, builds one minute record per minute, stores those in the minute file and sends them to data logging, and reports detected sessions to the service.
| struct AlgMinuteFileSampleV5 |
Minute file sample, version 5 fields.
The minute file is a settings file holding the subset of the data logging minute data needed by the sleep algorithm and by minute history queries.
| Data Fields | ||
|---|---|---|
| union AlgMinuteFileSampleV5.__unnamed47__ | __unnamed__ | Minute flags. |
| uint8_t | light | Light sensor reading divided by ALG_RAW_LIGHT_SENSOR_DIVIDE_BY. |
| uint8_t | orientation | Average orientation: upper 4 bits are the angle to the Z axis, lower 4 bits the angle in the X-Y plane, each quantized to 16 steps. |
| uint8_t | steps | Steps taken in this minute. |
| uint16_t | vmc | VMC (vector magnitude counts) of this minute. |
| struct AlgMinuteFileSample |
Minute file sample.
| Data Fields | ||
|---|---|---|
| uint8_t | heart_rate_bpm | Median heart rate, in beats per minute, 0 if none. |
| AlgMinuteFileSampleV5 | v5_fields | Fields of versions up to 5. |
| struct AlgMinuteDLSSample |
Data logging minute sample.
| Data Fields | ||
|---|---|---|
| uint16_t | active_calories | Active calories (1/1000 kcal) burned in this minute. |
| AlgMinuteFileSampleV5 | base | Base fields, also stored in the minute file (versions 4 and 5). |
| uint16_t | distance_cm | Distance covered in this minute, in centimeters. |
| uint8_t | heart_rate_bpm | Weighted median heart rate of this minute, in beats per minute. |
| uint16_t | heart_rate_total_weight_x100 | Total weight of the heart rate samples, multiplied by 100. |
| uint8_t | heart_rate_zone | Heart rate zone of this minute (HRZone). |
| uint16_t | resting_calories | Resting calories (1/1000 kcal) burned in this minute. |
| uint8_t | spo2_percent | Blood oxygen saturation (%) measured this minute, 0 if none. |
| uint8_t | spo2_quality |
SpO2 signal quality (HeartRateQuality value), 0 if none. |
| struct AlgMinuteRecord |
Minute record in the circular buffer.
Records are batched there before being written to data logging and the minute file.
| Data Fields | ||
|---|---|---|
| AlgMinuteDLSSample | data | Minute data. |
| time_t | utc_sec | UTC time of the minute. |
| struct AlgMinuteRecordHdr |
Header of minute file and data logging minute records.
| Data Fields | ||
|---|---|---|
| uint8_t | num_samples | Number of samples in the record. |
| uint8_t | sample_size | Size of each sample, in bytes. |
| int8_t | time_local_offset_15_min | Number of 15 minute intervals to add to UTC to get local time. |
| uint32_t | time_utc | UTC time of the first sample. |
| uint16_t | version | ALG_DLS_MINUTES_RECORD_VERSION or ALG_MINUTE_FILE_RECORD_VERSION. |
| struct AlgMinuteDLSRecord |
Data logging minute record.
| Data Fields | ||
|---|---|---|
| AlgMinuteRecordHdr | hdr | Header. |
| AlgMinuteDLSSample | samples[ALG_MINUTES_PER_DLS_RECORD] | One sample per minute. |
| struct AlgMinuteFileRecord |
Minute file record.
| Data Fields | ||
|---|---|---|
| AlgMinuteRecordHdr | hdr | Header. |
| AlgMinuteFileSample | samples[ALG_MINUTES_PER_FILE_RECORD] | One sample per minute. |
| union AlgMinuteFileSampleV5.__unnamed47__ |
Minute flags.
| Data Fields | ||
|---|---|---|
| struct AlgMinuteFileSampleV5.__unnamed47__.__unnamed49__ | __unnamed__ | Individual flags. |
| uint8_t | flags | All flags. |
| struct AlgMinuteFileSampleV5.__unnamed47__.__unnamed49__ |
| #define ALG_DLS_MINUTES_RECORD_VERSION 14 |
Version of the data logging minute records.
Fields may only be appended: the mobile apps keep parsing the known prefix. Android 3.10-4.0 requires bit 2 to be set and iOS requires a value below 255, so valid versions are 4, 5, 6, 7, 12, 13, 14, 15, 20, ...
| #define ALG_MINUTE_DATA_FILE_LEN 0x20000 |
Size quota of the minute file, in bytes.
| #define ALG_MINUTE_FILE_MAX_ENTRIES (ALG_MINUTE_DATA_FILE_LEN / sizeof(AlgMinuteFileRecord)) |
Upper bound of the number of records in the minute file.
Ignores the settings file overhead, so the actual number is lower.
| #define ALG_MINUTE_FILE_RECORD_VERSION 6 |
Version of the minute file records.
| #define ALG_MINUTES_PER_DLS_RECORD 15 |
Number of minutes in a data logging minute record.
| #define ALG_MINUTES_PER_FILE_RECORD 15 |
Number of minutes in a minute file record.
| bool activity_algorithm_activity_hrm_is_active | ( | void | ) |
Check whether a continuous heart rate session is active for a detected activity.
Drives SpO2 sampling during activities.
| void activity_algorithm_activity_hrm_set_paused | ( | bool | paused | ) |
Pause or resume the heart rate session of a detected activity.
Frees the optical path for a SpO2 reading. No-op without an activity heart rate session.
| paused | true to pause, false to resume. |
| bool activity_algorithm_deinit | ( | void | ) |
Deinitialize the algorithm.
| bool activity_algorithm_dump_minute_data_to_log | ( | void | ) |
Dump the minute file base64-encoded with PBL_LOG.
Used to extract it through a support request.
| void activity_algorithm_early_deinit | ( | void | ) |
Start tearing down: end all ongoing sessions.
| void activity_algorithm_enable_activity_tracking | ( | bool | enable | ) |
Enable or disable automatic activity session detection.
Disabled while a workout is running.
| enable | true to detect sessions, false to stop. |
| time_t activity_algorithm_get_last_sleep_utc | ( | void | ) |
Get the last minute processed by the sleep detector.
| bool activity_algorithm_get_minute_history | ( | HealthMinuteData * | minute_data, |
| uint32_t * | num_records, | ||
| time_t * | utc_start | ||
| ) |
Get historical minute data.
| [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_algorithm_get_step_rate | ( | uint16_t * | steps, |
| uint32_t * | elapsed_ms, | ||
| time_t * | end_sec | ||
| ) |
Get the most recent stepping rate.
| [out] | steps | Steps taken during elapsed_ms. |
| [out] | elapsed_ms | Duration over which the rate was computed, in milliseconds. |
| [out] | end_sec | UTC time at which the rate was last computed. |
| bool activity_algorithm_get_steps | ( | uint32_t * | steps | ) |
Get the number of steps counted today.
| [out] | steps | Steps. |
| void activity_algorithm_handle_accel | ( | AccelRawData * | data, |
| uint32_t | num_samples, | ||
| uint64_t | timestamp_ms | ||
| ) |
Process accelerometer samples.
| data | Samples, in mG. |
| num_samples | Number of samples in data. |
| timestamp_ms | Timestamp of the first sample, in milliseconds. |
| bool activity_algorithm_init | ( | AccelSamplingRate * | sampling_rate | ) |
Initialize the algorithm.
| [out] | sampling_rate | Required accelerometer sampling rate. |
| bool activity_algorithm_metrics_changed_notification | ( | void | ) |
Notify the algorithm that the metrics changed.
The algorithm reloads its running steps, calories and distance from the service. Called at midnight to start a new day and whenever new values are written into the health database.
| bool activity_algorithm_minute_file_info | ( | bool | compact_first, |
| uint32_t * | num_records, | ||
| uint32_t * | data_bytes, | ||
| uint32_t * | minutes | ||
| ) |
Get information on the minute file.
| 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. |
| void activity_algorithm_minute_handler | ( | time_t | utc_sec, |
| AlgMinuteRecord * | record_out | ||
| ) |
Collect and log the stats of the last minute.
Called once per minute. The minute data is mostly used to compute sleep.
| utc_sec | UTC time at which the minute handler was triggered. | |
| [out] | record_out | Minute record. |
| void activity_algorithm_post_process_sleep_sessions | ( | uint16_t | num_sessions, |
| ActivitySession * | sessions | ||
| ) |
Relabel sleep sessions that should be naps.
A sleep session is a nap when it is at most ALG_MAX_NAP_MINUTES long and lies entirely between ALG_PRIMARY_MORNING_MINUTE and ALG_PRIMARY_EVENING_MINUTE.
| num_sessions | Number of sessions in sessions. | |
| [in,out] | sessions | Sessions. |
| void activity_algorithm_send_minutes | ( | void | ) |
Send the buffered minute data to data logging now.
| bool activity_algorithm_set_user | ( | uint32_t | height_mm, |
| uint32_t | weight_g, | ||
| ActivityGender | gender, | ||
| uint32_t | age_years | ||
| ) |
Set the user metrics used for the calorie computations.
| height_mm | Height, in millimeters. |
| weight_g | Weight, in grams. |
| gender | Gender. |
| age_years | Age, in years. |
| bool activity_algorithm_test_fill_minute_file | ( | void | ) |
Fill the minute file (test apps).
| bool activity_algorithm_test_send_fake_minute_data_dls_record | ( | void | ) |
Send a fake minute record to data logging (mobile app testing).