diff --git a/firmware/application/app_ais.cpp b/firmware/application/app_ais.cpp index fc013d8d3..ebdbc486d 100644 --- a/firmware/application/app_ais.cpp +++ b/firmware/application/app_ais.cpp @@ -415,6 +415,11 @@ void AISView::on_blur() { set_dirty(); } +bool AISView::on_encoder(const EncoderEvent event) { + advance(event); + return true; +} + void AISView::paint(Painter& painter) { const auto r = screen_rect(); const auto& s = style(); @@ -430,7 +435,12 @@ void AISView::paint(Painter& painter) { line.resize(r.width() / 8, ' '); - painter.draw_string(p, s, line); + if( has_focus && (selected_key == entry.mmsi) ) { + painter.draw_string(p, s.invert(), line); + } else { + painter.draw_string(p, s, line); + } + p.y += s.font.line_height(); if( p.y >= r.bottom() ) { @@ -439,4 +449,35 @@ void AISView::paint(Painter& painter) { } } +AISView::RecentEntries::iterator AISView::selected_entry() { + const auto key = selected_key; + return std::find_if(std::begin(recent), std::end(recent), [key](const RecentEntry& e) { return e.mmsi == key; }); +} + +void AISView::advance(const int32_t amount) { + auto selected = selected_entry(); + if( selected == std::end(recent) ) { + if( recent.empty() ) { + selected_key = invalid_key; + } else { + selected_key = recent.front().mmsi; + } + } else { + if( amount < 0 ) { + if( selected != std::begin(recent) ) { + std::advance(selected, -1); + } + } + if( amount > 0 ) { + std::advance(selected, 1); + if( selected == std::end(recent) ) { + return; + } + } + selected_key = selected->mmsi; + } + + set_dirty(); +} + } /* namespace ui */ diff --git a/firmware/application/app_ais.hpp b/firmware/application/app_ais.hpp index 254a8008f..0bc828771 100644 --- a/firmware/application/app_ais.hpp +++ b/firmware/application/app_ais.hpp @@ -37,6 +37,8 @@ using namespace lpc43xx; #include #include +#include + namespace baseband { namespace ais { @@ -130,9 +132,15 @@ public: void on_focus() override; void on_blur() override; + bool on_encoder(const EncoderEvent event) override; + private: AISModel model; + using EntryKey = baseband::ais::MMSI; + EntryKey selected_key; + const EntryKey invalid_key = 0xffffffff; + bool has_focus = false; struct Position { @@ -160,9 +168,14 @@ private: } }; - std::list recent; + using RecentEntries = std::list; + RecentEntries recent; + void on_packet(const baseband::ais::Packet& packet); + RecentEntries::iterator selected_entry(); + + void advance(const int32_t amount); }; } /* namespace ui */