Class: Toybox.SensorHistory.SensorHistoryIterator

Overview

A class containing sensor data for a given period of time.

The SensorHistoryIterator describes a sequence of SensorSample objects. The iterator is retrieved using the appropriate "get" methods found in SensorHistory at the module level. This class provides the methods needed to retrieve information from each of the SensorSample objects included in the iterator.

See Also:

Example:

Gets a SensorHistoryIterator object to be used with the below methods

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();

Since:

API Level 2.1.0

Instance Method Summary collapse

Instance Method Details

getMax() as Lang.Number or Lang.Float or Null

Get the maximum SensorSample data value contained in this iterator.

Example:

Print out the maximum SensorSample data value

using Toybox.SensorHistory;
using Toybox.System;
// Given a valid SensorHistoryIterator object, print out the
// maximum sample value entry in the iterator
System.println(sensorIter.getMax().data);

Returns:

  • Lang.Number

    The maximum SensorSample data value in this iterator

See Also:

Since:

API Level 2.1.0

getMin() as Lang.Number or Lang.Float or Null

Get the minimum SensorSample data value contained in this iterator.

Example:

Print out the minimum SensorSample data value

using Toybox.SensorHistory;
using Toybox.System;
// Given a valid SensorHistoryIterator object, print out the
// minimum sample value entry in the iterator
System.println(sensorIter.getMin().data);

Returns:

  • Lang.Number

    The minimum SensorSample data value in this iterator

See Also:

Since:

API Level 2.1.0

getNewestSampleTime() as Time.Moment or Null

Get the Moment of the newest SensorSample in this iterator.

Example:

Print out the Moment of the newest SensorSample

using Toybox.SensorHistory;
using Toybox.System;
// Given a valid SensorHistoryIterator object, print out the Moment
// of the newest sample entry in the iterator
System.println(sensorIter.getNewestSampleTime());

Returns:

  • Time.Moment

    The Moment of the newest SensorSample in this iterator

See Also:

Since:

API Level 2.1.0

getOldestSampleTime() as Time.Moment or Null

Get the Moment of the oldest SensorSample in this iterator.

Example:

Print out the Moment of the oldest SensorSample

using Toybox.SensorHistory;
using Toybox.System;
// Given a valid SensorHistoryIterator object, print out the Moment
// of the oldest sample entry in the iterator
System.println(sensorIter.getOldestSampleTime());

Returns:

  • Time.Moment

    The Moment of the oldest SensorSample in this iterator

See Also:

Since:

API Level 2.1.0

next() as SensorHistory.SensorSample or Null

Get the next SensorSample entry in the iterator.

This must be called to get the initial data from the iterator.

Example:

Print out the next SensorSample data value

using Toybox.SensorHistory;
using Toybox.System;
// Given a valid SensorHistoryIterator object, print out the next
// entry in the iterator
System.println(sensorIter.next().data);

Returns:

See Also:

Since:

API Level 2.1.0


Generated Dec 11, 2024, 8:58:43 AM