Activity Info

Former Member
Former Member
Hi Guys,

Attempting to programming the vivoactive again, this time I am wanting to update some values from Activity. I cannot for the life of me workout why the following section of code does not work.


function onUpdate(dc) {

var activityInfo;
activityInfo = Act.getActivityInfo();
if ( activityInfo != null && activityInfo.elapsedTime != null ) {
dc.drawText( pt2_x, pt2_y, Gfx.FONT_MEDIUM , activityInfo.elapsedTime.toString(), Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
}

if ( activityInfo != null && activityInfo.elapsedDistance != null ) {
dc.drawText(pt6_x, pt6_y, Gfx.FONT_LARGE , activityInfo.elapsedDistance.toString(), Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
}

if ( activityInfo != null && activityInfo.currentSpeed != null) {
dc.drawText(pt5_x, pt5_y, Gfx.FONT_LARGE , activityInfo.currentSpeed.toString(), Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
}


}


The currentSpeed is displayed fine, elapsedTime is always displayed as zero and elapsedDistance is never displayed at all. If I run it in the simulator all fields are updated just fine. The only thing I can be thinking is, I have somehow missed how the Activity works or elapsedTime/elapsedDistance fields don't work when using Act.getActivityInfo() ??

I have used elapsedDistance and elapsedTime in a simpledatafield on the onCompute function and it works fine in there, so I am really at a loss here. Can anyone tell me what I am doing wrong?
  • I'm not 100% certain of this, and I'm away from my coding box so I can't verify... I think the problem is that when you're implementing a data field, there is an active activity (and the Activity.Info is valid and filled in by the device). When you are implementing an app or widget, you need to get the data from somewhere else (the Sensor module), or you need to start an activity recording session.

    I'll do some testing on my 920 when I get home this evening to verify I'm not totally full of it.

    Travis
  • Former Member
    Former Member over 10 years ago
    I'm not 100% certain of this, and I'm away from my coding box so I can't verify... I think the problem is that when you're implementing a data field, there is an active activity (and the Activity.Info is valid and filled in by the device). When you are implementing an app or widget, you need to get the data from somewhere else (the Sensor module), or you need to start an activity recording session.

    I'll do some testing on my 920 when I get home this evening to verify I'm not totally full of it.

    Travis


    Ok, I will also experiment, but I just found it strange that one of the fields works and the other two don't. The Sensor module does not seem to return any info from the Activity Info though, it seems to be it's own little thing. Now that I have the ability to record, I will add that code and see whether it makes any difference I guess. I think you are probably correct, and I think it makes sense that the Activity Info for elapsedTime and distance will only be valid when the watch is actually recording. Current speed works fine because it does not matter whether the activity is recording or not. elapsedTime and Distance the activity obviously needs to be running for them to be working.

    Will report back.
  • I think Travis is right. It acts like you are not starting the activity. I start/stop the activity in the view delegate with the following code.

    If I don't start the activity, it shows speed, but nothing for distance and 0 for elapsed time. When I start the activity, then the elapsed time runs and the distance is shown.

    else if (evt.getKey() == Ui.KEY_ENTER)
    {
    if (mActivity.isRecording() == false)
    {
    mActivity.start();
    mView.setBtnPress(START);
    if( Att has :playTone )
    {
    Att.playTone(Att.TONE_START);
    }
    if( Att has :vibrate )
    {
    Att.vibrate(mVibeShort);
    }
    Ui.requestUpdate();
    }
    else if (mActivity.isRecording() == true)
    {
    mActivity.stop();
    mView.setBtnPress(STOP);
    if( Att has :playTone )
    {
    Att.playTone(Att.TONE_STOP);
    }
    if( Att has :vibrate )
    {
    Att.vibrate(mVibeShort);
    }
    Ui.requestUpdate();
    }
    }
  • Former Member
    Former Member over 10 years ago
    Thank you. I will experiment with that now :) I think it will be fine now. The recording code never worked before because it was not functioning in the previous firmware.
  • Former Member
    Former Member over 10 years ago
    I think Travis is right. It acts like you are not starting the activity. I start/stop the activity in the view delegate with the following code.

    If I don't start the activity, it shows speed, but nothing for distance and 0 for elapsed time. When I start the activity, then the elapsed time runs and the distance is shown.


    MoxyRoger, I noticed today on my watch when I start a session, that my vivoactive automatically vibrates. With your code above, would it vibrate twice? I am just wondering what the default case is for different watches.
  • Garmin,

    I can't find exactly what the intended functionality is supposed to be with respect to native vibes, tones, and graphics response from button pushes and activity start/stop/lap/save/discard in Apps. The table below shows what I observe. I'm not 100% sure which tone is which so I made a few assumptions on what I'm hearing. There's quite a few instances of the watch acting different than the simulator so maybe that could get cleaned up at some point.

    It would be nice-to-have the activity start and stop calls also put up the native green arrow and red square graphics (just like the addLap call puts up the native lap screen) so they don't need to be programmed separately. The way it is, it kind of does some of the native functions like tones and vibes, and some of the native graphics like the lap screen, but not everything so it's a bit unintuitive.

    It's a bit more complicated, but having the native response to save and discard would save some programming too.

    Jason,
    On the 920, I have it programmed to vibrate and play a tone in addition to what it does from just the activity session call itself (like in the code above). I don't get double tones or notice double vibrates, but it does look like I could take the tones and vibrates out of my code since they would happen anyway on the watch.

  • @MoxyRoger: I've submitted your suggested to be considered. It looks like we need to have more consistency for keypress behaviors, and this points out a place we can bring the sim and devices closer together. I agree that it would be nice to use the native start/stop graphics (or at least make them available as an option).
  • Former Member
    Former Member over 7 years ago
    else if (evt.getKey() == Ui.KEY_ENTER)
    {
    if (mActivity.isRecording() == false)
    {
    mActivity.start();
    mView.setBtnPress(START);
    ...


    Hi MoxyRoger
    I'm with the same problem as jason_75 and I wonder what is mActivity in your code ? a session created with .createSession(...) ? anything else ?

    Sylvain

  • Sylvain - that's what it looks to me. What you get with createSession.

    If your problem is not seeing things in Activity.Info, a number of those fields with be 0 or null, until you do a start() on the session. Elapsed time starts at the first time start() is called, and continue to increase until you save or discard the session. For elapsedDistance, until you start recording, that will be zero/null (I forget which)

    calling stop() will pause the recording, and it can be "resumed" by calling start() another time.

  • I'm with the same problem as jason_75 and I wonder what is mActivity in your code ? a session created with .createSession(...) ? anything else ?


    Yes, from a createSession

    using Toybox.ActivityRecording as Arc;

    ???????mActivity = Arc.createSession({
    :sport => Arc.SPORT_CYCLING,
    :subSport => Arc.SUB_SPORT_GENERIC,
    :name => "cycling"
    });