Monday, November 02, 2020

Building a Garmin Watch Widget | Part 2: Holy Smokes! It Works!

The next task in building out the Sun Compass Widget for my Garmin Vivoactive 4  watch was to implement the underlying math. I carefully translated the first formula, Equation of Time, from Scheme to the Monkey C and of course it didn't work. The problem: I forgot to convert degrees to radians before calling sin() and cos(). Once passed this beginner mistake, the rest of the implementation was smooth sailing.

I fired up the calculator and the Garmin simulator and was below away. They match!

You'll notice in the screenshot above that the phrase 'fresh' next to the latitude and longitude. This tells me that the widget's call to the GPS for the current location was successful. Until this call returns, which can take quite a bit of time, I use the last known location. When a previous location is used, it's marked as stale. Fortunately, your location to the meter isn't needed for the compass to be reasonably accurate. As long a fresh reading was taken near your current location, the quickly shown stale value should work.

Caching the location went a long way towards speeding up the widget and making usable.

Here are some snapshots of the widget running on my actual watch on my actual wrist.

Next up: I'll graphically render the azimuth of the sun using something approximating a compass dial. I have to say, this development has been really fun. As I close in on finishing this little project, I'm already brainstorming on what my next app may be.

Check out the source code for the widget on github.

No comments:

Post a Comment