Is there way to detect watch model?

Is there a way to detect the watch model?

I am interested in positioning text on watch face depending on shape of the face.
  • Rather than detecting the device at runtime, we have a resource system in place to help design layouts for the difference screen geometries. You can read a discussion about it here:

    https://forums.garmin.com/showthread.php?228721-In-App-Device-Detection
  • I am interested in positioning text on watch face depending on shape of the face.

    If you're just trying to position text I think it would be better to just use the layout system as it is designed.

    If you really need to know what device you are on, then the post that Brandon linked to will show how to do that. I still don't think it is a good solution to the problem at hand, but sometimes you gotta do what you've gotta do.
  • Hello! Is the way to detect model? What is the Brandon? :o
  • There are now multiple ways to do this. Garmin added the partNumber field to the device settings, so you can do this...

    var deviceSettings = Sys.getDeviceSettings();

    // device part numbers come from ${SDKROOT}/bin/devices.xml
    var partNumber = deviceSettings.partNumber;
    if ("006-B2156-00".equals(partNumber)) {
    // fr630
    }
    else if ("006-B2431-00".equals(partNumber) ||
    "006-B2396-00".equals(partNumber) ||
    "006-B2397-00".equals(partNumber) ||
    "006-B2516-00".equals(partNumber)) {
    // fr235
    }
    // and so on


    Another option is to follow what has been suggested above. This involves using the resource system to identify the device. How you do this is discussed in the programmer's guide, but here is a quick crash course. You create a file to contain device-specific resources, like this...

    <!-- resources/device.xml -->
    <resources>
    <strings>
    <string id="DeviceModel">Unknown</string>
    </strings>
    </resources>


    If you want to support the fenix3, you'd create a new resource directory for files for the fenix3...

    <!-- resources-fenix3/device.xml -->
    <resources>
    <strings>
    <string id="DeviceModel">fenix3</string>
    </strings>
    </resources>


    Same thing to support other devices like the fr630...

    <!-- resources-fr630/device.xml -->
    <resources>
    <strings>
    <string id="DeviceModel">fr630</string>
    </strings>
    </resources>


    Then, in your code, you could do something like this...

    var _cached_device_model = null;

    function get_device_model() {
    if (_cached_device_model == null) {
    _cached_device_model = Ui.loadResource(Rez.Strings.DeviceModel);
    }

    return _cached_device_model;
    }


    If you are going to be using the function often and don't want to be doing string comparisons all of the time, you could do something like this...

    enum {
    FR920XT = 0x0001,
    FENIX3 = 0x0002,
    VIVOACTIVE = 0x0004,
    D2BRAVO = 0x0008,
    EPIX = 0x0010,

    // add others as they become available
    }

    var _cached_device_model = null;

    function get_device_model() {
    if (_cached_device_model == null) {
    var model = Ui.loadResource(Rez.Strings.DeviceModel);
    if ("fr920xt".equals(model)) {
    _cached_device_model = FR920XT;
    }
    else if ("fenix3".equals(model)) {
    _cached_device_model = FENIX3;
    }
    else if ("vivoactive".equals(model)) {
    _cached_device_model = VIVOACTIVE;
    }
    else if ("d2bravo".equals(model)) {
    _cached_device_model = D2BRAVO;
    }
    else {
    _cached_device_model = 0;
    }
    }

    return _cached_device_model;
    }

    function isDevice(deviceMask) {
    return (get_device_model() & deviceMask) != 0;
    }


    Then in your code you can write stuff like this

    if (isDeviceModel(FENIX3 | D2BRAVO)) {
    // device is fenix3 or d2bravo
    }


    All that said, chances are pretty good that you don't need to do this at all. The DeviceSettings type contains information about the device that can be used more generally to identify features of a device. For example isTouchScreen, screenShape, screenHeight, screenHeight can all be used to conditionally determine how to handle a device and using these can reduce the coupling between your code and each physical device that it was built for.

    Additionally, the MonkeyC language provides the ability to test for feature support. You can write stuff like if (Toybox.Attention has :playTone) to see if the given device firmware supports the playTone() method.

    Travis
  • As Travis mentioned, things about the specific device can be determined at run-time. I code stuff based on things like the dc width and height, and "isTouch", maybe use a "getFontHeight()", etc.

    (I will say I do NOT use layouts and use an x,y for things that I set in onLayout())

    So for me, the same prg actually works on a va and a 230 for example, and draw correctly. (but the colors in the icon for apps get weird - I've put a va build on a 230 a few times and that's how I can tell :) )
  • 8 year later, i'm creating my first apps, this is useful thanks!