Guest post 0: tackling Connect IQ versions, screen shapes and memory limitations (the resource override version)

Last year I made a first version of the article that now appeared on the Garmin developer blog, jungles did not exist yet back then, so I was using resource overrides to solve the same problem. Nowadays I’d advise you to go for the jungle approach as it provides greater flexibility, yet this version of this article might still be useful to as it shows how to use resource overrides in Monkey C code. When you read the guest post that was posted on the Garmin developer blog, you should notice many similarities, both versions of the code are available from my github account… 🙂

Garmin devices come in different shape and sizes, have different memory constraints, and have different levels of Connect IQ compatibility. To be able to maintain different Connect IQ devices you can use the has functionality to test whether a certain feature is present on the device, but applying this technique too much makes the code unmanageable. You could also set up a Connect IQ project per device and copy/paste your code across your projects, but this is very labor intensive to keep your code in sync and is prone to mistakes.

Using one code base to handle all Garmin devices compatible with Connect IQ is easier than you think. All you have to do is combine three core features of the Connect IQ framework: inheritance, resource overrides, and file excludes. Let’s see how these features help you to solve the issues that held us back.

Screen Geometry

One way to solve different size/shape issues is to use the layout system. This works perfect for watch faces as you have a lot of memory available there. In data fields, the memory budget is usually tight and as the layout system has a higher memory requirement, I got used to opting for using direct drawing on the dc object instead. I want to have the same benefits as the layout system though, as I might want a different layout on each device.

So how do we do this?

  • Define a base class CommonLogicView where we handle all logic that we have to do on each device.
  • Define a class called DeviceView for each device that we want to support. This DeviceView inherits from the CommonLogicViewand implements the layout specifics for each device by drawing to the dc
  • For each device create a build resource exclude where you exclude all other device class implementations. Let’s say that you’re trying to build for the original vivoactive and the Forerunner 735XT. These two products have different screen geometry and support different versions of Connect IQ. The picture below shows how the project will look like after this has been set up:

  • Folder structure

    The resources/fr735xt file excludes are defined in sources.xml. We simply specify which code files we do NOT want in the build for this device. We apply a similar tactic for each device we implement:

    The CommonLogicView is the base view. Here we handle all code that we can use in all the device implementations. It’s a pretty easy class, the main entry point into this class is the onUpdate function:

    The DeviceView is where we implement the specifics of the device, so for the Forerunner 735XT we could have something like this:

    For the vivoactive we have a similar file, but then implementing the specifics of the vivoactive:

    When we run the code this results in the following in the simulator:

    simulator view

    Full Source Code

    Memory Constraints

    The Forerunner 235 and Forerunner 735XT are both semi-round, but they have different memory limitations. For instance, in data field mode, the FR235 allows for 16K of memory, while the FR735XT has 26K of available memory to play with. That means we can pack 10K more goodies in the 735XT data field!
    To do this we apply the same technique of combining inheritance, resource overrides and file excludes, just adding one layer of extra inheritance does the trick:

    adding a memory layer

    In my Peter’s (Race) Pacer app I’m taking this technique to the extreme and have 4 layers of inheritance defined: CommonLogic, LayoutLowMemory, CommonHighMemoryLogic, and LayoutHighMemory.

    All layers inherit from each other so that I don’t have to write a single letter of duplicate code. This allows me to support all combinations of Connect IQ 1.x and 2.x devices from a single code base, while getting the max out of the available memory for each device!

    2 Layouts

    Connect IQ Version Compatibility

    We are treated with more and more features being added to the Connect IQ framework. Older devices can not be upgraded to Connect IQ 2 because they don’t have enough processing power and/or memory available. Luckily we can apply the same technique of combining inheritance and file excludes to be able to use new Connect IQ 2 features in our projects while simultaneously also retaining support for users that have Connect IQ 1 devices. Cool, eh?

    Let’s demonstrate this with a sample project. I’m going to extend the watch face with the ability to pull “to do” lists from a web-service via a background process, while at the same time we continue to support Connect IQ 1 devices. Of course the functionality on the Connect IQ devices will remain the same as before the changes as there is no alternative to background services in Connect IQ 1.x.

    We open our project from before and add the Connect IQ abstraction layer, this is the one I’ve defined for Connect IQ 1:

    A very similar class we add for the Connect IQ 2 devices, looks quite similar, only difference being that we’ll pick up the message from the application class:

    In addition we change the DeviceView to show the message variable and in the resource file excludes exclude either the or

    We’ve also duplicated the application layer level. The Connect IQ 1 version is pretty straightforward (you can have a peek at the source on github). The Connect IQ 2 version is slightly more complex as we’ll implement a background service to fetch from a webservice here (trimmed for readability):

    The service delegate is the main entry point for the background service, inside we’ll fetch a random to do item from the web-service.

    Full source code

    Hope you’ll like this technique!
    Happy coding!


    Did you like this article?Questions?
    • Post in the comments section below!

Leave a Reply