PebbleOS v4.47.0-512-g5285d4236
Loading...
Searching...
No Matches
Workout service

Manually started and stopped activity sessions. More...

Data Structures

struct  WorkoutServiceMetrics
 Metrics of the current workout, taken at one instant. More...
 

Functions

void workout_service_init (void)
 Initialize the workout service.
 
void workout_service_frontend_opened (void)
 Signal that the workout app was opened.
 
void workout_service_frontend_closed (void)
 Signal that the workout app was closed.
 
void workout_service_health_event_handler (PebbleHealthEvent *event)
 Handle a health event (movement and heart rate updates).
 
void workout_service_activity_event_handler (PebbleActivityEvent *event)
 Handle an activity event.
 
void workout_service_workout_event_handler (PebbleWorkoutEvent *event)
 Handle a workout event.
 
bool workout_service_is_workout_ongoing (void)
 Check whether a workout is ongoing.
 
bool workout_service_is_workout_type_supported (ActivitySessionType type)
 Check whether a session type can be a workout.
 
bool workout_service_start_workout (ActivitySessionType type)
 Start a workout.
 
bool workout_service_pause_workout (bool should_be_paused)
 Pause or resume the current workout.
 
bool workout_service_stop_workout (void)
 Stop the current workout.
 
bool workout_service_takeover_activity_session (ActivitySession *session)
 Turn a detected activity session into a workout.
 
bool workout_service_is_paused (void)
 Check whether the current workout is paused.
 
bool workout_service_get_current_workout_type (ActivitySessionType *type_out)
 Get the type of the current workout.
 
bool workout_service_get_current_workout_info (int32_t *steps_out, int32_t *duration_s_out, int32_t *distance_m_out, int32_t *current_bpm_out, HRZone *current_hr_zone_out)
 Get the current workout metrics.
 
bool workout_service_get_current_workout_metrics (WorkoutServiceMetrics *metrics_out)
 Get all metrics of the current workout at once.
 

Detailed Description

Manually started and stopped activity sessions.

Workouts are like detected activity sessions, but are started and stopped by the user and update more frequently. Only one workout runs at a time, and automatic session detection is disabled while it runs. Workouts of at least a minute are saved as manual ActivitySession entries when stopped.

int32_t steps, duration_s, distance_m, bpm;
HRZone zone;
workout_service_get_current_workout_info(&steps, &duration_s, &distance_m, &bpm, &zone);
...
}
HRZone
Heart rate zone.
Definition hr_util.h:20
bool workout_service_stop_workout(void)
Stop the current workout.
bool workout_service_get_current_workout_info(int32_t *steps_out, int32_t *duration_s_out, int32_t *distance_m_out, int32_t *current_bpm_out, HRZone *current_hr_zone_out)
Get the current workout metrics.
bool workout_service_start_workout(ActivitySessionType type)
Start a workout.
@ ActivitySessionType_Run
Run.
Definition activity.h:318

Data Structure Documentation

◆ WorkoutServiceMetrics

struct WorkoutServiceMetrics

Metrics of the current workout, taken at one instant.

Data Fields
int32_t active_kcal Estimated active kilocalories.
int32_t avg_bpm Average of the valid heart rate samples, in beats per minute.
int32_t current_bpm Current heart rate, in beats per minute.
HRZone current_hr_zone Current heart rate zone.
int32_t distance_m Distance, in meters.
int32_t duration_s Duration excluding pauses, in seconds.
int32_t hr_samples Valid heart rate samples while not paused, grows with every new reading.
int32_t hr_zone_time_s[HRZoneCount] Seconds spent in each heart rate zone, indexed by HRZone.
int32_t steps Steps.

Function Documentation

◆ workout_service_activity_event_handler()

void workout_service_activity_event_handler ( PebbleActivityEvent *  event)

Handle an activity event.

Pauses the workout when activity tracking stops. Called from the KernelMain event loop.

Parameters
eventEvent.

◆ workout_service_frontend_closed()

void workout_service_frontend_closed ( void  )

Signal that the workout app was closed.

Arms a reminder notification for a workout left running. Must be called from the app task.

◆ workout_service_frontend_opened()

void workout_service_frontend_opened ( void  )

Signal that the workout app was opened.

Cancels the abandoned workout reminder. Must be called from the app task.

◆ workout_service_get_current_workout_info()

bool workout_service_get_current_workout_info ( int32_t *  steps_out,
int32_t *  duration_s_out,
int32_t *  distance_m_out,
int32_t *  current_bpm_out,
HRZone *  current_hr_zone_out 
)

Get the current workout metrics.

Each output is optional.

Parameters
[out]steps_outSteps.
[out]duration_s_outDuration excluding pauses, in seconds.
[out]distance_m_outDistance, in meters.
[out]current_bpm_outCurrent heart rate, in beats per minute.
[out]current_hr_zone_outCurrent heart rate zone.
Returns
true if a workout is ongoing.

◆ workout_service_get_current_workout_metrics()

bool workout_service_get_current_workout_metrics ( WorkoutServiceMetrics *  metrics_out)

Get all metrics of the current workout at once.

Parameters
[out]metrics_outMetrics, left untouched without a workout.
Returns
true if a workout is ongoing.

◆ workout_service_get_current_workout_type()

bool workout_service_get_current_workout_type ( ActivitySessionType *  type_out)

Get the type of the current workout.

Parameters
[out]type_outWorkout type.
Returns
true if a workout is ongoing.

◆ workout_service_health_event_handler()

void workout_service_health_event_handler ( PebbleHealthEvent *  event)

Handle a health event (movement and heart rate updates).

Called from the KernelMain event loop.

Parameters
eventEvent.

◆ workout_service_init()

void workout_service_init ( void  )

Initialize the workout service.

◆ workout_service_is_paused()

bool workout_service_is_paused ( void  )

Check whether the current workout is paused.

Returns
true if a workout is ongoing and paused.

◆ workout_service_is_workout_ongoing()

bool workout_service_is_workout_ongoing ( void  )

Check whether a workout is ongoing.

Returns
true if a workout is ongoing, paused or not.

◆ workout_service_is_workout_type_supported()

bool workout_service_is_workout_type_supported ( ActivitySessionType  type)

Check whether a session type can be a workout.

Parameters
typeSession type.
Returns
true for walks, runs and open workouts.

◆ workout_service_pause_workout()

bool workout_service_pause_workout ( bool  should_be_paused)

Pause or resume the current workout.

Paused time does not count toward the workout duration.

Parameters
should_be_pausedtrue to pause, false to resume.
Returns
true on success, false if no workout is ongoing.

◆ workout_service_start_workout()

bool workout_service_start_workout ( ActivitySessionType  type)

Start a workout.

Ends ongoing detected sessions and disables automatic session detection. Every started workout must eventually be stopped.

Parameters
typeWorkout type.
Returns
true on success, false if the type is unsupported or a workout is already ongoing.

◆ workout_service_stop_workout()

bool workout_service_stop_workout ( void  )

Stop the current workout.

Saves it as a session and notifies the user if it lasted at least a minute, and re-enables automatic session detection.

Returns
true on success, false if no workout is ongoing.

◆ workout_service_takeover_activity_session()

bool workout_service_takeover_activity_session ( ActivitySession *  session)

Turn a detected activity session into a workout.

The session is removed and a workout starts with its start time, duration, steps, distance and calories.

Parameters
sessionSession to take over.
Returns
true on success.

◆ workout_service_workout_event_handler()

void workout_service_workout_event_handler ( PebbleWorkoutEvent *  event)

Handle a workout event.

Called from the KernelMain event loop.

Parameters
eventEvent.