Compare OS version in Firmware

Is there a way to use System.version() or System.versionNumber() to use different code for releases?

I’d like to:
if (System.version() < 1.5.0) {do this}
else {do this}

I’m just not sure how I can compare the numbers using the above version numbers. Does anyone have any ideas?

Yes, you can. You’d just need to have a look at the datatype and format System.version() returns and use that.
But the common way would be to do that via compiler directives so that non-applicable code won’t even be compiled into the binary.

e.g.

#if (SYSTEM_VERSION == 0x01050000)
  // code only for this version
#endif

@ScruffR thanks is there a way to compare the System_version? I’d like all versions less than 1.5.0 run a little differnetly because of the new Sleep2.0 and PMIC overide setting.

Will this expression still work?

#if (SYSTEM_VERSION >= 0x01050000)
  // code only for newer versions
#else
  // code for older versions
#endif

It should - why not just try?
However I’d rather go with < 0x01050000 to activate sleep 1.0 as you don’t know what future versions will bring, but you know what previous and current versions do.

1 Like

I gave it a try and it seems to work. I’ll use your suggestion though!

1 Like