Welcome to Connect IQ 4.0

At the Garmin Developer Virtual Conference this year, we shared some of the new features coming to Connect IQ 4.0 and also released a preview of the new Visual Studio Code extension. Today we have released a first preview of the Connect IQ 4.0 SDK. Let’s dive a little deeper into the new features you can expect from Connect IQ 4.0.

Monkey Types

Monkey Types is the new gradual type system for Monkey C, and this release has the first developer preview of the feature. Monkey Types is turned off by default for language compatibility, but you can turn it on by going to the compiler options settings in Eclipse or Visual Studio Code and adding ‘-l 1’.

As an example, here is a watch face onUpdate function using Monkey Types:

    // Update the view
    function onUpdate(dc as Dc) as Void {
        // Get and show the current time
        var clockTime = System.getClockTime();

        var info = System.getDeviceSettings();
        var hour = clockTime.hour;

        if(!info.is24Hour) {
            hour = hour % 12;
            hour = (hour == 0) ? 12 : hour;
        }

        var timeString = Lang.format("$1$:$2$", [hour.format("%02d"), clockTime.min.format("%02d")]);
        
        _timeLabel.setText(timeString);

        var date = Gregorian.info(Time.now(), Gregorian.FORMAT_SHORT);
        var dateString = Lang.format("$1$/$2$/$3$", [(date.month as Number).format("%02d"), date.day.format("%02d"), date.year.format("%02d")]);
        _dateLabel.setText(dateString);

        // Call the parent onUpdate function to redraw the layout
        View.onUpdate(dc);
    }

If this looks remarkably like what you’re used to, that’s the point. Monkey Types uses type-inferencing to identify types when possible, and it will only type-check what it knows about (including the API). It does require function arguments, return values and member variables to have typing information added using the “as” keyword.

The “as” keyword also does double-duty as the casting operator, which you can see on this line:

var dateString = Lang.format("$1$/$2$/$3$", [(date.month as Number).format("%02d"), date.day.format("%02d"), date.year.format("%02d")]);
        _dateLabel.setText(dateString);

The reason we need to cast month is that it can be a Number or a String, but only a Number has the format method. Monkey Types can see that without having to cast date as a Gregorian.Info.

We think Monkey Types will make it much easier to find type errors. It also does not add any runtime cost and will work for code for all Connect IQ devices. We reserve the right to change the grammar or behavior, so don’t make any irreversible changes to your code based on this preview. Look in the Monkey C section of the documentation included in the SDK for more information.

Resource Compiler Updates

Traditionally, Garmin wearables have featured always-on displays, but limited color palettes to utilize for your Connect IQ apps. That all changed with the Venu®, which introduced the first AMOLED display for a Garmin wearable. We’ve brought a few changes to Connect IQ 4.0 to make it easier for you to support the wide range of displays in Connect IQ.

First, the resource compiler now supports SVG as a standard import format. SVG is a popular vector format that is supported by a number of vector editing programs. SVGs are importable using the bitmap tag, which makes it easier to import complex vector imagery that scales across multiple products.

Speaking of scaling, the bitmap tag also supports three new options for scaling a bitmap on import:

Attribute

Value

Notes

scaleX

Pixel value or Percent

Can be independent of scaleY. If scaleY is set but not scaleX, will assume scaleX = scaleY

scaleY

Pixel value or percent

Can be independent of scaleY. If scaleY is set but not scaleX, will assume scaleX = scaleY

scaleRelativeTo

“screen” or “image”

If scaleX or scaleY is a percentage, will compute the percentage relative to the screen resolution or the image resolution

For example, if you want an image to be your header and take up the top 10% of the screen, you can use the syntax:

<bitmap filename="example.svg" id="example" scaleY="10%" scaleRelativeTo="screen" />

This will perform image scaling to account for the different watch face sizes on a vívoactive® 4s and a Venu. When combined with SVG, this makes it much easier to make layouts that scale across products.

Get the Preview

You can get the Connect IQ 4.0 preview SDK today using the Connect IQ SDK Manager (make sure you have version 1.0.2 of the SDK Manager). We have a sample on Github that demonstrates Monkey Types.

If you have any feedback on these new features, we’d love to hear it. Please drop us a line in the forums so we can see what you think.