Skip to content

Commit

Permalink
Examples: Update GPS Syntax (#1599)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtex authored Aug 19, 2019
1 parent 1626fa3 commit abe9b16
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 78 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ To get you up and running quickly, we provide a variety of examples for using ea

To interactively navigate the examples, visit the [Johnny-Five examples](http://johnny-five.io/examples/) page on the official website. If you want to link directly to the examples in this repo, you can use one of the following links.

**There are presently 360 example programs with code and diagrams!**
**There are presently 361 example programs with code and diagrams!**

<!--extract-start:examples-->

Expand Down Expand Up @@ -236,6 +236,7 @@ To interactively navigate the examples, visit the [Johnny-Five examples](http://
### GPS
- [GPS - Adafruit Ultimate GPS Breakout](https://github.com/rwaldron/johnny-five/blob/master/docs/gps-adafruit.md)
- [GPS - Default GPS](https://github.com/rwaldron/johnny-five/blob/master/docs/gps.md)
- [GPS - Hardware Serial](https://github.com/rwaldron/johnny-five/blob/master/docs/gps-hardware-serial.md)
- [GPS - Sparkfun GP-20U7](https://github.com/rwaldron/johnny-five/blob/master/docs/gps-GP-20U7.md)

### Servo Animation
Expand Down Expand Up @@ -320,8 +321,8 @@ To interactively navigate the examples, visit the [Johnny-Five examples](http://

### Proximity
- [Proximity](https://github.com/rwaldron/johnny-five/blob/master/docs/proximity.md)
- [Proximity - EVShield EV3 (IR)](https://github.com/rwaldron/johnny-five/blob/master/docs/proximity-EVS_EV3_IR-alert.md)
- [Proximity - EVShield EV3 (IR)](https://github.com/rwaldron/johnny-five/blob/master/docs/proximity-EVS_EV3_IR.md)
- [Proximity - EVShield EV3 (IR)](https://github.com/rwaldron/johnny-five/blob/master/docs/proximity-EVS_EV3_IR-alert.md)
- [Proximity - EVShield EV3 (Ultrasonic)](https://github.com/rwaldron/johnny-five/blob/master/docs/proximity-EVS_EV3_US.md)
- [Proximity - EVShield EV3 (Ultrasonic)](https://github.com/rwaldron/johnny-five/blob/master/docs/proximity-EVS_EV3_US-alert.md)
- [Proximity - GP2Y0A710K0F](https://github.com/rwaldron/johnny-five/blob/master/docs/proximity-GP2Y0A710K0F.md)
Expand Down
17 changes: 8 additions & 9 deletions docs/gps-GP-20U7.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ node eg/gps-GP-20U7.js


```javascript
var five = require("johnny-five");
var board = new five.Board();
const {Board, GPS} = require("johnny-five");
const board = new Board();

board.on("ready", function() {
var gps = new five.GPS({
board.on("ready", () => {
const gps = new GPS({
pins: {
rx: 11,
tx: 10,
Expand All @@ -45,15 +45,14 @@ board.on("ready", function() {
// If latitude, longitude data log it.
// This will output zero until a valid
// GPS position is detected.
gps.on("data", function() {
gps.on("data", position => {
console.log("position");
console.log(" latitude : ", this.latitude);
console.log(" longitude : ", this.longitude);
console.log(" altitude : ", this.altitude);
console.log(" latitude : ", position.latitude);
console.log(" longitude : ", position.longitude);
console.log(" altitude : ", position.altitude);
console.log("--------------------------------------");
});
});

```


Expand Down
14 changes: 7 additions & 7 deletions docs/gps-adafruit.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ node eg/gps-adafruit.js


```javascript
var five = require("johnny-five");
var board = new five.Board();
const {Board, GPS} = require("johnny-five");
const board = new Board();

board.on("ready", function() {
board.on("ready", () => {

/*
* This is the simplest initialization
* We assume SW_SERIAL0 for the port
*/
var gps = new five.GPS({
const gps = new GPS({
breakout: "ADAFRUIT_ULTIMATE_GPS",
pins: {
rx: 11,
Expand All @@ -51,10 +51,10 @@ board.on("ready", function() {
});

// If latitude, longitude, course or speed change log it
gps.on("change", function() {
gps.on("change", position => {
console.log("position");
console.log(" latitude : ", this.latitude);
console.log(" longitude : ", this.longitude);
console.log(" latitude : ", position.latitude);
console.log(" longitude : ", position.longitude);
console.log("--------------------------------------");
});
});
Expand Down
30 changes: 16 additions & 14 deletions docs/gps-hardware-serial.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<!--remove-start-->

# GPS - Adafruit Ultimate GPS via Hardware Serial
# GPS - Hardware Serial

<!--remove-end-->


When using GPS class with an Arduino (or similar microcontroller), be sure to upload the StandardFirmataPlus firmware to your board.




##### Adafruit Ultimate GPS via Hardware Serial

##### Breadboard for "GPS - Hardware Serial"

Example of Adafruit Ultimate GPS on hardware serial.


![docs/breadboard/gps-hardware-serial.png](breadboard/gps-hardware-serial.png)<br>
Expand All @@ -31,23 +31,25 @@ node eg/gps-hardware-serial.js


```javascript
var five = require("johnny-five");
var board = new five.Board();
const {Board, GPS} = require("johnny-five");
const board = new Board();

board.on("ready", function() {
board.on("ready", () => {

/*
* Explicitly setting HW_SERIAL1 for the port
*/
var gps = new five.GPS({
port: "HW_SERIAL1"
const gps = new GPS({
port: board.io.SERIAL_PORT_IDs.HW_SERIAL1
});

// If lat, long, course or speed change log it
gps.on("change", function(data) {
console.log(data);
// If latitude, longitude, course or speed change log it
gps.on("change", position => {
console.log("position");
console.log(" latitude : ", position.latitude);
console.log(" longitude : ", position.longitude);
console.log("--------------------------------------");
});

});

```
Expand All @@ -64,9 +66,9 @@ board.on("ready", function() {
<!--remove-start-->

## License
Copyright (c) 2012, 2013, 2014 Rick Waldron <waldron.rick@gmail.com>
Copyright (c) 2012-2014 Rick Waldron <waldron.rick@gmail.com>
Licensed under the MIT license.
Copyright (c) 2016 The Johnny-Five Contributors
Copyright (c) 2015-2019 The Johnny-Five Contributors
Licensed under the MIT license.

<!--remove-end-->
23 changes: 12 additions & 11 deletions docs/gps.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,36 @@ node eg/gps.js


```javascript
var five = require("johnny-five");
var board = new five.Board();
const {Board, GPS} = require("johnny-five");
const board = new Board();

board.on("ready", function() {
board.on("ready", () => {

/*
* This is the simplest initialization
* We assume SW_SERIAL0 for the port
*/
var gps = new five.GPS({
var gps = new GPS({
pins: {
rx: 11,
tx: 10,
}
});

// If latitude, longitude change log it
gps.on("change", function() {
gps.on("change", position => {
console.log("position");
console.log(" latitude : ", this.latitude);
console.log(" longitude : ", this.longitude);
console.log(" altitude : ", this.altitude);
console.log(" latitude : ", position.latitude);
console.log(" longitude : ", position.longitude);
console.log(" altitude : ", position.altitude);
console.log("--------------------------------------");
});

// If speed, course change log it
gps.on("navigation", function() {
gps.on("navigation", velocity => {
console.log("navigation");
console.log(" speed : ", this.speed);
console.log(" course : ", this.course);
console.log(" speed : ", velocity.speed);
console.log(" course : ", velocity.course);
console.log("--------------------------------------");
});
});
Expand Down
18 changes: 9 additions & 9 deletions eg/gps-GP-20U7.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var five = require("../lib/johnny-five.js");
var board = new five.Board();
const {Board, GPS} = require("../lib/johnny-five.js");
const board = new Board();

board.on("ready", function() {
var gps = new five.GPS({
board.on("ready", () => {
const gps = new GPS({
pins: {
rx: 11,
tx: 10,
Expand All @@ -12,11 +12,11 @@ board.on("ready", function() {
// If latitude, longitude data log it.
// This will output zero until a valid
// GPS position is detected.
gps.on("data", function() {
gps.on("data", position => {
console.log("position");
console.log(" latitude : ", this.latitude);
console.log(" longitude : ", this.longitude);
console.log(" altitude : ", this.altitude);
console.log(" latitude : ", position.latitude);
console.log(" longitude : ", position.longitude);
console.log(" altitude : ", position.altitude);
console.log("--------------------------------------");
});
});
});
14 changes: 7 additions & 7 deletions eg/gps-adafruit.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var five = require("../lib/johnny-five.js");
var board = new five.Board();
const {Board, GPS} = require("../lib/johnny-five.js");
const board = new Board();

board.on("ready", function() {
board.on("ready", () => {

/*
* This is the simplest initialization
* We assume SW_SERIAL0 for the port
*/
var gps = new five.GPS({
const gps = new GPS({
breakout: "ADAFRUIT_ULTIMATE_GPS",
pins: {
rx: 11,
Expand All @@ -16,10 +16,10 @@ board.on("ready", function() {
});

// If latitude, longitude, course or speed change log it
gps.on("change", function() {
gps.on("change", position => {
console.log("position");
console.log(" latitude : ", this.latitude);
console.log(" longitude : ", this.longitude);
console.log(" latitude : ", position.latitude);
console.log(" longitude : ", position.longitude);
console.log("--------------------------------------");
});
});
16 changes: 8 additions & 8 deletions eg/gps-hardware-serial.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
var five = require("../lib/johnny-five.js");
var board = new five.Board();
const {Board, GPS} = require("../lib/johnny-five.js");
const board = new Board();

board.on("ready", function() {
board.on("ready", () => {

/*
* Explicitly setting HW_SERIAL1 for the port
*/
var gps = new five.GPS({
port: this.io.SERIAL_PORT_IDs.HW_SERIAL1
const gps = new GPS({
port: board.io.SERIAL_PORT_IDs.HW_SERIAL1
});

// If latitude, longitude, course or speed change log it
gps.on("change", function() {
gps.on("change", position => {
console.log("position");
console.log(" latitude : ", this.latitude);
console.log(" longitude : ", this.longitude);
console.log(" latitude : ", position.latitude);
console.log(" longitude : ", position.longitude);
console.log("--------------------------------------");
});
});
23 changes: 12 additions & 11 deletions eg/gps.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
var five = require("../lib/johnny-five.js");
var board = new five.Board();
const {Board, GPS} = require("../lib/johnny-five.js");
const board = new Board();

board.on("ready", function() {
board.on("ready", () => {

/*
* This is the simplest initialization
* We assume SW_SERIAL0 for the port
*/
var gps = new five.GPS({
var gps = new GPS({
pins: {
rx: 11,
tx: 10,
}
});

// If latitude, longitude change log it
gps.on("change", function() {
gps.on("change", position => {
console.log("position");
console.log(" latitude : ", this.latitude);
console.log(" longitude : ", this.longitude);
console.log(" altitude : ", this.altitude);
console.log(" latitude : ", position.latitude);
console.log(" longitude : ", position.longitude);
console.log(" altitude : ", position.altitude);
console.log("--------------------------------------");
});

// If speed, course change log it
gps.on("navigation", function() {
gps.on("navigation", velocity => {
console.log("navigation");
console.log(" speed : ", this.speed);
console.log(" course : ", this.course);
console.log(" speed : ", velocity.speed);
console.log(" course : ", velocity.course);
console.log("--------------------------------------");
});
});
5 changes: 5 additions & 0 deletions tpl/programs.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@
{ "title": "GPS Receiver - GP-20U7 (56 Channel)", "href": "https://www.sparkfun.com/products/13740"}
]
},
{
"file": "gps-hardware-serial.js",
"title": "GPS - Hardware Serial",
"description": "When using GPS class with an Arduino (or similar microcontroller), be sure to upload the StandardFirmataPlus firmware to your board."
},
{
"file": "gps-adafruit.js",
"title": "GPS - Adafruit Ultimate GPS Breakout",
Expand Down

0 comments on commit abe9b16

Please sign in to comment.