• part 2 of 5 of: GPS Module, Extensions, and u-blox NEO-6M GPS receiver

    All code fragments of previous post and this one can coexist and can therefore be copied and pasted into the Web IDE edit pane, sent at the same time to the board, and individually invoked from the console pane or custom made functions.

    The following setup is common to both - basic and enhanced - modes. Again, notice comments for the inline vs. module way of using the code.

    // common setup
    Serial4.setup(9600,{tx:C10,rx:C11});
    // var gps = require("GPS"); // uncomment when using GPS code as module
    

    The code below - example A) - shows the basic mode usage and validates the backward compatibility.

    // A) for basic use: gpsHandlerFunction as callback as per ESPRUINO doc 
    var gpsHandlerFunction = function(data) { console.log(data); };
    

    For convenience - and coexistence in the Web IDE and sending to board - I added a goXyz...() function to be invoked in the command pane to run the vaious modes A) through C).

    The goBasic() function connects the gps and passes the callback handler function .gpsHandlerFunction() as specified in A) above. This function is the same as used in Espruino's module documentation - http://www.espruino.com/GPS. Instead of defining it inline while passing it, it is defined as a variable and used in all scenarios to write to the console the data objects which is created by the various line handlers.

    function goBasic() {
      gps.connect(Serial4, gpsHandlerFunction);
    }
    

    After sending the code to the board, enter goBasic() into the command pane to use the GPS module in basic mode.

    Example B) is kind of a twitter: uses an wrapping line handler to wrap the defaultLineHandler() of the GPS module and is thus reusing it. The .includeDefaultLineHandler property with value true, makes the enhance GPS module to add the defaultLineHandler() function as same named method to the passed handler object.

    // B) for enhanced use: gpsHandlerObjectDefaultOnly reusing just same basic function as in A)
    var gpsHandlerObjectDefaultOnly = { 
      includesDefaultLineHandler: true,
      lineHandler: function(line, handler) { 
          handler.defaultLineHandler(line,gpsHandl­erFunction);
      }
    };
    

    Invoke the function below in the command pane to run example B).

    function goEnhancedWithDefaultOnly() {
      gps.connect(Serial4, gpsHandlerObjectDefaultOnly);
    }
    

    part 2 of 5 of: GPS Module, Extensions, and u-blox NEO-6M GPS receiver

About

Avatar for allObjects @allObjects started