Skip to content

Commit e6a2c06

Browse files
authored
Various position fixes (meshtastic#3297)
* Guard against no movement * Add newlines * Fix printfs
1 parent ce0e5c0 commit e6a2c06

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

src/gps/GPS.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ bool GPS::setup()
319319
delay(250);
320320
_serial_gps->write("$CFGMSG,6,1,0\r\n");
321321
delay(250);
322-
323322
} else if (gnssModel == GNSS_MODEL_UBLOX) {
324323
// Configure GNSS system to GPS+SBAS+GLONASS (Module may restart after this command)
325324
// We need set it because by default it is GPS only, and we want to use GLONASS too
@@ -458,7 +457,6 @@ bool GPS::setup()
458457
LOG_WARN("Unable to enable NMEA 4.10.\n");
459458
}
460459
}
461-
462460
} else {
463461
if (strncmp(info.hwVersion, "00040007", 8) == 0) { // This PSM mode is only for Neo-6
464462
msglen = makeUBXPacket(0x06, 0x11, 0x2, _message_CFG_RXM_ECO);
@@ -642,12 +640,12 @@ void GPS::setGPSPower(bool on, bool standbyOnly, uint32_t sleepTime)
642640
#endif
643641
#ifdef PIN_GPS_STANDBY // Specifically the standby pin for L76K and clones
644642
if (on) {
645-
LOG_INFO("Waking GPS");
643+
LOG_INFO("Waking GPS\n");
646644
pinMode(PIN_GPS_STANDBY, OUTPUT);
647645
digitalWrite(PIN_GPS_STANDBY, 1);
648646
return;
649647
} else {
650-
LOG_INFO("GPS entering sleep");
648+
LOG_INFO("GPS entering sleep\n");
651649
// notifyGPSSleep.notifyObservers(NULL);
652650
pinMode(PIN_GPS_STANDBY, OUTPUT);
653651
digitalWrite(PIN_GPS_STANDBY, 0);

src/gps/GeoCoord.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,17 @@ void GeoCoord::convertWGS84ToOSGB36(const double lat, const double lon, double &
376376
}
377377

378378
/// Ported from my old java code, returns distance in meters along the globe
379-
/// surface (by magic?)
379+
/// surface (by Haversine formula)
380380
float GeoCoord::latLongToMeter(double lat_a, double lng_a, double lat_b, double lng_b)
381381
{
382-
double pk = (180 / 3.14169);
383-
double a1 = lat_a / pk;
384-
double a2 = lng_a / pk;
385-
double b1 = lat_b / pk;
386-
double b2 = lng_b / pk;
382+
// Don't do math if the points are the same
383+
if (lat_a == lat_b && lng_a == lng_b)
384+
return 0.0;
385+
386+
double a1 = lat_a / DEG_CONVERT;
387+
double a2 = lng_a / DEG_CONVERT;
388+
double b1 = lat_b / DEG_CONVERT;
389+
double b2 = lng_b / DEG_CONVERT;
387390
double cos_b1 = cos(b1);
388391
double cos_a1 = cos(a1);
389392
double t1 = cos_a1 * cos(a2) * cos_b1 * cos(b2);

src/gps/GeoCoord.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#define PI 3.1415926535897932384626433832795
1313
#define OLC_CODE_LEN 11
14+
#define DEG_CONVERT 180 / PI
1415

1516
// Helper functions
1617
// Raises a number to an exponent, handling negative exponents.

src/modules/PositionModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ struct SmartPosition PositionModule::getDistanceTraveledSinceLastSend(meshtastic
372372
LOG_DEBUG("currentPosition.latitude_i=%i, currentPosition.longitude_i=%i\n", lastGpsLatitude, lastGpsLongitude);
373373

374374
LOG_DEBUG("--------SMART POSITION-----------------------------------\n");
375-
LOG_DEBUG("hasTraveledOverThreshold=%i, distanceTraveled=%d, distanceThreshold=% u\n",
375+
LOG_DEBUG("hasTraveledOverThreshold=%i, distanceTraveled=%f, distanceThreshold=%f\n",
376376
abs(distanceTraveledSinceLastSend) >= distanceTravelThreshold, abs(distanceTraveledSinceLastSend),
377377
distanceTravelThreshold);
378378

0 commit comments

Comments
 (0)