checking for firmware version

Posted on
  • I have written the following function to check for firmware greater than X.Y.Z but its a bit messy.
    Wondering if there is a better way.

        function checkFirmware(maj,min,bld) {
          var major = process.env.VERSION.split(".")[0].split(­"v")[0];
          var minor = process.env.VERSION.split(".")[0].split(­"v")[1];
          var build = process.env.VERSION.split(".")[1];
          if (major > maj) return true;
          if (major == 2 && minor > min) return true;
          if (major == 2 && minor == min && build >= bld) return true;
          return false;

    And then in the App...

          if (!checkFirmware(2,8,187)) {
            g.drawString("E-FW", 120, Y_ACTIVITY);

    Also was thinking that the format of the firware version string is a bit odd.
    Why not use instead of major. "v0" ?

  • Wondering if there is a better way.

    well, calling process.env.VERSION.split(".") three times is a waste
    ther are also regular expressions­p

  • Well, if it works then I guess that's fine. It doesn't have to be too speedy.

    If at all possible I'd check based on the actual feature though? I mean, if you need Bangle.isGPSOn then check for Bangle.isGPSOn!==undefined.

    You could maybe also do something like turning 2v08.123 into 2.080123 and could just compare based on that? You just need to ensure you pad out the number after the '.' correctly.

  • is the build number important for any check? I guess it is nice to show it somewhere so you know which one you have but expecting some functionality in the code based on that number feels wrong to me. Well even checking the minor/major version is not ideal, why not to check for specific functionality?

  • Yeah the code code be improved, it was more the concept I wanted to discuss. Good point about Bangle.isGPSOn!==undefind thats a much better idea, no hard coding of version numbers etc.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

checking for firmware version

Posted by Avatar for HughB @HughB