DEV Community

Cover image for Day 55 of #100DaysOfCode: Learn Monkey C (Garmin Connect IQ)- Retrieve common data
Jen-Hsuan Hsieh
Jen-Hsuan Hsieh

Posted on • Edited on

Day 55 of #100DaysOfCode: Learn Monkey C (Garmin Connect IQ)- Retrieve common data

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

Start/Finish an activity

  • Click the right-top button
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) {
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Retrieve common data

1.ActivityInfo Common indicators

Usages

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);
    }
}
Enter fullscreen mode Exit fullscreen mode

2.Running dynamics data Common indicators

Usages

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);
    }
}
Enter fullscreen mode Exit fullscreen mode

Usages


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());
    }
}

Enter fullscreen mode Exit fullscreen mode

That's it!

Articles

There are some of my articles. Feel free to check if you like!

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (1)

Collapse
 
ikif profile image
Ikif

Example\source\RunDataProvider.mc:26: Undefined symbol "RunningDataProvider" detected.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay