First step for datafield

Hello!

I try to create my own datafield. It should sum the time, where cadence and/or power is zero.

Should running on a Edge1040

I setup Visual Studio, install Monkey C and create first project. When I click on "Run without debugging" I choose the Edge1040 and the simulator start.

But there I have only a blank screen. I thought it will display the edge 1040?

Is there a tutorial for a simple datafield on a edge 1040?

Thank you!

  • Here is the simple code for testing:

    import Toybox.Activity;
    import Toybox.Lang;
    import Toybox.Time;
    import Toybox.WatchUi;
    
    class ZeroPowerView extends WatchUi.SimpleDataField {
      // Set the label of the data field here.
      function initialize() {
        SimpleDataField.initialize();
        label = "Zero Power";
        System.println("function initialize");
      }
    
      // The given info object contains all the current workout
      // information. Calculate a value and return it in this method.
      // Note that compute() and onUpdate() are asynchronous, and there is no
      // guarantee that compute() will be called before onUpdate().
      function compute(info as Activity.Info) as Numeric or Duration or String or
          Null {
        // See Activity.Info in the documentation for available information.
        System.println("function compute");
        return 0.0;
      }
    }

  • Not sure why this exact problem is happening to you, but the sim is notoriously flaky. Are you getting any error message in the console, such as "Could not connect to the simulator"?

    Personally when something like this happens to me, I just try to rebuild and re-run the app over and over again, until it finally works. Sometimes I close and reopen the sim, too.

    If you have a physical Edge 1040 device, you could always copy the PRG from the bin folder onto the device (in \GARMIN\APPS), to see the app in action. I realize you'd rather test in the sim first tho.

    I try to create my own datafield. It should sum the time, where cadence and/or power is zero.

    Is this actually something you need, or are you only doing it for the purposes of learning CIQ.

    If you actually need this data field, my CIQ data field Appbuilder 5 can help.

    The following settings should work for you:

    - Label: CAD/POW 0 TIME (or whatever you want)

    - Display Format: Time

    - Formula: sum(not(power) or not(cadence))

    This formula actually counts the number of seconds that either power and/or cadence is 0 or null.

    If you want the number of seconds that either power and/or cadence is 0 (and not null), use the following formula:

    sum(power eq 0 or cadence eq 0)

  • Here is the terminal output when I run without debugging. Chossing monkeyc as debugger:

    Executing task: monkeyc: Building For Device 
    
    java -Xms1g -Dfile.encoding=UTF-8 -Dapple.awt.UIElement=true -jar c:\Users\User\AppData\Roaming\Garmin\ConnectIQ\Sdks\connectiq-sdk-win-7.2.1-2024-06-25-7463284e6\bin\monkeybrains.jar -o bin\ZeroPower.prg -f c:\Users\User\Dokumente\Garmin SDK\Zero Power\ZeroPower\monkey.jungle -y c:\Users\HannesHörting\OneDrive - Gedomo GmbH\Dokumente\Garmin SDK\developer_key -d edge1040_sim -w
    
    WARNING: edge1040: The launcher icon (30x30) isn't compatible with the specified launcher icon size of the device 'edge1040' (40x40). Image will be scaled to the target size.
    WARNING: edge1040: The 'Background' permission was enabled but no source code was annotated. The entire application will be loaded as a background process.
    BUILD SUCCESSFUL
     *  Terminal will be reused by tasks, press any key to close it. 

    here the manifest.xml:

    <?xml version="1.0"?>
    <!-- This is a generated file. It is highly recommended that you DO NOT edit this file. -->
    <iq:manifest version="3" xmlns:iq="http://www.garmin.com/xml/connectiq">
        <!--
            Use "Monkey C: Edit Application" from the Visual Studio Code command palette
            to update the application attributes.
        -->
        <iq:application id="76359c66-42f6-4670-9552-fe619a62cd62" type="datafield" name="@Strings.AppName" entry="ZeroPowerApp" launcherIcon="@Drawables.LauncherIcon" minApiLevel="4.0.0">
            <!--
                Use the following from the Visual Studio Code comand palette to edit
                the build targets:
                "Monkey C: Set Products by Product Category" - Lets you add all products
                                           that belong to the same product category
                "Monkey C: Edit Products" - Lets you add or remove any product
            -->
            <iq:products>
                <iq:product id="edge1040"/>
                <iq:product id="fenix7"/>
                <iq:product id="fenix7pro"/>
                <iq:product id="fenix7pronowifi"/>
            </iq:products>
            <!--
                Use "Monkey C: Edit Permissions" from the Visual Studio Code command
                palette to update permissions.
            -->
            <iq:permissions>
                <iq:uses-permission id="Background"/>
                <iq:uses-permission id="Sensor"/>
                <iq:uses-permission id="SensorHistory"/>
            </iq:permissions>
            <!--
                Use "Monkey C: Edit Languages" from the Visual Studio Code command
                palette to edit your compatible language list.
            -->
            <iq:languages>
                <iq:language>deu</iq:language>
                <iq:language>eng</iq:language>
            </iq:languages>
            <!--
                Use "Monkey C: Configure Monkey Barrel" from the Visual Studio Code
                command palette to edit the included barrels.
            -->
            <iq:barrels/>
        </iq:application>
    </iq:manifest>

    But should I not get the prinln command in terminal? Even this is not printing.

  • When I switch in visual studio to "Output / window" then I see this:

    2024-08-09 10:03:06.670 [error] An unknown error occurred. Please consult the log for more details.: AggregateError:
        at internalConnectMultiple (node:net:1117:18)
        at afterConnectMultiple (node:net:1684:7)
    2024-08-09 10:03:07.684 [error] An unknown error occurred. Please consult the log for more details.: AggregateError:
        at internalConnectMultiple (node:net:1117:18)
        at afterConnectMultiple (node:net:1684:7)
    2024-08-09 10:03:08.711 [error] An unknown error occurred. Please consult the log for more details.: AggregateError:
        at internalConnectMultiple (node:net:1117:18)
        at afterConnectMultiple (node:net:1684:7)
    2024-08-09 10:03:09.729 [error] An unknown error occurred. Please consult the log for more details.: AggregateError:
        at internalConnectMultiple (node:net:1117:18)
        at afterConnectMultiple (node:net:1684:7)
    Did someone know where the log files stored?
  • println output should show in the debug console in VSC,  Make sure you use the latest SDK.  You might also see things there if there was a problem starting your app in the sim.  There could be a timeout for example..

    If you don't have a background service, turn off the background permission.  If you do, annotate the code you need in the background with (:background)

  • Never seen anything like this before, but it seems like something that happens every second, so maybe something with compute()

  • Which monkey extension I need to add in VSS?

    this two I have installed

  • If you've never had anything run in the sim, what I'd do, is in VSC, do Monkey C:New project, and have that create a simple data field (it uses a template from the SDK), and try running that with no changes to that code.  If that doesn't run, there is something about how you are set up.  If it does run, make minor changes based on your code and see what breaks it.

  • Remove the one at the bottom.  You only want the one from Garmin

  • Did all suggestions .. nothing helps. Deinstalling VScode and reinstall. Same.

    Now I use my MacBook and working.

    But now I need the current Power and current cadenz from a running activity How can I get this info in:

    Activity.Info
    Thanks