From 6e0aa79d4458422e5912598c70833db287b6b932 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Thu, 14 Jan 2016 09:41:58 -0800 Subject: [PATCH] Move app-level config to new AISAppView class. --- firmware/application/ais_app.cpp | 60 +++++++++++++++++--------------- firmware/application/ais_app.hpp | 19 +++++----- 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/firmware/application/ais_app.cpp b/firmware/application/ais_app.cpp index b062621fe..e6b591fb7 100644 --- a/firmware/application/ais_app.cpp +++ b/firmware/application/ais_app.cpp @@ -163,36 +163,11 @@ void AISRecentEntries::truncate_entries() { namespace ui { -AISRecentEntriesView::AISRecentEntriesView() { +AISRecentEntriesView::AISRecentEntriesView( + AISRecentEntries& recent +) : recent { recent } +{ flags.focusable = true; - - EventDispatcher::message_map().register_handler(Message::ID::AISPacket, - [this](Message* const p) { - const auto message = static_cast(p); - const ais::Packet packet { message->packet }; - if( packet.is_valid() ) { - this->logger.on_packet(packet); - this->on_packet(packet); - } - } - ); - - receiver_model.set_baseband_configuration({ - .mode = 3, - .sampling_rate = 2457600, - .decimation_factor = 1, - }); - receiver_model.set_baseband_bandwidth(1750000); -} - -AISRecentEntriesView::~AISRecentEntriesView() { - EventDispatcher::message_map().unregister_handler(Message::ID::AISPacket); -} - -void AISRecentEntriesView::on_packet(const ais::Packet& packet) { - recent.on_packet(packet); - - set_dirty(); } void AISRecentEntriesView::on_focus() { @@ -296,6 +271,27 @@ AISAppView::AISAppView() { add_children({ { &recent_entries_view, } }); + + EventDispatcher::message_map().register_handler(Message::ID::AISPacket, + [this](Message* const p) { + const auto message = static_cast(p); + const ais::Packet packet { message->packet }; + if( packet.is_valid() ) { + this->on_packet(packet); + } + } + ); + + receiver_model.set_baseband_configuration({ + .mode = 3, + .sampling_rate = 2457600, + .decimation_factor = 1, + }); + receiver_model.set_baseband_bandwidth(1750000); +} + +AISAppView::~AISAppView() { + EventDispatcher::message_map().unregister_handler(Message::ID::AISPacket); } void AISAppView::set_parent_rect(const Rect new_parent_rect) { @@ -303,4 +299,10 @@ void AISAppView::set_parent_rect(const Rect new_parent_rect) { recent_entries_view.set_parent_rect({ 0, 0, new_parent_rect.width(), new_parent_rect.height() }); } +void AISAppView::on_packet(const ais::Packet& packet) { + logger.on_packet(packet); + recent.on_packet(packet); + recent_entries_view.set_dirty(); +} + } /* namespace ui */ diff --git a/firmware/application/ais_app.hpp b/firmware/application/ais_app.hpp index 4f4251717..4c4159f3a 100644 --- a/firmware/application/ais_app.hpp +++ b/firmware/application/ais_app.hpp @@ -108,8 +108,7 @@ namespace ui { class AISRecentEntriesView : public View { public: - AISRecentEntriesView(); - ~AISRecentEntriesView(); + AISRecentEntriesView(AISRecentEntries& recent); void paint(Painter& painter) override; @@ -119,29 +118,31 @@ public: bool on_encoder(const EncoderEvent event) override; private: - AISLogger logger; - + AISRecentEntries& recent; + using EntryKey = ais::MMSI; EntryKey selected_key; const EntryKey invalid_key = 0xffffffff; bool has_focus = false; - AISRecentEntries recent; - - void on_packet(const ais::Packet& packet); - void advance(const int32_t amount); }; class AISAppView : public View { public: AISAppView(); + ~AISAppView(); void set_parent_rect(const Rect new_parent_rect) override; private: - AISRecentEntriesView recent_entries_view; + AISRecentEntries recent; + AISLogger logger; + + AISRecentEntriesView recent_entries_view { recent }; + + void on_packet(const ais::Packet& packet); }; } /* namespace ui */