Need advice

Good day to all.
Actually, need two advices. Both for watch face developing.

First one with getting GPS position for further calculations.
Before I used “currentLocation” from “Activity.getActivityInfo()”, but it makes some inconvenient, to get PSN data, need to activate GPS in short time before position data will be used. Same, when need to refresh changed GPS PSN – extra code requested.
Not so far, while making widget, I found that GPS PSN can be taken from “(Position.getInfo()).position” and it’s looks like that last received GPS PSN stored there constantly, and automatically updated, when received.
It’s properly working with beta fw 9.72, tested on Fenix 5x and 5s. But on fw 9.2 (same devices) got two different errors: 5x error – “Unexpected Type Error”, 5s – “Permission error”. After update devices to 9.72 all working smooth and without errors.
Question is: is it new possibility of last beta or bug of last official?

Second question regarding “settings” file from “resources” with watch face settings. One of my watch face has 8 cells to data selected by user. For each cell can be selected one from thirteen types of data. I’m using same list of option for each cell, it’s just duplicated eight times.
Question is: is there any possibility to avoid duplicating and call same option list for each cell?
  • 1) You still use Activity.Info.currentLocation. You can not start GPS in a watchface (you'll get a permission error if you try). Note! With CIQ3 devices you need to have the "positioning" permission to use currentLocation, but you still can't start up GPS in a watch face. Without that permission, you'll always get null. You can set that permission starting with the 2.4.6 SDK.

    So (with that permission), you use currentLocation, and if it's not null, you save that location in the ObjectStore/Application.Storage. if it is null, you use the last location saved in the ObjectStore/Application storage.

    If it's null, and there's nothing saved, indicate in some way it needs GPS. The user then needs to do something like "run" to get a GPS location, and then return to the WF, where currentLocation won't be null any more, and it can be saved for reuse later. This should be a "only needed after the watchface is first installed" thing, as after that, it will have the cached version to fall back on.

    2) that's something that's been requested a number of times, but for now, you have to duplicate the lists.
  • 1) You still use Activity.Info.currentLocation. You can not start GPS in a watchface (you'll get a permission error if you try). Note! With CIQ3 devices you need to have the "positioning" permission to use currentLocation, but you still can't start up GPS in a watch face. Without that permission, you'll always get null. You can set that permission starting with the 2.4.6 SDK.

    So (with that permission), you use currentLocation, and if it's not null, you save that location in the ObjectStore/Application.Storage. if it is null, you use the last location saved in the ObjectStore/Application storage.

    If it's null, and there's nothing saved, indicate in some way it needs GPS. The user then needs to do something like "run" to get a GPS location, and then return to the WF, where currentLocation won't be null any more, and it can be saved for reuse later. This should be a "only needed after the watchface is first installed" thing, as after that, it will have the cached version to fall back on.

    2) that's something that's been requested a number of times, but for now, you have to duplicate the lists.


    Jim, thanks for as usual good and clear reply.

    But, usage of currentLocation for me.
    That what I mean, just try to use “(Position.getInfo()).position” with watch face or widget, whatever. It’s working with fw 9.72. Tested 100%

    Let’s say, try in any your wish, and do not switch on activity in simulator, just lunch normally (I tried with watch face and widget, and I, really, like how it works, much better than currentLocation, but only with beta 9.72, it's took, as i understood last saved psn):

    In manifest aloud permission for Position,
    Code:

    using Toybox.Position;
    System.println(((Position.getInfo()).position).toRadians());

    Point of question was, that on two devices: 5x and 5s with fw 9.2, I god different errors. But after upgrade those devices to beta 9.72, without any changes of code in watch face or widget, I got all working properly.

    Regarding settings, all clear, thanks.
  • The Hw architecture of the f5x and f5x is different. At one point, Activity.Info.currentLocation was only available when in "preview mode" of a watchface on the f5x for example. (it's now available in normal watch mode).

    There were some FW fixes to make that happen, and may not be there for Position.Info.location

    The normal practice is NOT to user Position.getInfo().location in a WF (in fact you couldn't before 2.4.6), but to use Activity.Info.currentLocation. The location will be the same, as in neither case does GPS get started, and the "aging" of the currentLocation in Activity.Info is known. I'm not sure how long after GPS is turned off the location in Position.Info is valid (non-null)

    Like I said, here's what you do:

    var actInfo=Activity.getActivityInfo();
    var loc=actInfo.currentLocation;
    if(loc!=null) {
    //save loc to Object Store
    } else {
    //set loc to last cached loction in Object Store
    }

    if(loc!=null) {
    //do what you need to do with the location
    } else {
    //indicate you need GPS (user must start an activity that uses GPS and return to this app)
    }


    After you do an activity that uses GPS, currentLocation will be valid for a period of time (at least an hour and up to a few hours), but then it goes stale, and is null, and once it's cached in the Object Store, you'll always have the last location in the watch face. You might be able to get Postion.Info.location to work, but that may not be consistent with different devices/firmware/etc. Activity.Info.currentLoction is so commonly used, that should be no problem.
  • Jim, you are again right.

    Normally I’m using currentLocation and saving data for further usage.

    Just discover interesting usage of (Position.getInfo()).position. With not so stable results for fw 9.2,
    but working great (not a single day) with 9.72.
    Here examples for 5x and some I’ve done for my wife for 5s, some of them with source code
    to post and keep up-to date code for all of them, I’m too lazy... ). No one is working properly with fw 9.2,
    but all working good with 9.72 for around one week:
    https://apps.garmin.com/en-US/apps/7...7-4ea7c391a08a
    https://apps.garmin.com/en-US/apps/a...e-e0cd12c6ccf7
    https://apps.garmin.com/en-US/apps/c...8-e8beae4f0bed
    https://apps.garmin.com/en-US/apps/c...2-3054c9ae8f19

    So, for me, and my wife - all great, will see what will be with next official firmware.
  • Bear in mind the 9.72+ FW for the f5x/f5s is CIQ3 where the whole positioning permission became required, and may have opened up access to Position.Info. But that means that using Position likely ONLY works on devices with CIQ3, and even for the f5x/f5s it could be a while for APAC variants to catch up, along with things like the Descent Mk1, and there are some devices that aren't moving from CIQ2 to CIQ3 (and some still on CIQ1). Activity.Info.currentLocation has worked as far back in CIQ as I can recall, so it's safe across all the devices and their variants.
  • Thank you for information.
    Maybe really better to change code to currentPosition up to next official firmware will come.
  • Just to not creating one more topic, need one more advice.

    To save battery (as I thinks, may be wrong), I set part of the code, to update data, every midnight, using simple check for hrs, min and sec == 0. In this midnight update, results are saving into App.Storage. All other period watch face took data to display on screen from saved in App.Storage.

    Is it has sense, or it’s better to minimize App.Storage usage and just recall code with normal onUpdate function procedure.

    In few words, how expensive usage of App.Storage?
  • First thing, is I wouldn't use the check for 00:00:00, but would look for the day to change, as the watchface may not be running at midnight - the user could have switch to another, an activity could be in process, etc.

    Let's say you do the "end of day" code on the 7th, user switches to another WF, and then switches back mid-day on the 9th. It would still have the data from the 7th until the next 00:00:00. But if you checked the date, since it's no longer the 7th, it would update right away on the 9th, and the next time on the 10th.

    To optimize the ObjectStore access, you can cut back on when it's used. You really only need to read the data when the apps starts (say in onStart() or initialize() for the main view), , and write it in onStop(). At other times, just use a variable in your code.
  • Hm… I’ve lost the idea, that user can be somewhere else exactly in midnight…
    Thanks a lot for your advice.
    Will set code to proper way.
  • And again I need advice.
    This time regarding “onPartialUpdate”.

    As I understood, this function will be called automatically, if presents in a code. Is there any possibility to call it only with special circumstances? Let’s say if some property will be true, and in case of false keep it off.

    For now, I just have idea to deactivate code inside of onPartialUpdate – to make check, and if true – code activating, if flase – nothing happens. But anyhow, onPartialUpdate will be called every second with that check inside…