mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-04-22 11:01:28 +00:00
Add AIS detail view.
This commit is contained in:
parent
b1707298b7
commit
aa249cbad4
@ -197,6 +197,19 @@ bool AISRecentEntriesView::on_encoder(const EncoderEvent event) {
|
|||||||
return true;
|
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(
|
static void ais_list_item_draw(
|
||||||
const AISRecentEntry& entry,
|
const AISRecentEntry& entry,
|
||||||
const Rect& target_rect,
|
const Rect& target_rect,
|
||||||
@ -265,11 +278,34 @@ void AISRecentEntriesView::advance(const int32_t amount) {
|
|||||||
set_dirty();
|
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() {
|
AISAppView::AISAppView() {
|
||||||
add_children({ {
|
add_children({ {
|
||||||
&recent_entries_view,
|
&recent_entries_view,
|
||||||
|
&recent_entry_detail_view,
|
||||||
} });
|
} });
|
||||||
|
|
||||||
|
recent_entry_detail_view.hidden(true);
|
||||||
|
|
||||||
EventDispatcher::message_map().register_handler(Message::ID::AISPacket,
|
EventDispatcher::message_map().register_handler(Message::ID::AISPacket,
|
||||||
[this](Message* const p) {
|
[this](Message* const p) {
|
||||||
const auto message = static_cast<const AISPacketMessage*>(p);
|
const auto message = static_cast<const AISPacketMessage*>(p);
|
||||||
@ -286,6 +322,13 @@ AISAppView::AISAppView() {
|
|||||||
.decimation_factor = 1,
|
.decimation_factor = 1,
|
||||||
});
|
});
|
||||||
receiver_model.set_baseband_bandwidth(1750000);
|
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() {
|
AISAppView::~AISAppView() {
|
||||||
@ -295,6 +338,7 @@ AISAppView::~AISAppView() {
|
|||||||
void AISAppView::set_parent_rect(const Rect new_parent_rect) {
|
void AISAppView::set_parent_rect(const Rect new_parent_rect) {
|
||||||
View::set_parent_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_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) {
|
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();
|
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 */
|
} /* namespace ui */
|
||||||
|
@ -53,6 +53,11 @@ struct AISRecentEntry {
|
|||||||
size_t received_count;
|
size_t received_count;
|
||||||
int8_t navigational_status;
|
int8_t navigational_status;
|
||||||
|
|
||||||
|
AISRecentEntry(
|
||||||
|
) : AISRecentEntry { 0 }
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
AISRecentEntry(
|
AISRecentEntry(
|
||||||
const ais::MMSI& mmsi
|
const ais::MMSI& mmsi
|
||||||
) : mmsi { mmsi },
|
) : mmsi { mmsi },
|
||||||
@ -113,11 +118,14 @@ namespace ui {
|
|||||||
|
|
||||||
class AISRecentEntriesView : public View {
|
class AISRecentEntriesView : public View {
|
||||||
public:
|
public:
|
||||||
|
std::function<void(const AISRecentEntry& entry)> on_select;
|
||||||
|
|
||||||
AISRecentEntriesView(AISRecentEntries& recent);
|
AISRecentEntriesView(AISRecentEntries& recent);
|
||||||
|
|
||||||
void paint(Painter& painter) override;
|
void paint(Painter& painter) override;
|
||||||
|
|
||||||
bool on_encoder(const EncoderEvent event) override;
|
bool on_encoder(const EncoderEvent event) override;
|
||||||
|
bool on_key(const ui::KeyEvent event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AISRecentEntries& recent;
|
AISRecentEntries& recent;
|
||||||
@ -129,6 +137,25 @@ private:
|
|||||||
void advance(const int32_t amount);
|
void advance(const int32_t amount);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class AISRecentEntryDetailView : public View {
|
||||||
|
public:
|
||||||
|
std::function<void(void)> 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 {
|
class AISAppView : public View {
|
||||||
public:
|
public:
|
||||||
AISAppView();
|
AISAppView();
|
||||||
@ -145,8 +172,11 @@ private:
|
|||||||
AISLogger logger;
|
AISLogger logger;
|
||||||
|
|
||||||
AISRecentEntriesView recent_entries_view { recent };
|
AISRecentEntriesView recent_entries_view { recent };
|
||||||
|
AISRecentEntryDetailView recent_entry_detail_view;
|
||||||
|
|
||||||
void on_packet(const ais::Packet& packet);
|
void on_packet(const ais::Packet& packet);
|
||||||
|
void on_show_list();
|
||||||
|
void on_show_detail(const AISRecentEntry& entry);
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace ui */
|
} /* namespace ui */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user