Fix GPS overflow

This commit is contained in:
3djc
2019-05-19 09:11:33 +02:00
parent 824e2bd23b
commit ddc92c237e
2 changed files with 2 additions and 1 deletions
+1
View File
@@ -1279,6 +1279,7 @@ extern uint8_t s_frsky_view;
#endif #endif
constexpr uint32_t EARTH_RADIUS = 6371009; constexpr uint32_t EARTH_RADIUS = 6371009;
constexpr uint32_t PRECALCULATED_EARTH_RADIUS_CONSTANT = 111194; // meters * pi / 180°
void getGpsPilotPosition(); void getGpsPilotPosition();
void getGpsDistance(); void getGpsDistance();
+1 -1
View File
@@ -355,7 +355,7 @@ void TelemetryItem::eval(const TelemetrySensor & sensor)
} }
} }
uint32_t angle = abs(gpsItem.gps.latitude - gpsItem.pilotLatitude); uint32_t angle = abs(gpsItem.gps.latitude - gpsItem.pilotLatitude);
uint32_t dist = ((uint64_t )EARTH_RADIUS * M_PI / 180) * angle) / 1000000; uint32_t dist = ((uint64_t)PRECALCULATED_EARTH_RADIUS_CONSTANT * angle) / 1000000;
uint32_t result = dist * dist; uint32_t result = dist * dist;
angle = abs(gpsItem.gps.longitude - gpsItem.pilotLongitude); angle = abs(gpsItem.gps.longitude - gpsItem.pilotLongitude);