Skip to content

Instantly share code, notes, and snippets.

@carlosdelfino
Created August 14, 2012 21:09
Show Gist options
  • Save carlosdelfino/3353069 to your computer and use it in GitHub Desktop.
Save carlosdelfino/3353069 to your computer and use it in GitHub Desktop.
Leitura do GPS, atualmente uso GPS_PRIORIZE = 1
inline boolean newNMEAreceived() {
return !resetingGPS && gps.newNMEAreceived();
}
void lerGPS(){
if (!serialOff()) {
#if GPS_PRIORIZE > 2
for (uint8_t i = 6; nmea_rb.ahead && nmea_rb.head != nmea_rb.tail && i > 0; --i) {
// if the head isn't ahead of the tail, we don't have any characters
volatile char* lastNMEA = nmea_rb.buffer[nmea_rb.tail];
uint8_t oldtail = nmea_rb.tail;
nmea_rb.tail = (uint8_t) (nmea_rb.tail + 1)
% NMEA_BUFFER_SIZE;
nmea_rb.swith &= nmea_rb.tail >oldtail;//se verdadeiro indica que não virou ainda.
if(nmea_rb.swith)
nmea_rb.ahead = nmea_rb.tail >= nmea_rb.head;
else
nmea_rb.ahead = nmea_rb.tail <= nmea_rb.head;
Serial.println((char*) lastNMEA);// this also sets the newNMEAreceived() flag to false
}
#endif
#if GPS_PRIORIZE == 1
if (newNMEAreceived()) {
// a tricky thing here is if we print the NMEA sentence, or data
// we end up not listening and catching other sentences!
// so be very wary if using OUTPUT_ALLDATA and trytng to print out data
char* lastNMEA = gps.lastNMEA();
if (!serialOff()) {
Serial.println(lastNMEA); // this also sets the newNMEAreceived() flag to false
}
} else {
gpsNoNewNMEACount++;
if (gpsNoNewNMEACount > GPS_NO_NMEA_COUNT_LIMIT
&& (millis() - gpsNoNewNMEACountShowTime)
> GPS_NO_NMEA_COUNT_SHOW_TIME_LIMIT
&& !serialOff()) {
Serial.print(PROTO_PREAMBULO);
Serial.print("1110,");
Serial.print((float) millis() / 1000);
Serial.print(PROTO_SEPARADOR);
Serial.print(gpsNoNewNMEACount);
Serial.println("*");
gpsNoNewNMEACountShowTime = millis();
}
}
#endif
}
}
// Interrupt is called once a millisecond,
// looks for any new GPS data, and stores it
ISR(TIMER0_COMPA_vect) {
if (!resetingGPS) {
#if GPS_PRIORIZE > 10
while (GPS_Serial.available()) {
#endif
gps.read();
#if GPS_PRIORIZE > 2
if (newNMEAreceived()) {
uint8_t i = (uint8_t) (nmea_rb.head + 1) % NMEA_BUFFER_SIZE;
// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
if (i != nmea_rb.tail) {
nmea_rb.buffer[nmea_rb.head] = gps.lastNMEA();
nmea_rb.head = i;
}
}
#endif
#if GPS_PRIORIZE > 10
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment