From 89f7968ca2690fdfbf0abf1bdb1cac18873f09a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 17 May 2022 13:03:14 +0200 Subject: [PATCH 1/5] don't wake t-echo through the touch button --- src/main.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 00a540b51..4c11d096e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -226,10 +226,6 @@ class ButtonThread : public OSThread #ifdef BUTTON_PIN_TOUCH userButtonTouch = OneButton(BUTTON_PIN_TOUCH, true, true); -#ifdef INPUT_PULLUP_SENSE - // Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did - pinMode(BUTTON_PIN_TOUCH, INPUT_PULLUP_SENSE); -#endif userButtonTouch.attachClick(touchPressed); userButtonTouch.attachDuringLongPress(touchPressedLong); userButtonTouch.attachDoubleClick(touchDoublePressed); From 8d74c41802c9e8bfb73990039911dccf796885b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 17 May 2022 18:57:42 +0200 Subject: [PATCH 2/5] switch GPS back to 9600 baud, seems to work better now we only use the 2 sentences --- src/gps/GPS.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index a02142697..fe0228222 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -37,13 +37,17 @@ bool GPS::setupGPS() _serial_gps->setRxBufferSize(2048); // the default is 256 #endif #ifdef TTGO_T_ECHO - // Switch to 4800 baud, then close and reopen port - _serial_gps->write("$PCAS01,0*1C\r\n"); - delay(250); + // Switch to 9600 baud, then close and reopen port _serial_gps->end(); delay(250); _serial_gps->begin(4800); delay(250); + _serial_gps->write("$PCAS01,1*1D\r\n"); + delay(250); + _serial_gps->end(); + delay(250); + _serial_gps->begin(9600); + delay(250); // Initialize the L76K Chip, use GPS + GLONASS _serial_gps->write("$PCAS04,5*1C\r\n"); delay(250); @@ -53,7 +57,6 @@ bool GPS::setupGPS() // Switch to Vehicle Mode, since SoftRF enables Aviation < 2g _serial_gps->write("$PCAS11,3*1E\r\n"); delay(250); - #endif #ifdef GPS_UBLOX // Set the UART port to output NMEA only From f3cc732e7dce6efb38217d1be80128954ad92bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 17 May 2022 19:44:41 +0200 Subject: [PATCH 3/5] Print error codes and returns during UBX config --- src/gps/GPS.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++------ src/gps/GPS.h | 2 ++ 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index fe0228222..a6cd31cc3 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -22,6 +22,52 @@ GPS *gps; /// only init that port once. static bool didSerialInit; +bool GPS::getACK(uint8_t c, uint8_t i) { + uint8_t b; + uint8_t ack = 0; + uint8_t ackP[2] = {c, i}; + uint8_t buf[250]; + unsigned long startTime = millis(); + + buf[0] = 0xB5; + buf[1] = 0x62; + buf[2] = 0x05; + buf[3] = 0x01; + buf[4] = 0x02; + buf[5] = 0x00; + buf[8] = 0x00; + buf[9] = 0x00; + + for (int i = 2; i < 6; i++) { + buf[8] += buf[i]; + buf[9] += buf[8]; + } + + for (int i = 0; i < 2; i++) { + buf[6+i] = ackP[i]; + buf[8] += buf[6+i]; + buf[9] += buf[8]; + } + + while (1) { + if (ack > 9) { + return true; + } + if (millis() - startTime > 2000) { + return false; + } + if (_serial_gps->available()) { + b = _serial_gps->read(); + if (b == buf[ack]) { + ack++; + } + else { + ack = 0; + } + } + } +} + bool GPS::setupGPS() { if (_serial_gps && !didSerialInit) { @@ -64,49 +110,49 @@ bool GPS::setupGPS() 0x01, 0x00, 0x00, 0x00, 0xC0, 0x08, 0x00, 0x00, 0x80, 0x25, 0x00, 0x00, 0x07, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, 0xAF}; _serial_gps->write(_message_nmea,sizeof(_message_nmea)); - delay(250); + if (!getACK(0x06, 0x00)) DEBUG_MSG("WARNING: Unable to set UART.\n"); // disable GGL byte _message_GGL[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x05,0x3A}; _serial_gps->write(_message_GGL,sizeof(_message_GGL)); - delay(250); + if (!getACK(0x06, 0x01)) DEBUG_MSG("WARNING: Unable to disable NMEA GGL.\n"); // disable GSA byte _message_GSA[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x02, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x06,0x41}; _serial_gps->write(_message_GSA,sizeof(_message_GSA)); - delay(250); + if (!getACK(0x06, 0x01)) DEBUG_MSG("WARNING: Unable to disable NMEA GSA.\n"); // disable GSV byte _message_GSV[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x03, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x07,0x48}; _serial_gps->write(_message_GSV,sizeof(_message_GSV)); - delay(250); + if (!getACK(0x06, 0x01)) DEBUG_MSG("WARNING: Unable to disable NMEA GSV.\n"); // disable VTG byte _message_VTG[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x05, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x09,0x56}; _serial_gps->write(_message_VTG,sizeof(_message_VTG)); - delay(250); + if (!getACK(0x06, 0x01)) DEBUG_MSG("WARNING: Unable to disable NMEA VTG.\n"); // enable RMC byte _message_RMC[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x04, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x09,0x54}; _serial_gps->write(_message_RMC,sizeof(_message_RMC)); - delay(250); + if (!getACK(0x06, 0x01)) DEBUG_MSG("WARNING: Unable to enable NMEA RMC.\n"); // enable GGA byte _message_GGA[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x05, 0x38}; _serial_gps->write(_message_GGA,sizeof(_message_GGA)); - delay(250); + if (!getACK(0x06, 0x01)) DEBUG_MSG("WARNING: Unable to enable NMEA GGA.\n"); #endif } diff --git a/src/gps/GPS.h b/src/gps/GPS.h index 5724889fe..b4716af76 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -137,6 +137,8 @@ class GPS : private concurrency::OSThread GpsOperation getGpsOp() const; + bool getACK(uint8_t cl, uint8_t id); + /** * Tell users we have new GPS readings */ From f251727524f0b725ca3b3067a0333289054b73fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 17 May 2022 19:47:59 +0200 Subject: [PATCH 4/5] wrong header file --- src/gps/GPS.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gps/GPS.h b/src/gps/GPS.h index b4716af76..836114d2e 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -137,7 +137,7 @@ class GPS : private concurrency::OSThread GpsOperation getGpsOp() const; - bool getACK(uint8_t cl, uint8_t id); + bool getACK(uint8_t c, uint8_t i); /** * Tell users we have new GPS readings From 3fded9aaa9f812b59ece319df3d7e94d3d1f683e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 17 May 2022 21:02:00 +0200 Subject: [PATCH 5/5] don't be too smart --- src/gps/GPS.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index a6cd31cc3..9a2c073f9 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -25,7 +25,7 @@ static bool didSerialInit; bool GPS::getACK(uint8_t c, uint8_t i) { uint8_t b; uint8_t ack = 0; - uint8_t ackP[2] = {c, i}; + const uint8_t ackP[2] = {c, i}; uint8_t buf[250]; unsigned long startTime = millis(); @@ -38,14 +38,14 @@ bool GPS::getACK(uint8_t c, uint8_t i) { buf[8] = 0x00; buf[9] = 0x00; - for (int i = 2; i < 6; i++) { - buf[8] += buf[i]; + for (int j = 2; j < 6; j++) { + buf[8] += buf[j]; buf[9] += buf[8]; } - for (int i = 0; i < 2; i++) { - buf[6+i] = ackP[i]; - buf[8] += buf[6+i]; + for (int j = 0; j < 2; j++) { + buf[6 + j] = ackP[j]; + buf[8] += buf[6 + j]; buf[9] += buf[8]; }