Created
July 8, 2015 21:51
-
-
Save flippyhead/b2c197cd5d77959aeb2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
native _begin(), _read(), _GPS; | |
native do | |
##include <Adafruit_GPS.h> | |
##include <SoftwareSerial.h> | |
SoftwareSerial my_Serial(8, 7); | |
Adafruit_GPS GPS(&my_Serial); | |
void begin() { | |
Serial.begin(9600); | |
Serial.println("Adafruit GPS library basic test!"); | |
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800 | |
GPS.begin(9600); | |
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude | |
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); | |
// Set the update rate | |
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate | |
// Request updates on antenna status, comment out to keep quiet | |
GPS.sendCommand(PGCMD_ANTENNA); | |
} | |
void read() { | |
GPS.read(); | |
if (GPS.newNMEAreceived()) { | |
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false | |
return; // we can fail to parse a sentence in which case we should just wait for another | |
} | |
if (GPS.fix) { | |
Serial.print("Location: "); | |
Serial.print(GPS.latitude, 4); Serial.print(GPS.lat); | |
Serial.print(", "); | |
Serial.print(GPS.longitude, 4); Serial.println(GPS.lon); | |
} | |
} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "arduino.ceu" | |
#include "gps.ceu" | |
_begin(); | |
loop do | |
_read(); | |
// ouputs unilitialized data: | |
// Location: 0, 0 | |
await 2s; | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "arduino.ceu" | |
#include "gps.ceu" | |
_begin(); | |
loop do | |
// duplicating the update() function in gps.ceu | |
_GPS.read(); | |
if _GPS.newNMEAreceived() then | |
if _GPS.parse(_GPS.lastNMEA()) then | |
await 5s; | |
if _GPS.fix then | |
_Serial.print("Location: "); | |
_Serial.print(_GPS.latitude, 4); _Serial.print(_GPS.lat); | |
_Serial.print(", "); | |
_Serial.print(_GPS.longitude, 4); _Serial.println(_GPS.lon); | |
end | |
// outputs valid location data: | |
// Location: 51.5033630, 48.10202 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like the examples above are not quite the same: you chose different timings (2s vs 5s) and the
await
statements are placed in between different statements (after _read() vs betweenparse
andfix
).Anyway, I think it is a good idea to separate the sensing task from your programs:
Sensing should deal with the details in the GPS protocol and emit some higher level input event into your program. This way, sensing can be reused in any program using GPS.
The program will only deal with the awaits and the control flow of your actual problem domain.
The sensing loop can also be merged with
poll.ino
.