FitContributor: setData array

Hello ConnectIQ community,

I need to log the raw accelerometer values for developing offline an algorithm. I was thinking that using the FitContributor fields approach with array was good but... it does not work

// The field creation, 8 samples expected
_zImuField = session.createField("IMU z raw", 99, 
                                        FitContributor.DATA_TYPE_SINT32, 
                                        {:count => 8, :units=>"mg"});
                                        
// The setData in another function
_zImuField.setData(sensorData.accelerometer.slice(0, 8));

But in the Fit file with the simulator, it only contains a single value, the 1st one of the sensorData.

But in the Fit file with the device, it crashes with "Cannot convert object to Long" on the setData call.

Can anyone explain me why ? it seems to be an issue reading the doc but...

Setup:

device Garmin Fenix6

fw version: 23.1

SDK: 4.1.7

Thanks for your help / ideas Slight smile

  • TL;DR the FIT protocol supports array types, but they aren't exposed in the CIQ SDK, and even if you could write an array type (e.g. by manually specifying the integer value for the corresponding type), Garmin Connect probably wouldn't be able to render your data.

    So this is a really great question imo. I had a very similar question when I started dabbling in CIQ development a few years back: "Why do the docs say that the FIT field's count property applies a string or an array, but there's no reference in the docs to an array data type?"

    Just for the benefit of anyone else reading this:

    [https://developer.garmin.com/connect-iq/api-docs/Toybox/ActivityRecording/Session.html#createField-instance_function]

    Note the the available data types in the CIQ documentation (the values range from 1 to 9):

    [https://developer.garmin.com/connect-iq/api-docs/Toybox/FitContributor.html#DataType-module]

    No mention of array types. Of course you might guess, like I once did, that if you set count to > 1, that turns a scalar value into an array. But as you've found, nope.

    But if we go to the FIT protocol docs, we see a bunch of types that aren't in the CIQ docs:

    [https://developer.garmin.com/fit/protocol/]

    Maybe if you hardcoded a type of 13, you could write an array of bytes, but I'm pretty sure Garmin Connect (the website and the app) wouldn't be able to render it. (Could be wrong tho)

  • Hi FlowState.

    Many thanks for a such clear answer. I tried with 13 but it does not work, not compiling, and if forced to the right type, fails at call. 

    Do you have a good suggestion to be able to log the accelerometer in raw instead of using FitContributor so ?

    Have a nice day !

  • Do you have a good suggestion to be able to log the accelerometer in raw instead of using FitContributor so ?

    Well I would suggest logging to 8 fields haha except you have no guarantee that the writes will be synchronized, so your data could be junk. (EDIT: I mean I don't see any reason why they wouldn't be -- since setData() just sets the next value to be written, as opposed to actually writing anything, I assume that if you called setData() on multiple fields within the same CIQ execution context, then eventually either every field will be written with those values or none at all, but I wouldn't bet my life on it.)

    If it's just for your own personal use (as you mentioned), you could try logging to a text file:

    https://developer.garmin.com/connect-iq/core-topics/debugging/

    Basic Debugging

    One way to test Connect IQ apps is to include System.println() statements at strategic points in your app. Within Visual Studio Code, these println() statements will output to the console. On a device, println() statements write to an <APPNAME>.TXT file in the /GARMIN/APPS/LOGS directory in the device file system.

    These log files are not automatically created, so they must be manually created on the device and named to match the name of the app’s corresponding PRG file. For example, to log output from /GARMIN/APPS/MYAPP.PRG, you must create /GARMIN/APPS/LOGS/MYAPP.TXT.

  • Hi FlowState,

    Thanks for your answer, that's I was already using so...

    Have a nice day