Module: Toybox.SensorHistory

Overview

The SensorHistory module contains the interface for SensorHistory.

SensorHistory provides access to historical information recorded by the on-board sensors of device hardware. The amount of information that is available is device dependent. This means that one device may provide more information than another. This class provides an ORDER_* enum which is used to select the data order of the sample iterator.

Since:

API Level 2.1.0

Supported Devices:

Requires Permission:

  • SensorHistory

Classes Under Namespace

Classes: SensorHistoryIterator, SensorSample

Constant Summary

Order

Name Value Since Description
ORDER_NEWEST_FIRST 0

API Level 2.1.0

Request iterator with newest data first

ORDER_OLDEST_FIRST 1

API Level 2.1.0

Request iterator with oldest data first

Instance Method Summary collapse

Instance Method Details

getElevationHistory(options as { :period as Lang.Number or Time.Duration or Null, :order as SensorHistory.Order } or Null) as SensorHistory.SensorHistoryIterator

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

This function always returns the most recent pressure samples. The time between each SensorSample in the iterator may be device dependent.

Parameters:

  • options(Lang.Dictionary)

    Dictionary of options. Can be null.

    • :period(Time.Duration)

      The period of time from which to retrieve the samples:

      • If null, the entire available history is retrieved

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

      • If a Number, then the last specified Number of entries are retrieved

    • :order(Lang.Boolean)

      The order in which to retrieve the samples:

      • If null, the samples will be ORDER_NEWEST_FIRST

      • Use the ORDER_* enumeration to explicitly select ORDER_NEWEST_FIRST or ORDER_OLDEST_FIRST

Example:

Gets a SensoryHistoryIterator and prints out the elevation value from the most recent SensorSample

using Toybox.SensorHistory;
using Toybox.Lang;
using Toybox.System;

// Create a method to get the SensorHistoryIterator object
function getIterator() {
    // Check device for SensorHistory compatibility
    if ((Toybox has :SensorHistory) && (Toybox.SensorHistory has :getElevationHistory)) {
        return Toybox.SensorHistory.getElevationHistory({});
    }
    return null;
}

// Store the iterator info in a variable. The options are 'null' in
// this case so the entire available history is returned with the
// newest samples returned first.
var sensorIter = getIterator();

// Print out the next entry in the iterator
if (sensorIter != null) {
    System.println(sensorIter.next().data);
}

Supported Devices:

Returns:

See Also:

Since:

API Level 2.1.0

getHeartRateHistory(options as { :period as Lang.Number or Time.Duration, :order as SensorHistory.Order or Null } or Null) as SensorHistory.SensorHistoryIterator

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 SensorSample in the iterator may be device dependent.

Parameters:

  • options(Lang.Dictionary)

    Dictionary of options. Can be null.

    • :period(Time.Duration)

      The period of time from which to retrieve the samples:

      • If null, the entire available history is retrieved

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

      • If a Number, then the last specified Number of entries are retrieved

    • :order(Lang.Boolean)

      The order in which to retrieve the samples:

      • If null, the samples will be listed ORDER_NEWEST_FIRST

      • Use the ORDER_* enumeration to explicitly select ORDER_NEWEST_FIRST or ORDER_OLDEST_FIRST

Example:

Gets a SensoryHistoryIterator and prints out the heart rate value from the most recent SensorSample

using Toybox.SensorHistory;
using Toybox.Lang;
using Toybox.System;

// Create a method to get the SensorHistoryIterator object
function getIterator() {
    // Check device for SensorHistory compatibility
    if ((Toybox has :SensorHistory) && (Toybox.SensorHistory has :getHeartRateHistory)) {
        return Toybox.SensorHistory.getHeartRateHistory({});
    }
    return null;
}

// Store the iterator info in a variable. The options are 'null' in
// this case so the entire available history is returned with the
// newest samples returned first.
var sensorIter = getIterator();

// Print out the next entry in the iterator
if (sensorIter != null) {
    System.println(sensorIter.next().data);
}

Returns:

See Also:

Since:

API Level 2.1.0

getOxygenSaturationHistory(options as { :period as Lang.Number or Time.Duration or Null, :order as SensorHistory.Order } or Null) as SensorHistory.SensorHistoryIterator

Get the oxygen saturation history for the given period

This function always returns the most recent sensor history samples. The time between each `SensorSample` in the iterator may be device dependent.

Parameters:

  • options(Lang.Dictionary)

    Dictionary of options. Can be null.

    • :period(Time.Duration)

      The period of time from which to retrieve the samples:

      • If null, the entire available history is retrieved

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

      • If a Number, then the last specified Number of entries are retrieved

    • :order(Lang.Boolean)

      The order in which to retrieve the samples:

      • If null, the samples will be ORDER_NEWEST_FIRST

      • Use the ORDER_* enumeration to explicitly select ORDER_NEWEST_FIRST or ORDER_OLDEST_FIRST

Example:

Gets a SensoryHistoryIterator and prints out the Muscle Oxygen Saturation value from the most recent SensorSample

using Toybox.SensorHistory;
using Toybox.Lang;
using Toybox.System;

// Create a method to get the SensorHistoryIterator object
function getIterator() {
    // Check device for SensorHistory compatibility
    if ((Toybox has :SensorHistory) && (Toybox.SensorHistory has :getOxygenSaturationHistory)) {
        // Set up the method with parameters
        return Toybox.SensorHistory.getOxygenSaturationHistory({});
    }
    return null;
}

// Store the iterator info in a variable. The options are 'null' in
// this case so the entire available history is returned with the
// newest samples returned first.
var sensorIter = getIterator();

// Print out the next entry in the iterator
if (sensorIter != null) {
    System.println(sensorIter.next().data);
}

Supported Devices:

Returns:

See Also:

Since:

API Level 3.2.0

getPressureHistory(options as { :period as Lang.Number or Time.Duration or Null, :order as SensorHistory.Order } or Null) as SensorHistory.SensorHistoryIterator

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

This function always returns the most recent pressure samples. The time between each SensorSample in the iterator may be device dependent.

Parameters:

  • options(Lang.Dictionary)

    Dictionary of options. Can be null.

    • :period(Time.Duration)

      The period of time from which to retrieve the 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 specified Number of entries are retrieved

    • :order(Lang.Boolean)

      The order in which to retrieve the samples.

      • If order is null, the samples will be ORDER_NEWEST_FIRST

      • Use the ORDER enumeration to explicitly select ORDER_NEWEST_FIRST or ORDER_OLDEST_FIRST

Example:

Gets a SensoryHistoryIterator and prints out the pressure value from the most recent SensorSample

using Toybox.SensorHistory;
using Toybox.Lang;
using Toybox.System;

// Create a method to get the SensorHistoryIterator object
function getIterator() {
    // Check device for SensorHistory compatibility
    if ((Toybox has :SensorHistory) && (Toybox.SensorHistory has :getPressureHistory)) {
        return Toybox.SensorHistory.getPressureHistory({});
    }
    return null;
}

// Store the iterator info in a variable. The options are 'null' in
// this case so the entire available history is returned with the
// newest samples returned first.
var sensorIter = getIterator();

// Print out the next entry in the iterator
if (sensorIter != null) {
    System.println(sensorIter.next().data);
}

Supported Devices:

Returns:

See Also:

Since:

API Level 2.1.0

getTemperatureHistory(options as { :period as Lang.Number or Time.Duration or Null, :order as SensorHistory.Order } or Null) as SensorHistory.SensorHistoryIterator

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

This function always returns the most recent temperature samples. The time between each SensorSample in the iterator may be device dependent.

Parameters:

  • options(Lang.Dictionary)

    Dictionary of options. Can be null.

    • :period(Time.Duration)

      The period of time from which to retrieve the samples:

      • If null, the entire available history is retrieved

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

      • If a Number, then the last specified Number of entries are retrieved

    • :order(Lang.Boolean)

      The order in which to retrieve the samples.

      • If null, the samples will be listed ORDER_NEWEST_FIRST

      • Use the ORDER_* enumeration to explicitly select ORDER_NEWEST_FIRST or ORDER_OLDEST_FIRST

Example:

Gets a SensoryHistoryIterator and prints out the temperature value from the most recent SensorSample

using Toybox.SensorHistory;
using Toybox.Lang;
using Toybox.System;

// Create a method to get the SensorHistoryIterator object
function getIterator() {
    // Check device for SensorHistory compatibility
    if ((Toybox has :SensorHistory) && (Toybox.SensorHistory has :getTemperatureHistory)) {
        // Set up the method with parameters
        return Toybox.SensorHistory.getTemperatureHistory({});
    }
    return null;
}

// Store the iterator info in a variable. The options are 'null' in
// this case so the entire available history is returned with the
// newest samples returned first.
var sensorIter = getIterator();

// Print out the next entry in the iterator
if (sensorIter != null) {
    System.println(sensorIter.next().data);
}

Supported Devices:

Returns:

See Also:

Since:

API Level 2.1.0


Generated Nov 29, 2021 1:34:36 PM