From 3943848add2eb14db77d1906565b4ef1d4eaa5f4 Mon Sep 17 00:00:00 2001 From: Totoo Date: Thu, 11 Jan 2024 22:17:06 +0100 Subject: [PATCH] GPS + orientation for Sonde (#1757) * RadioSonde has gpsdata * Orientation update in Sonde --- firmware/application/apps/ui_sonde.cpp | 16 +++++++++++++++- firmware/application/apps/ui_sonde.hpp | 19 +++++++++++++++++++ firmware/application/ui/ui_geomap.cpp | 10 +++++++--- firmware/application/ui/ui_geomap.hpp | 4 ++-- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/firmware/application/apps/ui_sonde.cpp b/firmware/application/apps/ui_sonde.cpp index b809e591..b3691f1b 100644 --- a/firmware/application/apps/ui_sonde.cpp +++ b/firmware/application/apps/ui_sonde.cpp @@ -90,7 +90,7 @@ SondeView::SondeView(NavigationView& nav) }; button_see_map.on_select = [this, &nav](Button&) { - nav.push( + geomap_view_ = nav.push( sonde_id, gps_info.alt, GeoPos::alt_unit::METERS, @@ -98,6 +98,9 @@ SondeView::SondeView(NavigationView& nav) gps_info.lat, gps_info.lon, 999); // set a dummy heading out of range to draw a cross...probably not ideal? + nav.set_on_pop([this]() { + geomap_view_ = nullptr; + }); }; logger = std::make_unique(); @@ -124,6 +127,17 @@ SondeView::~SondeView() { audio::output::stop(); } +void SondeView::on_gps(const GPSPosDataMessage* msg) { + if (!geomap_view_) + return; + geomap_view_->update_my_position(msg->lat, msg->lon, msg->altitude); +} +void SondeView::on_orientation(const OrientationDataMessage* msg) { + if (!geomap_view_) + return; + geomap_view_->update_my_orientation(msg->angle, true); +} + void SondeView::focus() { field_frequency.focus(); } diff --git a/firmware/application/apps/ui_sonde.hpp b/firmware/application/apps/ui_sonde.hpp index d93b90be..aa5e3e34 100644 --- a/firmware/application/apps/ui_sonde.hpp +++ b/firmware/application/apps/ui_sonde.hpp @@ -60,6 +60,8 @@ class SondeView : public View { SondeView(NavigationView& nav); ~SondeView(); + SondeView(const SondeView& other) = delete; + SondeView& operator=(const SondeView& other) = delete; void focus() override; @@ -173,6 +175,8 @@ class SondeView : public View { {16 * 8, 15 * 16, 12 * 8, 3 * 16}, "See on map"}; + GeoMapView* geomap_view_{nullptr}; + MessageHandlerRegistration message_handler_packet{ Message::ID::SondePacket, [this](Message* const p) { @@ -181,6 +185,21 @@ class SondeView : public View { this->on_packet(packet); }}; + MessageHandlerRegistration message_handler_gps{ + Message::ID::GPSPosData, + [this](Message* const p) { + const auto message = static_cast(p); + this->on_gps(message); + }}; + MessageHandlerRegistration message_handler_orientation{ + Message::ID::OrientationData, + [this](Message* const p) { + const auto message = static_cast(p); + this->on_orientation(message); + }}; + + void on_gps(const GPSPosDataMessage* msg); + void on_orientation(const OrientationDataMessage* msg); void on_packet(const sonde::Packet& packet); char* float_to_char(float x, char* p); }; diff --git a/firmware/application/ui/ui_geomap.cpp b/firmware/application/ui/ui_geomap.cpp index f06fa560..b277e44b 100644 --- a/firmware/application/ui/ui_geomap.cpp +++ b/firmware/application/ui/ui_geomap.cpp @@ -516,8 +516,12 @@ void GeoMap::update_my_position(float lat, float lon, int32_t altitude) { markerListUpdated = true; set_dirty(); } -void GeoMap::update_my_orientation(uint16_t angle) { +void GeoMap::update_my_orientation(uint16_t angle, bool refresh) { my_angle = angle; + if (refresh) { + markerListUpdated = true; + set_dirty(); + } } void GeoMapView::focus() { @@ -530,8 +534,8 @@ void GeoMapView::focus() { void GeoMapView::update_my_position(float lat, float lon, int32_t altitude) { geomap.update_my_position(lat, lon, altitude); } -void GeoMapView::update_my_orientation(uint16_t angle) { - geomap.update_my_orientation(angle); +void GeoMapView::update_my_orientation(uint16_t angle, bool refresh) { + geomap.update_my_orientation(angle, refresh); } void GeoMapView::update_position(float lat, float lon, uint16_t angle, int32_t altitude, int32_t speed) { diff --git a/firmware/application/ui/ui_geomap.hpp b/firmware/application/ui/ui_geomap.hpp index a8849250..1e0245b3 100644 --- a/firmware/application/ui/ui_geomap.hpp +++ b/firmware/application/ui/ui_geomap.hpp @@ -186,7 +186,7 @@ class GeoMap : public Widget { bool on_keyboard(const KeyboardEvent event) override; void update_my_position(float lat, float lon, int32_t altitude); - void update_my_orientation(uint16_t angle); + void update_my_orientation(uint16_t angle, bool refresh = false); bool init(); void set_mode(GeoMapMode mode); @@ -278,7 +278,7 @@ class GeoMapView : public View { void update_position(float lat, float lon, uint16_t angle, int32_t altitude, int32_t speed = 0); void update_my_position(float lat, float lon, int32_t altitude); - void update_my_orientation(uint16_t angle); + void update_my_orientation(uint16_t angle, bool refresh = false); std::string title() const override { return "Map view"; };