diff --git a/include/taskGPS.h b/include/taskGPS.h new file mode 100644 index 0000000..5588a6c --- /dev/null +++ b/include/taskGPS.h @@ -0,0 +1,5 @@ +#include +#include + +extern TinyGPSPlus gps; +void taskGPS(void *parameter); diff --git a/src/TTGO_T-Beam_LoRa_APRS.ino b/src/TTGO_T-Beam_LoRa_APRS.ino index 296ef22..a4feb9c 100644 --- a/src/TTGO_T-Beam_LoRa_APRS.ino +++ b/src/TTGO_T-Beam_LoRa_APRS.ino @@ -9,7 +9,6 @@ #include #include #include // library from OE1ACM -#include #include #include #include @@ -22,6 +21,7 @@ #include #include #include +#include "taskGPS.h" #ifdef ENABLE_BLUETOOTH #include "BluetoothSerial.h" @@ -43,9 +43,6 @@ String inTNCData = ""; int button=0; int button_ctr=0; -// Pins for GPS -static const int RXPin = 12, TXPin = 34; // changed BG A3 A2 -static const uint32_t GPSBaud = 9600; //GPS // LED for signalling const byte TXLED = 33; //pin number for LED on TX Tracker @@ -114,8 +111,7 @@ void displayInvalidGPS(); void handleKISSData(char character); -HardwareSerial gpsSerial(1); // TTGO has HW serial -TinyGPSPlus gps; // The TinyGPS++ object + AXP20X_Class axp; // checkRX @@ -137,15 +133,7 @@ BluetoothSerial SerialBT; // This custom version of delay() ensures that the gps object // is being "fed". static void smartDelay(unsigned long ms){ - #ifdef KISS_PROTOCOL - delay(10); - return; - #endif - unsigned long start = millis(); - do{ - while (gpsSerial.available()) - gps.encode(gpsSerial.read()); - } while (millis() - start < ms); + vTaskDelay(ms/portTICK_PERIOD_MS); } char *ax25_base91enc(char *s, uint8_t n, uint32_t v){ @@ -353,15 +341,9 @@ void setup(){ max_time_to_nextTX=nextTX; } writedisplaytext("LoRa-APRS","","Init:","RF95 OK!","","",250); - gpsSerial.begin(GPSBaud, SERIAL_8N1, TXPin, RXPin); //Startup HW serial for GPS - writedisplaytext("LoRa-APRS","","Init:","GPS Serial OK!","","",250); writedisplaytext(" "+Tcall,"","Init:","Waiting for GPS","","",250); - while (millis() < 5000 && gps.charsProcessed() < 10) {} - if (millis() > 5000 && gps.charsProcessed() < 10) { - writedisplaytext(" "+Tcall,"","Init:","ERROR!","No GPS data!","Please restart TTGO",0); - while (true) {} - } - writedisplaytext(" "+Tcall,"","Init:","Data from GPS OK!","","",250); + xTaskCreate(taskGPS, "taskGPS", 10000, NULL, 1, NULL); + writedisplaytext(" "+Tcall,"","Init:","GPS Task Created!","","",250); writedisplaytext("LoRa-APRS","","Init:","ADC OK!","BAT: "+String(axp.getBattVoltage()/1000,1),"",250); rf95.setFrequency(433.775); rf95.setModemConfig(BG_RF95::Bw125Cr45Sf4096); // hard coded because of double definition @@ -383,9 +365,6 @@ void setup(){ // +---------------------------------------------------------------------+// void loop() { - while (gpsSerial.available() > 0) { - gps.encode(gpsSerial.read()); - } #ifdef KISS_PROTOCOL while (Serial.available() > 0 ){ @@ -543,6 +522,7 @@ void loop() { } #endif #endif + vTaskDelay(1); } void handleKISSData(char character) { diff --git a/src/taskGPS.cpp b/src/taskGPS.cpp new file mode 100644 index 0000000..ec98df1 --- /dev/null +++ b/src/taskGPS.cpp @@ -0,0 +1,20 @@ +#include + +// Pins for GPS +static const int RXPin = 12, TXPin = 34; // changed BG A3 A2 +static const uint32_t GPSBaud = 9600; //GPS +HardwareSerial gpsSerial(1); // TTGO has HW serial +TinyGPSPlus gps; // The TinyGPS++ object +bool gpsInitialized = false; + +void taskGPS(void *parameter) { + if (!gpsInitialized){ + gpsSerial.begin(GPSBaud, SERIAL_8N1, TXPin, RXPin); //Startup HW serial for GPS + } + for (;;) { + while (gpsSerial.available() > 0) { + gps.encode(gpsSerial.read()); + } + vTaskDelay(100 / portTICK_PERIOD_MS); + } +}