Water depth with instinct 2

Good afternoon all 

My instinct2  has the same barometer sensor as the G1 so iv been told. Im trying to make a water depth data field, but the simulator app crashes. I'm fairly new to monkey c could one of you experts read  it over and tell me where im going wrong 

import Toybox.Activity;
import Toybox.Lang;
import Toybox.Time;
import Toybox.WatchUi;
import Toybox.Sensor;

class valueView extends WatchUi.SimpleDataField {

    function initialize() {
        SimpleDataField.initialize();
        label = "Water depth M";
    }

     var x = Activity.getActivityInfo().ambientPressure;
     var y = ((x - 1013)/9.9) ; //1013 average sea level pressure Pr, h=(P-Pr)/(rho * g '=9.9') 
    function compute(info as Activity.Info) as Numeric or Duration or String or Null {
        return y ;
    }

}

  • The two lines starting with var x and var y need to be inside of compute, as you want to get Acitivity.Info each time compute is called.  And the paramete pass to compute is actually Activitity.Info, so,

        function compute(info as Activity.Info) as Numeric or Duration or String or Null {
            var x=info.ambientPressure;
            var y=0;
            if(x!=null) {
                y = ((x - 1013)/9.9) ; //1013 average sea level pressure Pr, h=(P-Pr)/(rho * g '=9.9') 
            }
            return y ;
        }

    Since the Instinct2 isn't a diving watch, the value ofr ambienPressure may be limited by the FW.

  • Thanks for that, it seems to return an error. im not  sure what's wrong 

  • import Toybox.Activity;
    import Toybox.Lang;
    import Toybox.Time;
    import Toybox.WatchUi;
    import Toybox.Sensor;
    
    class valueView extends WatchUi.SimpleDataField {
    
        function initialize() {
            SimpleDataField.initialize();
            label = "Water depth M";
        }
       function compute(info as Activity.Info) as Numeric or Duration or String or Null {
            var x=info.ambientPressure;
            var y=0;
            if(x!=null) {
                y = ((x - 1013)/9.9) ; //1013 average sea level pressure Pr, h=(P-Pr)/(rho * g '=9.9')     
           return y ;
            }   
       }

    extraneous input '<EOF>' expecting

  • There is a missing "}"after line 17. and a missing ";" on line 17

  • Thanks for the help Thumbsup. Seems to be working I will have to invest more time in learning monkey 

  • I'm assuming ambient pressure is measured in pascals as to convert to Mb I just needed to /100 to get a realist figure. 

  • Hi

    its interesting if i read ambient pressure only it displays 96803 assuming would be 968.02mb but my barometer reads 998.0mb on the watch app  itself. any ideas if im selecting the correct data field, it goes up and down with hills. do garmin have to calibrate pressure readings ?

  • Notice there is ambientPressure as well as rawAmbientPressure and also 

    for ambientPressure

    The data is smoothed by a two-stage filter to reduce noise and instantaneous variation.

    for rawAmbientPressure

    The data is the temperature compensated information read directly from the internal sensor.

  • Ok seems strange how it's so far off, going with the filtered data it's saying I'm almost 3000ft high when in reality I'm 200ft. I'm wondering if they just use an offset to calibrate it for the main watch barometer.