ESP32-PaxCounter/src/gpsread.cpp

48 lines
1.4 KiB
C++
Raw Normal View History

2018-06-08 22:41:37 +02:00
#ifdef HAS_GPS
#include "globals.h"
// Local logging tag
static const char TAG[] = "main";
2018-06-09 17:59:59 +02:00
2018-06-09 22:21:23 +02:00
// read GPS data and cast to global struct
2018-06-09 13:18:59 +02:00
void gps_read(){
2018-06-09 22:21:23 +02:00
gps_status.latitude = (float) gps.location.lat();
gps_status.longitude = (float) gps.location.lng();
gps_status.satellites = (uint8_t) gps.satellites.value();
gps_status.hdop = (uint16_t) gps.hdop.value();
gps_status.altitude = (uint16_t) gps.altitude.meters();
2018-06-09 13:18:59 +02:00
}
2018-06-09 22:21:23 +02:00
// GPS serial feed FreeRTos Task
2018-06-08 22:41:37 +02:00
void gps_loop(void * pvParameters) {
configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check
2018-06-09 19:20:34 +02:00
HardwareSerial GPS_Serial(1);
2018-06-08 22:41:37 +02:00
while(1) {
2018-06-09 19:20:34 +02:00
if (cfg.gpsmode)
{
// if GPS function is enabled try serial connect to GPS device
GPS_Serial.begin(HAS_GPS);
while(cfg.gpsmode) {
// feed GPS decoder with serial NMEA data from GPS device
while (GPS_Serial.available()) {
gps.encode(GPS_Serial.read());
vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog
}
}
// after GPS function was disabled, close connect to GPS device
GPS_Serial.end();
2018-06-08 22:41:37 +02:00
}
2018-06-09 19:20:34 +02:00
2018-06-08 22:41:37 +02:00
vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog
2018-06-09 19:20:34 +02:00
} // end of infinite loop
} // gps_loop()
2018-06-08 22:41:37 +02:00
#endif // HAS_GPS