From aa249cbad479f07a85cf760d69374c2be240ea82 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Thu, 14 Jan 2016 22:39:58 -0800 Subject: [PATCH] Add AIS detail view. --- firmware/application/ais_app.cpp | 57 ++++++++++++++++++++++++++++++++ firmware/application/ais_app.hpp | 30 +++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/firmware/application/ais_app.cpp b/firmware/application/ais_app.cpp index 83e8fc0aa..d56e894a5 100644 --- a/firmware/application/ais_app.cpp +++ b/firmware/application/ais_app.cpp @@ -197,6 +197,19 @@ bool AISRecentEntriesView::on_encoder(const EncoderEvent event) { return true; } +bool AISRecentEntriesView::on_key(const ui::KeyEvent event) { + if( event == ui::KeyEvent::Select ) { + if( on_select ) { + const auto selected = recent.find_by_mmsi(selected_key); + if( selected != std::end(recent) ) { + on_select(*selected); + return true; + } + } + } + return false; +} + static void ais_list_item_draw( const AISRecentEntry& entry, const Rect& target_rect, @@ -265,11 +278,34 @@ void AISRecentEntriesView::advance(const int32_t amount) { set_dirty(); } +AISRecentEntryDetailView::AISRecentEntryDetailView() { + add_children({ { + &button_done, + } }); + + button_done.on_select = [this](const ui::Button&) { + if( this->on_close ) { + this->on_close(); + } + }; +} + +void AISRecentEntryDetailView::focus() { + button_done.focus(); +} + +void AISRecentEntryDetailView::set_entry(const AISRecentEntry& new_entry) { + entry = new_entry; +} + AISAppView::AISAppView() { add_children({ { &recent_entries_view, + &recent_entry_detail_view, } }); + recent_entry_detail_view.hidden(true); + EventDispatcher::message_map().register_handler(Message::ID::AISPacket, [this](Message* const p) { const auto message = static_cast(p); @@ -286,6 +322,13 @@ AISAppView::AISAppView() { .decimation_factor = 1, }); receiver_model.set_baseband_bandwidth(1750000); + + recent_entries_view.on_select = [this](const AISRecentEntry& entry) { + this->on_show_detail(entry); + }; + recent_entry_detail_view.on_close = [this]() { + this->on_show_list(); + }; } AISAppView::~AISAppView() { @@ -295,6 +338,7 @@ AISAppView::~AISAppView() { void AISAppView::set_parent_rect(const Rect new_parent_rect) { View::set_parent_rect(new_parent_rect); recent_entries_view.set_parent_rect({ 0, 0, new_parent_rect.width(), new_parent_rect.height() }); + recent_entry_detail_view.set_parent_rect({ 0, 0, new_parent_rect.width(), new_parent_rect.height() }); } void AISAppView::on_packet(const ais::Packet& packet) { @@ -303,4 +347,17 @@ void AISAppView::on_packet(const ais::Packet& packet) { recent_entries_view.set_dirty(); } +void AISAppView::on_show_list() { + recent_entries_view.hidden(false); + recent_entry_detail_view.hidden(true); + recent_entries_view.focus(); +} + +void AISAppView::on_show_detail(const AISRecentEntry& entry) { + recent_entries_view.hidden(true); + recent_entry_detail_view.hidden(false); + recent_entry_detail_view.set_entry(entry); + recent_entry_detail_view.focus(); +} + } /* namespace ui */ diff --git a/firmware/application/ais_app.hpp b/firmware/application/ais_app.hpp index 31f890a42..e9d8df92b 100644 --- a/firmware/application/ais_app.hpp +++ b/firmware/application/ais_app.hpp @@ -53,6 +53,11 @@ struct AISRecentEntry { size_t received_count; int8_t navigational_status; + AISRecentEntry( + ) : AISRecentEntry { 0 } + { + } + AISRecentEntry( const ais::MMSI& mmsi ) : mmsi { mmsi }, @@ -113,11 +118,14 @@ namespace ui { class AISRecentEntriesView : public View { public: + std::function on_select; + AISRecentEntriesView(AISRecentEntries& recent); void paint(Painter& painter) override; bool on_encoder(const EncoderEvent event) override; + bool on_key(const ui::KeyEvent event) override; private: AISRecentEntries& recent; @@ -129,6 +137,25 @@ private: void advance(const int32_t amount); }; +class AISRecentEntryDetailView : public View { +public: + std::function on_close; + + AISRecentEntryDetailView(); + + void set_entry(const AISRecentEntry& new_entry); + + void focus() override; + +private: + AISRecentEntry entry; + + Button button_done { + { 72, 192, 96, 24 }, + "Done" + }; +}; + class AISAppView : public View { public: AISAppView(); @@ -145,8 +172,11 @@ private: AISLogger logger; AISRecentEntriesView recent_entries_view { recent }; + AISRecentEntryDetailView recent_entry_detail_view; void on_packet(const ais::Packet& packet); + void on_show_list(); + void on_show_detail(const AISRecentEntry& entry); }; } /* namespace ui */