Vertical Speed

Hi,

Do any of you know how to calculate "Vertical Speed"?

Is it as something like (info.totalAscent + info.totalDescent) / info.timerTime?

Thanks,

  • Thanks! Would have been nice being able to declare byte variable. I can see some memory improvement... Maybe on on upcoming CIQ release... Garmin shoud give us more control on this as memory is very limited...

  • By the way, that's the code I came up with:

    class MyClass extends WatchUi.DataField
    {
      protected var arrayAltPointer = 0;
      protected var arrayAltPrecision = 60;
      protected var altitudeArray = new [arrayAltPrecision];
      protected var verticalSpeed = 0;
    
      function initialize()
      {
        var info = Activity.getActivityInfo();
        var currentAltitude = info.altitude == null ? 0 : info.altitude;
          
        for (var i = 0; i < arrayAltPrecision; i++)
        {
    	    altitudeArray[i] = currentAltitude;
        }
      }
    
      function compute(info)
      {
        if (info.altitude  != null)
        {
          var index = arrayAltPointer % arrayAltPrecision;
          var calculatedAltitude = info.altitude - altitudeArray[index];
          altitudeArray[index] = info.altitude;
          
          arrayAltPointer++;
          var indexLastArrayElement = arrayAltPointer < arrayAltPrecision ? arrayAltPointer : arrayAltPrecision;
          verticalSpeed = calculatedAltitude / indexLastArrayElement * 60;
        }
      }
    }

  • yes, because byte arrays the ("b") are arrays. an array of bytes (8 bit values).  That's why you get the error with var1 - it's not an array

  • Actually not.  With a byte array, each item in the array is 8 bits.  If you want to put a 32 bit value in a byte array, you need to use encodeNumber, where it takes 4 bytes of the array and you can specify the endian and starting offset in the byte array.   So if you put a 32 bit value in a byte array, it would be in ba[0], ba[1], ba[2], ba[3] for example.

    with encodeNumber you can also insert 16 bit values (which use 2 bytes).  With decodeNumber you can get the values back, using the offset and endian.

    consider this:

    var ba=new [4]b;
            System.println("ba1="+ba);
            ba[0]=-1;
            ba[1]=255;
            ba[2]=1000;
            ba[3]=123;
            System.println("ba2="+ba);

    an exception is thrown on the lines with ba[2]:

    Error: Unhandled Exception
    Exception: Number is too large to fit within a byte

    if ba[3]=null is used, you get an exception that it's not a number at all;  With ba[2]=0x10, here's the output:

    ba1=[0, 0, 0, 0]
    ba2=[255, 255, 16, 123]

    (you'll see that the sign on ba[0] isn't preserved.)

  • Here's an example of butting a 32 value in a byte array (big and little endian)

            var num=1000;
            ba.encodeNumber(num, Lang.NUMBER_FORMAT_SINT32, {:endianness => Lang.ENDIAN_BIG});
            System.println("ba3="+ba);
            ba.encodeNumber(num, Lang.NUMBER_FORMAT_SINT32, {:endianness => Lang.ENDIAN_LITTLE});
        	System.println("ba4="+ba);

    ba3=[0, 0, 3, 232]
    ba4=[232, 3, 0, 0]

  • Great, but it would be even better if Garmin could allow native byte variable. I'm trying to avoid array as they consume too much memory.

  • It really is an array of bytes, but referenced with a ByteArray object.  The places I use them is with ble to send/receive a series of bytes.

    Per the memory viewer, 15 bytes for the object, and then a byte for each element, so "ba" above in 19 bytes long

    if I create a byte array that's [80]b, it''s a total of 95 bytes, and so on. So you can save a bunch of memory if you need an array of values that fit in 8 bits

  • I don't come up with the same memory usage.

    To calculate memory usage, I have started my application and look how much memory was used for each element (<Global>, <Code>, <Data>, etc.).

    Then I have added to the code a byte array of 1 element and look at memory usage again.

    Finally I have added to the code a byte array of 10 elements and look at memory usage again.

    I found that 49 bytes were used for the Array itself + 14 bytes for each element in the Array.

  • I'm using the memory view in the sim.  Could you post that bit of your code?

  • Memory Usage intially :

    Then, I add this single line of code :

    protected var BIG_ARRAY = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]b;

    The result is as follow :

    1314 bytes more on <Code>
    8 bytes more on <Data>
    127 bytes more on <Entry Point>

    Total of 1449 bytes added (49 bytes for the Array + 14 bytes/element)