Is DataField.compute() actually called once per second?

The docs indicate that Toybox::WatchUi::DataField.compute() is called once per second. In testing with simulated data, it looks like it is called every ~1015ms. If I load up a .fit file generated with once-per-second recording, then I get data consistently at 1000ms.

Given this, it seems safest for an application to assume that compute() is called approximately once a second and track the elapsed time to ensure calculations are correct. Is this right?

On a related note, there are typically three measures of time when dealing with recorded data. There are wall clock time, moving time, and elapsed time. I'm certain that the former comes from System.getClockTime(), and the latter is available via Activity::Info.elapsedTime. Unfortunately, it isn't clear what System.getTimer() is. Additionally, it seems that the application needs to calculate moving time if it is needed since it isn't available via the API?
  • Former Member
    Former Member over 10 years ago
    The compute function should be called at exactly 1/second. I will try to correct the drift issue you noticed in the simulated data.

    The event should be precise enough on devices that attempting to compensate your calculations would be wasted effort.

    System.getTimer() returns a free running ms timer from the system. This is not related to data recording at all.

    The Activity module currently exposes 3 times from the activity. These are startTime (date/time of the start of the activity), elapsedTime (Time since the start of the activity), and timerTime (The stopwatch time on the device). If the stopwatch has not been stopped during the activity, elapsedTime and timerTime will be identical. Currently it is not possible to start and stop the timer on the simulator, and the FIT file parsing does not read timer events from the file, so these values will always match.

    Moving time is a post-processed metric that is computed by Garmin Connect, and is not available on the device.
  • So, just to be clear, I don't need to keep track of the last time that compute() was called and calculate the actual elapsed time, since my application will get called back exactly once a second? In that case, what happens if some other application sucks up a bunch of cycles before my code gets a slice?
  • Former Member
    Former Member over 10 years ago
    It is certainly possible that execution could get delayed occasionally, but my opinion is still that "the event should be precise enough on devices that attempting to compensate your calculations would be wasted effort".

    Much of the data provided from the system in the Activity.info object is only updated one time per second by the system.
  • I am developping a complex data field on a fenix 3 (OK it's an old product). It displays up to eight values on screen and draws three graphs, it stores several lists of data history (distance, altitude, hr, power, vertical speed). As I get some strange results on the watch, I integrate the display of the called interval, and I see that the data field is called 1/1400ms.

    This is why some of my results are wrong: I assume a 1/second call!

    To correct this I will have to store the elapsed time.

    Do you think it can be a problem for the behavior of the watch for recording the activity?