From 54f9ff116be63cc1e8388161c205394da6285bb9 Mon Sep 17 00:00:00 2001 From: Totoo Date: Sun, 29 Jun 2025 22:47:18 +0200 Subject: [PATCH] AIS map improv (#2725) * AIS map improv * format code mismatch with vc --- firmware/application/apps/ais_app.cpp | 42 +++++++++++++++++++++++++-- firmware/application/apps/ais_app.hpp | 7 +++++ firmware/application/ui/ui_geomap.cpp | 1 + firmware/application/ui/ui_geomap.hpp | 3 +- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/firmware/application/apps/ais_app.cpp b/firmware/application/apps/ais_app.cpp index 3e28fb4e8..07f2045cb 100644 --- a/firmware/application/apps/ais_app.cpp +++ b/firmware/application/apps/ais_app.cpp @@ -301,7 +301,7 @@ AISRecentEntryDetailView::AISRecentEntryDetailView(NavigationView& nav) { ais::format::text(entry_.name), 0, GeoPos::alt_unit::METERS, - GeoPos::spd_unit::NONE, + GeoPos::spd_unit::KNOTS, ais::format::latlon_float(entry_.last_position.latitude.normalized()), ais::format::latlon_float(entry_.last_position.longitude.normalized()), entry_.last_position.true_heading, @@ -324,7 +324,31 @@ AISRecentEntryDetailView& AISRecentEntryDetailView::operator=(const AISRecentEnt void AISRecentEntryDetailView::update_position() { if (send_updates) - geomap_view->update_position(ais::format::latlon_float(entry_.last_position.latitude.normalized()), ais::format::latlon_float(entry_.last_position.longitude.normalized()), (float)entry_.last_position.true_heading, 0, entry_.last_position.speed_over_ground); + geomap_view->update_position(ais::format::latlon_float(entry_.last_position.latitude.normalized()), ais::format::latlon_float(entry_.last_position.longitude.normalized()), (float)entry_.last_position.true_heading, 0, entry_.last_position.speed_over_ground > 1022 ? 0 : entry_.last_position.speed_over_ground); +} + +bool AISRecentEntryDetailView::add_map_marker(const AISRecentEntry& entry) { + if (geomap_view && send_updates) { + GeoMarker marker{}; + marker.lon = ais::format::latlon_float(entry.last_position.longitude.normalized()); + marker.lat = ais::format::latlon_float(entry.last_position.latitude.normalized()); + marker.angle = entry.last_position.true_heading; + marker.tag = entry.call_sign.empty() ? to_string_dec_uint(entry.mmsi) : entry.call_sign; + auto markerStored = geomap_view->store_marker(marker); + return markerStored == MARKER_STORED; + } + return false; +} +void AISRecentEntryDetailView::update_map_markers(AISRecentEntries& entries) { + if (geomap_view && send_updates) { + geomap_view->clear_markers(); + for (const auto& entry : entries) { + // if (entry.last_position.latitude.is_valid() && entry.last_position.longitude.is_valid()) { + add_map_marker(entry); + // } + } + update_position(); // to update view + } } void AISRecentEntryDetailView::focus() { @@ -415,14 +439,27 @@ AISAppView::AISAppView(NavigationView& nav) audio::set_rate(audio::Rate::Hz_24000); audio::output::start(); } + + signal_token_tick_second = rtc_time::signal_tick_second += [this]() { + on_tick_second(); + }; } AISAppView::~AISAppView() { + rtc_time::signal_tick_second -= signal_token_tick_second; audio::output::stop(); receiver_model.disable(); baseband::shutdown(); } +void AISAppView::on_tick_second() { + ++timer_seconds; + if (timer_seconds % 10 == 0) { + if (recent_entry_detail_view.hidden()) return; + recent_entry_detail_view.update_map_markers(recent); + } +} + void AISAppView::focus() { options_channel.focus(); } @@ -461,6 +498,7 @@ void AISAppView::on_show_detail(const AISRecentEntry& entry) { recent_entry_detail_view.hidden(false); recent_entry_detail_view.set_entry(entry); recent_entry_detail_view.focus(); + recent_entry_detail_view.update_map_markers(recent); } } /* namespace ui */ diff --git a/firmware/application/apps/ais_app.hpp b/firmware/application/apps/ais_app.hpp index 8146dd4a0..20bb3a67c 100644 --- a/firmware/application/apps/ais_app.hpp +++ b/firmware/application/apps/ais_app.hpp @@ -125,10 +125,14 @@ class AISRecentEntryDetailView : public View { void update_position(); void focus() override; void paint(Painter&) override; + bool add_map_marker(const AISRecentEntry& entry); + void update_map_markers(AISRecentEntries& entries); AISRecentEntryDetailView(const AISRecentEntryDetailView& Entry); AISRecentEntryDetailView& operator=(const AISRecentEntryDetailView& Entry); + GeoMapView* get_geomap_view() { return geomap_view; } + private: AISRecentEntry entry_{}; @@ -215,6 +219,8 @@ class AISAppView : public View { Channel channel{ {21 * 8, 5, 6 * 8, 4}, }; + SignalToken signal_token_tick_second{}; + uint8_t timer_seconds = 0; MessageHandlerRegistration message_handler_packet{ Message::ID::AISPacket, @@ -229,6 +235,7 @@ class AISAppView : public View { void on_packet(const ais::Packet& packet); void on_show_list(); void on_show_detail(const AISRecentEntry& entry); + void on_tick_second(); }; } /* namespace ui */ diff --git a/firmware/application/ui/ui_geomap.cpp b/firmware/application/ui/ui_geomap.cpp index c98f74bbe..83defae98 100644 --- a/firmware/application/ui/ui_geomap.cpp +++ b/firmware/application/ui/ui_geomap.cpp @@ -110,6 +110,7 @@ GeoPos::GeoPos( text_alt_unit.set(altitude_unit_ ? "m" : "ft"); if (speed_unit_ == KMPH) text_speed_unit.set("kmph"); if (speed_unit_ == MPH) text_speed_unit.set("mph"); + if (speed_unit_ == KNOTS) text_speed_unit.set("knots"); if (speed_unit_ == HIDDEN) { text_speed_unit.hidden(true); label_spd_position.hidden(true); diff --git a/firmware/application/ui/ui_geomap.hpp b/firmware/application/ui/ui_geomap.hpp index 772efedac..621816192 100644 --- a/firmware/application/ui/ui_geomap.hpp +++ b/firmware/application/ui/ui_geomap.hpp @@ -81,6 +81,7 @@ class GeoPos : public View { NONE = 0, MPH, KMPH, + KNOTS, HIDDEN = 255 }; @@ -134,7 +135,7 @@ class GeoPos : public View { {12 * 8, 0 * 16, 2 * 8, 16}, ""}; Text text_speed_unit{ - {25 * 8, 0 * 16, 4 * 8, 16}, + {25 * 8, 0 * 16, 5 * 8, 16}, ""}; NumberField field_lat_degrees{