mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-10 09:58:28 -04:00
ArduCopter: fixed print_latlon bug in which it would print negative lat/lon numbers incorrectly (i.e. -1234567890 would be printed as -124.xxx).
This commit is contained in:
parent
c2d14a5cad
commit
2a216ce900
@ -220,13 +220,20 @@ process_logs(uint8_t argc, const Menu::arg *argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// print_latlon - prints an latitude or longitude value held in an int32_t
|
||||
// probably this should be moved to AP_Common
|
||||
void print_latlon(BetterStream *s, int32_t lat_or_lon)
|
||||
{
|
||||
int32_t dec_portion = lat_or_lon / T7;
|
||||
int32_t frac_portion = labs(lat_or_lon - dec_portion*T7);
|
||||
int32_t dec_portion, frac_portion;
|
||||
|
||||
// extract decimal portion (special handling of negative numbers to ensure we round towards zero)
|
||||
dec_portion = labs(lat_or_lon) / T7;
|
||||
if( lat_or_lon < 0 ){
|
||||
dec_portion = -dec_portion;
|
||||
}
|
||||
|
||||
// extract fractional portion
|
||||
frac_portion = labs(lat_or_lon - dec_portion*T7);
|
||||
s->printf("%ld.%07ld",(long)dec_portion,(long)frac_portion);
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,17 @@ AP_GPS_Auto GPS(&Serial1, &gps);
|
||||
// probably this should be moved to AP_Common
|
||||
void print_latlon(BetterStream *s, int32_t lat_or_lon)
|
||||
{
|
||||
int32_t dec_portion = lat_or_lon / T7;
|
||||
int32_t frac_portion = labs(lat_or_lon - dec_portion*T7);
|
||||
s->printf("%ld.%07ld",dec_portion,frac_portion);
|
||||
int32_t dec_portion, frac_portion;
|
||||
|
||||
// extract decimal portion (special handling of negative numbers to ensure we round towards zero)
|
||||
dec_portion = labs(lat_or_lon) / T7;
|
||||
if( lat_or_lon < 0 ){
|
||||
dec_portion = -dec_portion;
|
||||
}
|
||||
|
||||
// extract fractional portion
|
||||
frac_portion = labs(lat_or_lon - dec_portion*T7);
|
||||
s->printf("%ld.%07ld",(long)dec_portion,(long)frac_portion);
|
||||
}
|
||||
|
||||
void setup()
|
||||
|
Loading…
Reference in New Issue
Block a user