FitContibution: Call setData for unchanged data?

Hello,

I have a value that is read from a device via BLE (every second), but that is not changed every second (it is based on user interaction).

Now I'm wondering if I should just call `setData` and let this method take care of whether the value is changed before writing it to the FIT file, if I should take care not to write unchanged data, or even if Garmin creates an entry every second even when `setData` has not been called.

The documentation is unclear on this point:

Best practice is to only call setData() when values have changed to accommodate Smart Recording.

But Smart Recording is a feature of the Garmin device, so I guess `setData` takes care about changed values!?

If `setData` doesn`t care about this, I will store the previous value in my code and only call the method if the new value differs, but if the `setData` method cares about this, I can save this overhead in my code. Does anyone know how this behaves?

Many regards,
Jens

  • You're right, the line of the documentation that you quoted is unclear, and it doesn't really reflect how some of the recording samples in the SDK are coded.

    Now I'm wondering if I should just call `setData` and let this method take care of whether the value is changed before writing it to the FIT file, if I should take care not to write unchanged data, or even if Garmin creates an entry every second even when `setData` has not been called.

    Just call setData() unconditionally, IMO. With one exception (*), setData() never causes data to be written, it sets the next value to be written, and the firmware decides when to write.

    (*) The sort of exception to this rule is that before you call setData() for the first time, no data will be written. Once you call setData() for the first time, that causes data to be written for the first time. e.g. If you call setData() for the first time five minutes into the activity, then the FIT graph will be blank until that point.

    Obviously I don't know your code, but it seems simpler to just call setData() unconditionally, as opposed to storing the previous value and checking to see if the current value differs.

    Another thing to note is that if you are writing session or lap data, you have to call setData() *before* the lap is triggered or the session ends. For example, it's too late to write lap data in onTimerLap().

    The usual way to do this is to call setData() lap data and session data *all the time* (e.g. once per second), even though the actual values will be written far less frequently. (You can see this is the SDK MoxyField sample app, which has FIT recording.)

    (However, another way to handle writing session data is to call setData() in onTimerStop(), since the user has to stop an activity before saving it.)

  • Having said all that, I never use smart recording on my watch, so I don't know what the effect of calling setData() all the time would be in that case. For all I know, it could work the way the documentation says. Only way is to try it out, I think.

  • According to my testing it works both ways. I think the only difference is the generated fit files's size if you're on every-second recording. But I don't see any difference in the graphs.

    BTW at the beginning I had a condition to only call setData when the value has changed and later I removed it to shrink the code size.

  • According to my testing it works both ways. I think the only difference is the generated fit files's size if you're on every-second recording. But I don't see any difference in the graphs.

    Thanks for confirming that. That's exactly what I would've assumed, but of course, as OP pointed out, it means the docs are wrong, or at the very least, misleading. Not the first time.

  • Doc is very strange if I follow it and save only when something change user won't see values according watch's settings (Smart recording = off).