How to Develop Wearable Apps with Connect IQ


Developing on wearable platforms is new and challenging. An app developer is asked to create a dynamic user experience on small screens that compares to what customers see on their mobile phones and web pages, keeping additional concerns in mind as well.

Connect IQ combines three W’s:

  1. Wear - Garmin’s experience in power management, activity tracking and ANT or ANT+  sensors means users will spend more time wearing the product and less time charging it.
  2. Where - Location awareness is at the center of Garmin products. They don’t become dead weight without a smartphone connection, but become more alive with one.
  3. Ware - Garmin’s new Connect IQ app system allows for developers to extend their apps into the Garmin wearable ecosystem.

Connect IQ products provide the best of what Garmin has to offer. Using the Connect IQ SDK, developers can create apps for Connect IQ devices and distribute them via the Connect IQ Store.

The language Garmin created from the ground up that is behind the Connect IQ platform is called Monkey C.  Monkey C is an object-oriented language, designed for easy app development on wearable devices. The goal of Monkey C is to round the sharp edges of making a wearable app, letting developers focus more on the customer and less on resource constraints. It uses reference counting to automatically clean up memory, freeing you from focusing on memory management. In addition, the resource compiler helps you import fonts and images to easily convert them between devices.

If you’ve worked with dynamic languages in the past like Java, PHP, Ruby, or Python, Monkey C should be very familiar.

Devices and APIs

The issue of API Fragmentation is a challenge for app developers. If a developer takes advantage of new APIs, newer devices with less customer penetration may be targeted. On the other hand, if only established APIs are used, apps may not take advantage of new capabilities.

Unlike cell phones, Garmin devices are all wildly different from each other: round screens versus square screens, touch displays versus buttons and a different array of sensors depending on device purpose. While the Java philosophy of “write once run anywhere” is a notable goal, creating a universal API that crosses every Garmin device would inevitably lead to a lowest common denominator API.

Rather than attempting to abstract away differences in devices, Connect IQ APIs are tailored to the devices on which they run. If a device has a magnetometer, the device should have available the Magnetometer API. If two devices each have a magnetometer, the API should be the same between them. If a device does not have a magnetometer, it will not provide that API.

The Tao of Connect IQ

There is a rhyme and reason behind Monkey C to make it easier for developers to support the Garmin ecosystem of products:

1. The developer chooses what devices to support

Connect IQ apps can run across multiple devices, but the intended devices are up to the developer. Not every device will be aimed at the markets the developer wants to target nor will every device provide the experience the developer wants to provide. In short, the developer will not be forced to support devices they don’t want to.

2. The developer tools should help developers support multiple devices

The developer tools lessen the weight of supporting multiple devices. The Resource Compiler hides device specific palettes and orientations from the developer. It also permits per device override of resources, allowing different images, fonts, and page layouts to be specified in the resources XML.

3. Similar devices should have similar APIs

Consider the example where two different watches may have different display technologies, but they both support bitmaps, fonts, user events, ANT/ANT+ and BLE. A developer writing a sports app should not have to completely rewrite their app to support multiple devices.

4. At runtime, the developer can ask what the system “has”

If an app makes a reference to an API that does not exist on a particular system, the app will fail at runtime when the app references the API, not at load time like C++. This allows an app to avoid making the call by taking advantage of the “has” operator.

App Types

There are four main use cases for third party developers to interact with the watch:

  • Watch Faces - These replace the main watch face and are the home screen of the watch.
  • Data Fields - Data fields run within Garmin activities. They allow developers to compute values based off of the current activity, such as running, biking, etc.
  • Widgets - Widgets are full screen pages that can be embedded into the main page loop. They are loaded when brought on screen and shut down when the user switches to the next widget.
  • Device Apps - Started from the action list, wearable apps can be used to implement use cases like third party activities, games and other user-initiated actions. Apps push a page onto the UI and exit when the user backs out of the last page of the page stack.

Using The Eclipse Plug-in

The Connect IQ Eclipse plug-in turns the Eclipse IDE into a Monkey C development environment. Its features include:

  • Syntax highlighting editor
  • Build integration
  • Integrated execution of applications in the Connect IQ simulator

The Connect IQ plug-in requires either the Standard Edition or IDE for Java Developers (either 32 or 64 bit) of Eclipse Luna. Once Eclipse is installed, install the plug-in with the following steps.

Installing the Eclipse Plug-in

1. In the top menu, go to Help > Install New Software:
2. Use the Add… button to add http://developer.garmin.com/downloads/connect-iq/eclipse/ :
3. Mark the check box next to Connect IQ in the list and hit Next:
4. Dependent plug-in modules may need to be downloaded and installed. When this is complete, restart Eclipse to complete the installation.

Configuring the Eclipse Plug-in

1. Next, the plug-in will need to know where to find the Connect IQ SDK. To set this, go to theWindow > Preferences menu (Windows), or to Eclipse > Preferences (Mac):
2. Click the Browse button and add the path to your Connect IQ SDK directory. Make sure it is referencing the root directory of the SDK and not the bin subdirectory.
3. Add the Connect IQ perspective to Eclipse by selecting Window > Open Perspective > Other…and then select Connect IQ:

Generating a Developer Key

The Connect IQ compiler requires a developer key be provided to for signing when compiling and packaging apps. The required key must be a RSA 4096 bit private key.

Note: It’s important to keep track of the key you use to sign app packages. You will need to use the same key to sign updates to an existing app on the store. If you lose your original signing key you will not be able to update your app.

There is a key generation utility built into the Eclipse Plug-in. The tool can be accessed through the compiler preferences page (Preferences > Connect IQ > Compiler). Clicking the Generate button will open the wizard. Set the output path in the wizard and click Finish.

The developer key specified in the Connect IQ compiler preferences will automatically be passed to the compiler when a project is compiled.

Creating Your First Project

1. Click the File menu, and choose New > Project
2. Select ‘Connect IQ Project’ and click Next to continue:
3. Enter a name for your project (for this example, use “BabyFace”) and click Next:
4. Set the project type to Watch Face
5. Check the Square Watch and Round Watch target platforms, leaving the minimum SDK version at the default, and click Next:
6. Select the Simple template, upon which the project will be based:
7. Select English as the supported language, and click Finish:

Eclipse will create the project and move to the Connect IQ perspective. Once the project is initialized, the following project elements will be created automatically:

bin
Contains binary and debug output from the app compilation

resources
Inputs to the resource compiler, such as layouts, images, fonts, and strings, and language-specific resources

source
Contains the Monkey C source files, initially broken into ‘App’ and ‘View’ files

manifest.xml
Application properties like the app id, the app type, and the targeted devices

Running the Program

Before running the app for the first time, you may wish to set up a Run Configuration in Eclipse, a pre-selected set of options with which to run a project to help speed development. Once configured, new run configurations only need to be added if new app or device configurations are needed.
To add a run configuration:

  1. Click the Run > Run Configurations menu
  2. Right click on the Connect IQ App option in the list on the left side of the window, and select New
  3. Give the configuration a name at the top
  4. Choose the Connect IQ project that will use this configuration (It should automatically select your current project, but the Project button can be used to select a different one)
  5. Choose a target device
  6. Click Apply and Close

Before running your program, start the Connect IQ simulator by clicking the Connect IQ menu and selecting Start Simulator, or clicking on the start simulator icon  in the toolbar. A blank simulator window will appear.

With a Run Configuration created and the simulator started, you’re ready to go! Use the down arrow next to the Run > Run Configurations menu (or from the Run Configurations selector on the toolbar) to select your configuration.

If all goes well the following run output will appear in the console:

Found Transport: tcp
Connecting...
Connecting to device...
Device Version 0.1.0
Device id 1 name "A garmin device"
Shell Version 0.1.0
Connection Finished
Closing shell and usb

…and the watch will appear in the simulator:

Let’s take it up a notch. Create an images directory inside resources and save this image there as fist-bump-baby-square.png.

Open up the resources\layouts\layouts.xml file. This file is where you can provide page layouts to the resource compiler. We are going to add a date label and a background image.

<layout id="WatchFace">
    <bitmap id="Baby" filename="../images/fist-pump-baby-square.png" />
    <label id="TimeLabel" x="205" y="60" font="Gfx.FONT_LARGE" justification="Gfx.TEXT_JUSTIFY_RIGHT" color="Gfx.COLOR_BLACK" />
    <label id="DateLabel" x="205" y="80" font="Gfx.FONT_LARGE" justification="Gfx.TEXT_JUSTIFY_RIGHT" color="Gfx.COLOR_BLACK" />
</layout>

This tells the resource compiler that there is a background image, and a new text label. Open up source\BabyFaceView.mc in the editor. Monkey C is dynamically typed (like JavaScript or Python), object oriented (like Java), and bytecode interpreted (also like Java).

At the top of the file are your using statements, which import modules into your file scope. All of the system modules fall under the Toybox parent module. You’ll need to add the following clauses to the top of the file.

using Toybox.Time as Time;
using Toybox.Time.Gregorian as Calendar;

Now find the onUpdate method in the BabyFaceView class.

//! Update the view
function onUpdate(dc) {
   // Get and show the current time
   var clockTime = Sys.getClockTime();
   var timeString = Lang.format("$1$:$2$",
         [clockTime.hour, clockTime.min.format("%.2d")]);
   var view = View.findDrawableById("TimeLabel");
   view.setText(timeString);

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

The method currently gets the time from the system and formats the string for TimeLabel. Add the following code before View.onUpdate(dc); to populate the date field:

var dateInfo = Calendar.info( Time.now(), Calendar.FORMAT_SHORT );
var dateString = Lang.format("$1$/$2$/$3$",
         [ dateInfo.month, dateInfo.day, dateInfo.year ]);
var date = View.findDrawableById("DateLabel");     
         date.setText(dateString);

Now when we run it – success!

Importing an Example

To try one of the Connect IQ sample apps, import it into your Eclipse workspace:
1. Click the File menu
2. Select Import…
3. Choose Existing Projects into Workspace under the General section of the window, and click Next
4. Click the Browse button and select the root directory of the sample to import:
5. Check all projects to import that are listed in the Projects window.
6. If there are multiple projects in the root directory, check Search for nested projects to ensure that Eclipse locates all potential projects
7. If you prefer to work with a copy of the project, check Copy projects into workspace
8. Click Finish to complete the import

Now you are ready to hit the ground running.  For more tools and resources for Connect IQ, please visit our developer site.

About Connect IQ:
Connect IQ launched early in 2015 with the goal of making Garmin devices open to the developer ecosystem and subsequently to consumers for personalizing their devices. Since the launch of Connect IQ last year Garmin has launched many more Connect IQ enabled wearables in addition to the first compatible bike computer and handheld GPS unit. The new SDK just launched last month as well, check it out here!  For more information on Connect IQ please see this overview page.

About Garmin:
For decades, Garmin has pioneered new GPS navigation and wireless devices and applications that are designed for people who live an active lifestyle.  Garmin serves five primary business units, including automotive, aviation, fitness, marine, and outdoor recreation. For more information about Garmin, visit our virtual pressroom at garmin.com/newsroom, contact the Media Relations department at 913-397-8200, or follow us at facebook.com/garmin, twitter.com/garmin, or youtube.com/garmin.

 

Be sure to read the next Wearable article: Microsoft Strands Developers As It Kills Off Its Fitness Band SDK

 

Comments (0)