What kind of value is left_right_balance?

I am working with the FIT SDK since some weeks now, and since some days I own a power meter on my road bike. Power data in the decoded fit file is pretty straightorward, but what kind of value is "left_right_balance"? In Profile.xlsx I can see is should bei "% contribution", but I cannot interpret values like "178" as a percentage ...

  • The data type of the record message left_right_balance field is the enum type left_right_balance. If you look at the types you will find the definition for it. 


    The left_right_balance type has two values, both of which are masks that are used to interpret the data.:
    mask = 0x7F and is the % contribution
    right = 0x80 and indicates if the data corresponds to right if set, otherwise unknown

    The most significant bit indicates if the value is for the right or left side. The seven least significant bits are the value.

    is_right_side = (record.left_right_balance & left_right_balance.right) == left_right_balance.right
    percent = record.left_right_balance & left_right_balance.mask

    Using 178 as the value

    is_right_side = ((178 & 0x80) == 0x80) == true
    percent = (178 & 0x7F) = 50%

    The left_right_balance values are defined in each of the SDKs, so you don't need to hard code 0x80 or 0x7F in your code.
  • Thanks for your answer! That is pretty weird. Usually the decoded values are ready to use (well, more or less, except for the GPS data noted in semicircles), but not this value. What do you mean by "The left_right_balance values are defined in each of the SDKs, so you don't need to hard code 0x80 or 0x7F in your code"? I use the JS SDK, and in the decoded messages I do find 178 and not 50. 

  • Everything that is listed in the Profile.xlsx spreadsheet is also defined in each SDK. There is a Profile dictionary exported from the JavaScript SDK that has the types in them. 
    https://developer.garmin.com/fit/example-projects/javascript/ 

    It is expected that the value will be 178. You need to check the most significant bit to see if the value applies to the left side or the right side, ie which leg does the percentage apply too, and then use the 7 least significant bits as the value itself. Follow the example above and you will have the value that you are looking for. 

    With the JavaScript SDK you might find it easier to define your own constants for the mask (0x7F) and the right side indicator (0x80) and then use those constants in the formulas above.