Skip to content

Commit

Permalink
Fixes to the log and screen rendering of the geo coordinates.
Browse files Browse the repository at this point in the history
  • Loading branch information
teixeluis committed Jun 23, 2021
1 parent 2ceb49e commit 97349b0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
37 changes: 31 additions & 6 deletions firmware/application/apps/ui_adsb_rx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Boston, MA 02110-1301, USA.
*/


#include "ui_adsb_rx.hpp"
#include "ui_alphanum.hpp"

Expand Down Expand Up @@ -233,14 +234,38 @@ void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
entry.set_frame_pos(frame, raw_data[6] & 4);

if (entry.pos.valid) {
std::string latitude_str(8, '\0');
std::string longitude_str(8, '\0');

int written = std::snprintf(&latitude_str[0], latitude_str.size(), "%.2f", entry.pos.latitude);
latitude_str.resize(written);

written = std::snprintf(&longitude_str[0], longitude_str.size(), "%.2f", entry.pos.longitude);
longitude_str.resize(written);

str_info = "Alt:" + to_string_dec_int(entry.pos.altitude) +
" Lat:" + to_string_dec_int(entry.pos.latitude) +
"." + to_string_dec_int((int)abs(entry.pos.latitude * 1000) % 100, 2, '0') +
" Lon:" + to_string_dec_int(entry.pos.longitude) +
"." + to_string_dec_int((int)abs(entry.pos.longitude * 1000) % 100, 2, '0');

" Lat:" + latitude_str +
" Lon:" + longitude_str;

// printing the coordinates in the log file with more
// resolution, as we are not constrained by screen
// real estate there:

latitude_str.resize(13, '\0');
longitude_str.resize(13, '\0');

written = std::snprintf(&latitude_str[0], latitude_str.size(), "%.7f", entry.pos.latitude);
latitude_str.resize(written);

written = std::snprintf(&longitude_str[0], longitude_str.size(), "%.7f", entry.pos.longitude);
longitude_str.resize(written);

std::string log_info = "Alt:" + to_string_dec_int(entry.pos.altitude) +
" Lat:" + latitude_str +
" Lon:" + longitude_str;

entry.set_info_string(str_info);
logentry+=str_info+ " ";
logentry+=log_info + " ";

if (send_updates)
details_view->update(entry);
Expand Down
6 changes: 6 additions & 0 deletions firmware/common/adsb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ int cpr_NL_approx(float lat) {
}

int cpr_NL(float lat) {
// TODO prove that the approximate function is good
// enough for the precision we need. Uncomment if
// that is true:

//return cpr_NL_approx(lat);

return cpr_NL_precise(lat);
}

Expand Down

0 comments on commit 97349b0

Please sign in to comment.