getCurrentSport() and getHeartRateZones() are members of the UserProfile module, not the UserProfile.Profile class. (Yeah, it's probably not the greatest design / naming scheme.)
The following code…
Here's my little app displaying the time spent in each heart rate zone with a horizontal bar graph representing the percentage of time in relation to the total elapsed time.
The triangle also moves…
getCurrentSport() and getHeartRateZones() are members of the UserProfile module, not the UserProfile.Profile class. (Yeah, it's probably not the greatest design / naming scheme.)
The following code should work:
var currentSport = UserProfile.getCurrentSport();
var zones = UserProfile.getHeartRateZones(currentSport);
If you're not getting a compile-time error/warning, it seems that you've either got type checking disabled or there's an error in the type checker.
Also note that, similar to TypeScript, the Monkey Types type checker works at compile time only (think of it as a separate compile-time layer on top of Monkey C, same as TypeScript is a compile-time layer on top of JavaScript.) When TypeScript is compiled to JavaScript, no trace of TypeScript types remains. Similarly, when a Monkey C program is run, there's no trace of Monkey Types, although runtime types still exist (but runtime Monkey C types and Monkey Types aren't exactly the same thing.)
Since casting is a feature of Monkey Types, there's no cast you can do at compile time that will change the runtime type. (Unlike say Java or C#.) All casting does in Monkey C is to change what the type checker thinks the type of a variable is.
Yes it works when using UserProfile directly. Now I get the array with the heart rate zones!
The sample in the documentation mislead me into thinking that the profile variables were in Profile.getUserProfile().. made sense to me :P
In the Monkey C extension I have the type check set to default, what level should it be set to catch this errors?
Thanks for explaining how it works, I'm more of a Java/Kotlin dev where casting must happen sometimes.
Another related question maybe you can help: how do I get access to the time spent in each heart rate zone? My Edge 840 has this data field, time in zone 1, time in zone 2 etc... I don't find this info in the documentation, does it have to be calculated? If so, when the datafield is not visible the onUpdate function is called so we can update the time?
Thanks
In the Monkey C extension I have the type check set to default, what level should it be set to catch this errors?
The default setting (which is "informative", and equivalent to the "-l 1
" compiler option) returns errors for the code in the OP:
ERROR: d2bravo: ...:30,8: Cannot find symbol ':getCurrentSport' on type '$.Toybox.UserProfile.Profile'.
ERROR: d2bravo: ...:31,8: Cannot find symbol ':getHeartRateZones' on type '$.Toybox.UserProfile.Profile'.
You wouldn't happen to have the following line in monkey.jungle?
project.typecheck = 0
That will turn off type checking (when the Monkey C extension type check setting is set to default, as in your case.)
Another related question maybe you can help: how do I get access to the time spent in each heart rate zone? My Edge 840 has this data field, time in zone 1, time in zone 2 etc... I don't find this info in the documentation, does it have to be calculated? If so, when the datafield is not visible the onUpdate function is called so we can update the time?
You have to calculate it yourself :/, and computations like that should be done in compute(). You can assume that compute() is called roughly once per second, regardless of whether the data field is visible or not. As you mentioned, onUpdate() is not called when the datafield is not visible.
The project was on default type checking.
Setting to Informative I have a bunch of warnings but it's ok, I'll fix them later.
in the monkey.jungle file there is just the manifest declaration.
Playing with VS Code and the Monkey C plugin is not as fun as playing with Intelij Idea. But so far I got this thing working! It's close to what I want.
If compute() is called every second even when the screen is not visible, I think this will work, I can save the values and display later.
Thanks.
No problem!
Playing with VS Code and the Monkey C plugin is not as fun as playing with Intelij Idea.
I use both VS Code and Intellij at work, and I'll just say that I wouldn't judge VS Code by the Monkey C extension. VS Code is far from perfect, but it works great if you're using a well-supported language like TypeScript or Python, or even just for general purpose text manipulation or viewing. I also use VS Code regularly with a proprietary language which is not well-supported (even compared to Monkey C), and it does the job.
I like Intellij's Java support (durr) but I find it to be a bit bloated and slow (even compared to VS Code, which is saying a lot).
When I want a very fast, natively compiled editor, I use Sublime Text or notepad++ (the latter is a bit lacking in modern features tho).
Here's my little app displaying the time spent in each heart rate zone with a horizontal bar graph representing the percentage of time in relation to the total elapsed time.
The triangle also moves up and down based on the current heart rate.
Time for a field test.