stanleyhuangyc / ArduinoOBD

OBD-II library and sketches for Arduino
http://freematics.com
977 stars 519 forks source link

lat/long display bug #1

Closed krausmt closed 11 years ago

krausmt commented 11 years ago

The code assumes that latitude and longitude are always positive. If you are in China, I suppose this is true. But in the USA, longitude is going to be WEST and the convention is that negative numbers are used. Likewise, in the southern hemisphere, latitude will be negative. The affected code is this:

// megalogger.ino: lines 377 and 380 (version 2013-08-28)
sprintf(buf, "%d.%ld", (int)(lat / 100000), lat % 100000);
sprintf(buf, "%d.%ld", (int)(lon / 100000), lon % 100000);

In the USA, the longitude might print out something like this:

-127.-33654

The suggested change is something like this:

sprintf(buf, "%d.%ld", (int)(lat / 100000), abs(lat) % 100000);
sprintf(buf, "%d.%ld", (int)(lon / 100000), abs(lon) % 100000);
stanleyhuangyc commented 11 years ago

Thanks for this! I can't notice this if I am not on the west hemisphere. I've committed it.