Beginner quistion

Former Member
Former Member

Hi here Slight smile

Recently i bought myself /moving from other brand) an Fenix5 watch; really like the idea that programming/customizing is possible.

I figured out, as with all coding stuff the learning curve can be hard to crack, so i started reading stuff about the monkeyC language.

I have experience from other languages (mostly Linux, BASH, and a little python), not much C stuff, but i like to learn through!

I installed the eclipse env., and have a working workspace now.

Well, i find it hard to understand where and what to put inside the different files, and how to use the structure.

By this i mean stuff like ::

function initialize

function onLayou

function onShow

function onUpdate

etc... etc..

I tried putting some Println stuff inside, and i see how things are triggered when using watch on simulator, but i can't seem to get further, and therefore i ask for help here to get going.

What i would like to make, is an watchapp, which should be a simple Gym-Log. The app must do the following ::

At load/start, show my SPLASH image  (Yes i know! not pro., but just for a start now Slight smile)

Start the session, stop the session, where user is asked whether to save, resume etc.. just normal stuff here.

The layout should be 4 fields, 1. field "timer", 2. field "actual pulse", 3. field "temperature", 4. field "actual time"

If possible, user should not have possiblilty to change layout, actually i like user to have no possiblities to change anything (this app is intended for myself mainly)

When session is done, and user have saved session, i like the session (if possible) to be saved as "Strenght training"...

Anyone help me to get further from here ???

Rgds; Jesper

  • In the sdk there are samples available that should get you on the way with the different functionalities.

    On my website I also have a step by step tutorial that should be able to help anyone (no coding experience required) to get started: http://starttorun.info/garmin-connect-iq-tutorial-overview/  and I'm also linking to other repo's with apps with source code http://starttorun.info/connect-iq-apps-with-source-code/  that should kickstart your development.

    I'd advice you to start with my tutorial though (even though it's a data field and you want a watch app), the tutorial is really good to get the basics right!

  • Former Member
    Former Member over 6 years ago in reply to peterdedecker

    Thanx Peter...

    I will look into this; trying to learn the thing...

    Rgds; Jesper

  • Former Member
    Former Member over 6 years ago

    So i tried a lot of different, and i am beginning to see how it works.

    Tried some of the samples along with Peter's suggestions.

    I also played with some "menu" layouts etc...

    So now i grabbed the code from activitymonitor help topic

    using Toybox.ActivityMonitor;
    using Toybox.System;
    
    // get a HeartRateIterator object; oldest sample first
    var hrIterator = ActivityMonitor.getHeartRateHistory(null, false);
    var previous = hrIterator.next();                                   // get the previous HR
    var lastSampleTime = null;                                          // get the last
    
    while (true) {
        var sample = hrIterator.next();
        if (null != sample) {                                           // null check
            if (sample.hearRate != ActivityMonitor.INVALID_HR_SAMPLE    // check for invalid samples
                && previous.heartRate
                != ActivityMonitor.INVALID_HR_SAMPLE) {
                    lastSampleTime = sample.when;
                    System.println("Previous: " + previous.heartRate);  // print the previous sample
                    System.println("Sample: " + sample.heartRate);      // print the current sample
            }
        }
    }
    
    // get ActivityMonitor info
    var info = ActivityMonitor.getInfo();
    
    var steps = info.steps;
    var calories = info.calories;
    
    System.println("You have taken: " + steps +
                   " steps and burned: " + calories + " calories!");

    I tried placing this code in onUpdate, onLayout etc... but nomatter what i do, the simulator crashes with error (to many bla. bla. bla.)

    This HR monitor, i struggle to get working, and also showing on app, but i cant find anything about howto get further now, i am stuck again.

    I need some suggestions, example to show me how i can display current HR etc.. on my app"face"

    Strange that i cannot find anything usefull about this.

    Rgds; Jesper

  • What's the crash you see?

    Another way to get HR (getHeartRateHistory on updates every 90 seconds or so on many devices) is to use

    Activity.getActivityInfo().currentHeartRate

    That will be more "real time" on most devices, but it can be null if the watch isn't being worn.  With that you can also display HR in onPartialUpdate() to have more of a real-time HR on a watchface.  On Peter's site, theses a link to a tutorial I did on 1hz facefaces, and displaying HR is a common topic there.

  • Here's the basic code I user for HR in a watch face: I'm only looking for the newest value.

    			//hasHR is a boolen I set earlier to check if getHeartRateHistory is available on the device
    			ret="N.A.";
    			if(Activity.getActivityInfo().currentHeartRate!=null) {
    				thisHR=Activity.getActivityInfo().currentHeartRate;
    				ret=thisHR.toString();
    			} else if(hasHR) {
    				var hrh=ActMon.getHeartRateHistory(1,true);
    				ret="---";			
    				if(hrh!=null) {
    					var hrs=hrh.next();			
    					if(hrs!=null && hrs.heartRate!=null && hrs.heartRate!=ActMon.INVALID_HR_SAMPLE) {
    						thisHR=hrs.heartRate;
    						ret=thisHR.toString();
    					}
    				}
    			}

  • Former Member
    Former Member over 6 years ago in reply to jim_m_58

    Thanks a lot...

    I feel i am getting closer.

    The error i got is "too long execution", because it keeps counting i guess.

    I tried youre code, but i am getting some errors due to some variables i did not setup i guess?

  • Former Member
    Former Member over 6 years ago in reply to Former Member

    Ahh... i got some of it running now Slight smile

  • "too long execution" is the watchdog timer tripping, and is typically something like an infinite loop.

    In the code I posted, yes, you'll need to use "var" on some of the things.  In my actual code, they are defined elsewhere. on line 34 add a "var" in front of ret, and then add a line for "var thisHr;" right after that.

  • Former Member
    Former Member over 6 years ago in reply to jim_m_58

    Oh...

    On my 2. picture i did most of that, but you say and then add a line for "var thisHr;

    I simply don't understand what you mean ? :)

    ... Jesper.

  • Ok, in the code, do this starting at line 34 in your code:

    var ret="N.A.";  //add the var

    var thisHR;     //add this line