Duration in heart rate history iterator does not work

This statement:
return SensorHistory.getHeartRateHistory({:order=>SensorHistory.ORDER_NEWEST_FIRST, :period=>new Time.Duration(4 * Time.Gregorian.SECONDS_PER_HOUR)});


leades to following failure message:
UnexpectedTypeException: Expected an object of type Time.Duration
native function
  • Are you seeing this on a device or in the simulator, and which versions are you using?

    I took some time to write up a test case, but I'm unable to reproduce (in the simulator using the 2.3.4 SDK)...

    using Toybox.Application as App;
    using Toybox.Graphics as Gfx;
    using Toybox.WatchUi as Ui;
    using Toybox.System as Sys;
    using Toybox.Lang;
    using Toybox.SensorHistory;

    class TestView extends Ui.DataField {

    function initialize() {
    DataField.initialize();
    }

    hidden const sensors = {
    "HeartRate" => :getHeartRateHistory,
    "Temperature" => :getTemperatureHistory,
    "Pressure" => :getPressureHistory,
    "Elevation" => :getElevationHistory
    };

    hidden var current_sensor = 0;

    function getSensorHistoryName() {
    return sensors.keys()[current_sensor];
    }

    function getSensorHistoryIterator(options) {
    var symbol = sensors.values()[current_sensor];
    if (Toybox.SensorHistory has symbol) {
    var callback = new Lang.Method(SensorHistory, symbol);
    return callback.invoke(options);
    }

    return null;
    }

    function onUpdate(dc) {
    dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_BLACK);
    dc.clear();

    var display_name = getSensorHistoryName();
    var iterator = getSensorHistoryIterator({
    :period => new Time.Duration(1 * 3600),
    :order => SensorHistory.ORDER_NEWEST_FIRST
    });

    var display_value = null;
    if (iterator != null) {
    display_value = iterator.getMax().format("%2.1f");
    }

    var cx = dc.getWidth() / 2;
    var cy = dc.getHeight() / 2;
    cy -= dc.getFontHeight(Gfx.FONT_SMALL);

    dc.drawText(cx, cy, Gfx.FONT_SMALL, display_name, Gfx.TEXT_JUSTIFY_CENTER);

    if (display_value != null) {
    cy += dc.getFontHeight(Gfx.FONT_SMALL);
    dc.drawText(cx, cy, Gfx.FONT_NUMBER_MEDIUM, display_value, Gfx.TEXT_JUSTIFY_CENTER);
    }

    current_sensor = (current_sensor + 1) % sensors.size();
    }
    }

    class TestApp extends App.AppBase {

    function initialize() {
    AppBase.initialize();
    }

    function getInitialView() {
    return [ new TestView() ];
    }

    }


    Travis
  • Former Member
    Former Member
    Can anyone comment on the status of this bug.
    I have the same issue with SDK 2.4.1 in the simulator

    var elevationHistory;
    var historyDuration = new Time.Duration(300);
    elevationHistory = Toybox.SensorHistory.getElevationHistory({:period => historyDuration});


    throws an exception: Expected an object of type Time.Duration

    but
    var elevationHistory;
    elevationHistory = Toybox.SensorHistory.getElevationHistory({});


    does not.
    Interestingly, it worked when I started coding the iterator function in my app but then all of the sudden it stopped.

  • I tried to reproduce this again using the code you provided above pasted into my AppBase derived class...

    using Toybox.Application as App;
    using Toybox.WatchUi as Ui;
    using Toybox.Graphics as Gfx;
    using Toybox.Time as Time;


    class TestView extends Ui.View
    {
    function initialize() {
    View.initialize();
    }

    function onUpdate(dc) {
    dc.setColor(Gfx.COLOR_RED, Gfx.COLOR_BLUE);
    dc.clear();
    }
    }

    class TestApp extends App.AppBase
    {
    function initialize() {
    AppBase.initialize();


    var historyDuration = new Time.Duration(300);
    var elevationHistory = Toybox.SensorHistory.getElevationHistory({:period => historyDuration});
    }

    function getInitialView() {
    return [ new TestView() ];
    }
    }


    I was unable to reproduce the failure. The code I provided previously (see above) tests each of the history functions and passes a duration in the period value, and I still have no problems with that test case either.

    Since I can't reproduce the problem, I'm reluctant to file an issue.

    If you could provide a complete test case that demonstrates the problem (you can e-mail it to [EMAIL="[email protected]"][email protected][/EMAIL]), I'd be more than happy to investigate and file an issue if appropriate.

    Travis
  • Former Member
    Former Member
    Hi Travis,

    thanks for the input. I tried to reproduce it with your code but was not able to do so.
    Now even in my own app it does not appear anymore. I will post again if I find out more...
  • Former Member
    Former Member
    xlr8t

    Thanks for the report back. Please do let us know if you encounter this bug again. For now I'm going to close this thread as there will likely be a new set of conditions needed to repro and test if a new bug occurs. Thank you!

    -Coleman