Module: Toybox.ActivityMonitor

Overview

The ActivityMonitor module contains the interface for Activity Monitoring data.

Example:

Shows the use of HeartRateIterator, HeartRateSample, and Info

using Toybox.ActivityMonitor;
using Toybox.System;

// get a HeartRateIterator object; oldest sample first
var hrIterator = ActivityMonitor.getHeartRateHistory(null, false);
var previous = hrIterator.next();                                   // get the previous HR
var lastSampleTime = null;                                          // get the last

while (true) {
    var sample = hrIterator.next();
    if (null != sample) {                                           // null check
        if (sample.heartRate != ActivityMonitor.INVALID_HR_SAMPLE   // check for invalid samples
            && previous.heartRate
            != ActivityMonitor.INVALID_HR_SAMPLE) {
                lastSampleTime = sample.when;
                System.println("Previous: " + previous.heartRate);  // print the previous sample
                System.println("Sample: " + sample.heartRate);      // print the current sample
        }
    }
}

// get ActivityMonitor info
var info = ActivityMonitor.getInfo();

var steps = info.steps;
var calories = info.calories;

System.println("You have taken: " + steps +
               " steps and burned: " + calories + " calories!");

Since:

API Level 1.0.0

Supported Devices:

Classes Under Namespace

Classes: ActiveMinutes, HeartRateIterator, HeartRateSample, History, Info

Constant Summary

Constant Variables

Type Name Value Since Description
Type INVALID_HR_SAMPLE 255

API Level 1.2.2

Indicates that the given heart rate sample is invalid.

Type MOVE_BAR_LEVEL_MAX 5

API Level 1.0.0

The maximum level of the move bar

Type MOVE_BAR_LEVEL_MIN 0

API Level 1.0.0

The minimum level of the move bar

Instance Method Summary collapse

Instance Method Details

getHeartRateHistory(period as Time.Duration or Lang.Number or Null, newestFirst as Lang.Boolean) as ActivityMonitor.HeartRateIterator

Get the heart rate history for the given period, up to the last power cycle.

This function always returns the most recent heart rate samples. The time between each HeartRateSample in the iterator may be device dependent.

Parameters:

  • period(Time.Duration, Lang.Number)

    The period of time from which to retrieve heart rate samples

    • If period is null, the entire available history is retrieved

    • If period is a Duration, then the history for the given Duration is retrieved

    • If period is a Number, then the last Number entries are retrieved

  • newestFirst(Lang.Boolean)

    The order in which to retrieve heart rate samples

    • true to get the samples newest first

    • false to get the samples oldest first

Supported Devices:

Returns:

Since:

API Level 1.2.1

getHistory() as Lang.Array<ActivityMonitor.History>

Get an Array of ActivityMonitor.History objects

Returns:

Since:

API Level 1.0.0

getInfo() as ActivityMonitor.Info

Get the current ActivityMonitor.Info

Returns:

Since:

API Level 1.0.0


Generated Nov 29, 2021 1:34:34 PM