Day 55 of #100DaysOfCode: Learn Monkey C (Garmin Connect IQ)- Retrieve common data
Tags: garmin, 100daysofcode, ciq, monkeyc
Published: 2021-01-15 04:51:46

## Introduction
We can use Monkey C and Connect IQ SDK to customize the appearance of Garmin devices. The article is the note for learning Monkey C.

Welcome to visit the following articles to learn Garmin Connect IQ developing
* [Day 10 of #100DaysOfCode: Learn Monkey C- create a menu for CIQ application](https://dev.to/jenhsuan/day-10-of-100daysofcode-learn-monkey-c-create-a-menu-for-ciq-application-2dc9)

## Start/Finish an activity
* Click the right-top button

```C#
class ExampleDelegate extends Ui.BehaviorDelegate {
    function initialize() {
        BehaviorDelegate.initialize();
    }
    function onKey(evt) {
        var lastKey=evt.getKey();
        if(lastKey==Ui.KEY_ENTER || lastKey==Ui.KEY_START) {
        }
    }
}
```

## Retrieve common data
#### 1.ActivityInfo Common indicators
* [Cadence](https://developer.garmin.com/connect-iq/api-docs/Toybox/Activity/Info.html)
* [Heart rate](https://developer.garmin.com/connect-iq/api-docs/Toybox/Activity/Info.html)
* [Elapse time](https://developer.garmin.com/connect-iq/api-docs/Toybox/Activity/Info.html)
* [Elapse distance](https://developer.garmin.com/connect-iq/api-docs/Toybox/Activity/Info.html)

#### Usages

```C#
using Toybox.Activity;
class ExampleView extends Ui.View {
    function updateData() {
        var actInfo = Activity.getActivityInfo();
        Sys.println(actInfo.currentCadence);
        Sys.println(actInfo.currentHeartRate);
        Sys.println(actInfo.elapsedDistance);
        Sys.println(actInfo.elapsedTime);
    }
}
```

#### 2.Running dynamics data Common indicators
* [Step length](https://developer.garmin.com/connect-iq/api-docs/Toybox/AntPlus/RunningDynamicsData.html)
* [Vertical oscillation](https://developer.garmin.com/connect-iq/api-docs/Toybox/AntPlus/RunningDynamicsData.html)
* [Ground contact time](https://developer.garmin.com/connect-iq/api-docs/Toybox/AntPlus/RunningDynamicsData.html)
* [Ground contact balance](https://developer.garmin.com/connect-iq/api-docs/Toybox/AntPlus/RunningDynamicsData.html)
* [Vertical ratio](https://developer.garmin.com/connect-iq/api-docs/Toybox/AntPlus/RunningDynamicsData.html)

####Usages

```C#
using Toybox.System;
using Toybox.AntPlus;
using Toybox.System as Sys;

class RunDataProvider {
	var RD;
	
	function initialize() {
        var listener = new Toybox.AntPlus.RunningDynamicsListener();
		RD = new Toybox.AntPlus.RunningDynamics(listener);
	}
	
	function getRunningData() {
		return RD.getRunningDynamics();
	}
}


using Toybox.Activity;
class ExampleView extends Ui.View {
    var mRunDataProvider = null;
    function initialize() {
        View.initialize();
        mRunningDataProvider = new $.RunningDataProvider();
    }

    function updateData() {
        var runningData = mRunDataProvider.getRunningData();
        Sys.println(runningData.stepLength);
        Sys.println(runningData.verticalOscillation);
        Sys.println(runningData.groundContactTime);
        Sys.println(runningData.groundContactBalance);
    }
}
```

* [Heart rate zones](https://developer.garmin.com/connect-iq/api-docs/Toybox/UserProfile/Profile.html)

####Usages

```C#

using Toybox.UserProfile;
module ExampleModule {
var heartRateZone = "";
    function getMyHeartRateZone(){
        heartRateZone = "";
        var hrz = UserProfile.getHeartRateZones(UserProfile.HR_ZONE_SPORT_GENERIC);
        for(var i = 0; i < 5; i++){
            heartRateZone += hrz[i] + ",";
        }
        heartRateZone += hrz[5];
    }
}


using Toybox.Timer;
class ExampleView extends Ui.View {
    var _refresher = new Timer.Timer();
    function initialize() {
        View.initialize();
        Ui.requestUpdate();
        _refresher.start(method(:onTimer), 1000, true);
    }
    function onTimer(){
        Sys.println(JapanWearableExpo2020.heartRateZone());
    }
}

```

That's it!

## Articles
There are some of my articles. Feel free to check if you like! 
* My blog-posts for software developing: https://medium.com/a-layman
* My web resume: https://jenhsuan.github.io/ALayman/cover.html
* Facebook page: https://www.facebook.com/imalayman
* My latest side project - Daily Learning: https://daily-learning.herokuapp.com/