diff --git a/firmware/application/ais_app.cpp b/firmware/application/ais_app.cpp index bf4e2111..a96b1fdf 100644 --- a/firmware/application/ais_app.cpp +++ b/firmware/application/ais_app.cpp @@ -21,6 +21,8 @@ #include "ais_app.hpp" +#include "event_m0.hpp" + #include "string_format.hpp" #include "portapack.hpp" @@ -116,8 +118,7 @@ namespace ui { void AISView::on_show() { View::on_show(); - auto& message_map = context().message_map(); - message_map.register_handler(Message::ID::AISPacket, + EventDispatcher::message_map().register_handler(Message::ID::AISPacket, [this](Message* const p) { const auto message = static_cast(p); const ais::Packet packet { message->packet }; @@ -129,8 +130,7 @@ void AISView::on_show() { } void AISView::on_hide() { - auto& message_map = context().message_map(); - message_map.unregister_handler(Message::ID::AISPacket); + EventDispatcher::message_map().unregister_handler(Message::ID::AISPacket); View::on_hide(); } diff --git a/firmware/application/ert_app.cpp b/firmware/application/ert_app.cpp index 596831e3..c17c2ac8 100644 --- a/firmware/application/ert_app.cpp +++ b/firmware/application/ert_app.cpp @@ -21,6 +21,8 @@ #include "ert_app.hpp" +#include "event_m0.hpp" + #include "portapack.hpp" using namespace portapack; @@ -54,8 +56,7 @@ namespace ui { void ERTView::on_show() { Console::on_show(); - auto& message_map = context().message_map(); - message_map.register_handler(Message::ID::ERTPacket, + EventDispatcher::message_map().register_handler(Message::ID::ERTPacket, [this](Message* const p) { const auto message = static_cast(p); const ert::Packet packet { message->type, message->packet }; @@ -67,8 +68,7 @@ void ERTView::on_show() { } void ERTView::on_hide() { - auto& message_map = context().message_map(); - message_map.unregister_handler(Message::ID::ERTPacket); + EventDispatcher::message_map().unregister_handler(Message::ID::ERTPacket); Console::on_hide(); } diff --git a/firmware/application/event_m0.cpp b/firmware/application/event_m0.cpp index 609589c1..6e889771 100644 --- a/firmware/application/event_m0.cpp +++ b/firmware/application/event_m0.cpp @@ -54,6 +54,7 @@ CH_IRQ_HANDLER(M4Core_IRQHandler) { } +MessageHandlerMap EventDispatcher::message_map_; Thread* EventDispatcher::thread_event_loop = nullptr; EventDispatcher::EventDispatcher( @@ -118,7 +119,7 @@ void EventDispatcher::dispatch(const eventmask_t events) { void EventDispatcher::handle_application_queue() { std::array message_buffer; while(Message* const message = shared_memory.application_queue.pop(message_buffer)) { - context.message_map().send(message); + message_map().send(message); } } @@ -172,7 +173,7 @@ void EventDispatcher::on_touch_event(ui::TouchEvent event) { void EventDispatcher::handle_lcd_frame_sync() { DisplayFrameSyncMessage message; - context.message_map().send(&message); + message_map().send(&message); painter.paint_widget_tree(top_widget); } diff --git a/firmware/application/event_m0.hpp b/firmware/application/event_m0.hpp index 342ed098..1409ceb7 100644 --- a/firmware/application/event_m0.hpp +++ b/firmware/application/event_m0.hpp @@ -27,6 +27,8 @@ #include "ui_widget.hpp" #include "ui_painter.hpp" +#include "message.hpp" + #include "touch.hpp" #include "ch.h" @@ -63,7 +65,12 @@ public: } } + static MessageHandlerMap& message_map() { + return message_map_; + } + private: + static MessageHandlerMap message_map_; static Thread* thread_event_loop; touch::Manager touch_manager; diff --git a/firmware/application/main.cpp b/firmware/application/main.cpp index 788a4452..d9900426 100755 --- a/firmware/application/main.cpp +++ b/firmware/application/main.cpp @@ -76,8 +76,7 @@ int main(void) { ui::Painter painter; EventDispatcher event_dispatcher { &system_view, painter, context }; - auto& message_handlers = context.message_map(); - message_handlers.register_handler(Message::ID::Shutdown, + EventDispatcher::message_map().register_handler(Message::ID::Shutdown, [&event_dispatcher](const Message* const) { event_dispatcher.request_stop(); } diff --git a/firmware/application/tpms_app.cpp b/firmware/application/tpms_app.cpp index 85a849c8..39af6c07 100644 --- a/firmware/application/tpms_app.cpp +++ b/firmware/application/tpms_app.cpp @@ -21,6 +21,8 @@ #include "tpms_app.hpp" +#include "event_m0.hpp" + #include "portapack.hpp" using namespace portapack; @@ -58,8 +60,7 @@ namespace ui { void TPMSView::on_show() { Console::on_show(); - auto& message_map = context().message_map(); - message_map.register_handler(Message::ID::TPMSPacket, + EventDispatcher::message_map().register_handler(Message::ID::TPMSPacket, [this](Message* const p) { const auto message = static_cast(p); this->log(this->model.on_packet(*message)); @@ -68,8 +69,7 @@ void TPMSView::on_show() { } void TPMSView::on_hide() { - auto& message_map = context().message_map(); - message_map.unregister_handler(Message::ID::TPMSPacket); + EventDispatcher::message_map().unregister_handler(Message::ID::TPMSPacket); Console::on_hide(); } diff --git a/firmware/application/ui_audio.cpp b/firmware/application/ui_audio.cpp index 0dd698e2..b85e0dd9 100644 --- a/firmware/application/ui_audio.cpp +++ b/firmware/application/ui_audio.cpp @@ -21,12 +21,14 @@ #include "ui_audio.hpp" +#include "event_m0.hpp" + #include namespace ui { void Audio::on_show() { - context().message_map().register_handler(Message::ID::AudioStatistics, + EventDispatcher::message_map().register_handler(Message::ID::AudioStatistics, [this](const Message* const p) { this->on_statistics_update(static_cast(p)->statistics); } @@ -34,7 +36,7 @@ void Audio::on_show() { } void Audio::on_hide() { - context().message_map().unregister_handler(Message::ID::AudioStatistics); + EventDispatcher::message_map().unregister_handler(Message::ID::AudioStatistics); } void Audio::paint(Painter& painter) { diff --git a/firmware/application/ui_baseband_stats_view.cpp b/firmware/application/ui_baseband_stats_view.cpp index 76cccb5a..0d576e81 100644 --- a/firmware/application/ui_baseband_stats_view.cpp +++ b/firmware/application/ui_baseband_stats_view.cpp @@ -21,6 +21,8 @@ #include "ui_baseband_stats_view.hpp" +#include "event_m0.hpp" + #include #include @@ -40,7 +42,7 @@ BasebandStatsView::BasebandStatsView() { } void BasebandStatsView::on_show() { - context().message_map().register_handler(Message::ID::BasebandStatistics, + EventDispatcher::message_map().register_handler(Message::ID::BasebandStatistics, [this](const Message* const p) { this->on_statistics_update(static_cast(p)->statistics); } @@ -48,7 +50,7 @@ void BasebandStatsView::on_show() { } void BasebandStatsView::on_hide() { - context().message_map().unregister_handler(Message::ID::BasebandStatistics); + EventDispatcher::message_map().unregister_handler(Message::ID::BasebandStatistics); } diff --git a/firmware/application/ui_channel.cpp b/firmware/application/ui_channel.cpp index a5c8a568..cdcb8d73 100644 --- a/firmware/application/ui_channel.cpp +++ b/firmware/application/ui_channel.cpp @@ -21,12 +21,14 @@ #include "ui_channel.hpp" +#include "event_m0.hpp" + #include namespace ui { void Channel::on_show() { - context().message_map().register_handler(Message::ID::ChannelStatistics, + EventDispatcher::message_map().register_handler(Message::ID::ChannelStatistics, [this](const Message* const p) { this->on_statistics_update(static_cast(p)->statistics); } @@ -34,7 +36,7 @@ void Channel::on_show() { } void Channel::on_hide() { - context().message_map().unregister_handler(Message::ID::ChannelStatistics); + EventDispatcher::message_map().unregister_handler(Message::ID::ChannelStatistics); } void Channel::paint(Painter& painter) { diff --git a/firmware/application/ui_rssi.cpp b/firmware/application/ui_rssi.cpp index 7cbba2a1..629b66d4 100644 --- a/firmware/application/ui_rssi.cpp +++ b/firmware/application/ui_rssi.cpp @@ -21,12 +21,14 @@ #include "ui_rssi.hpp" +#include "event_m0.hpp" + #include namespace ui { void RSSI::on_show() { - context().message_map().register_handler(Message::ID::RSSIStatistics, + EventDispatcher::message_map().register_handler(Message::ID::RSSIStatistics, [this](const Message* const p) { this->on_statistics_update(static_cast(p)->statistics); } @@ -34,7 +36,7 @@ void RSSI::on_show() { } void RSSI::on_hide() { - context().message_map().unregister_handler(Message::ID::RSSIStatistics); + EventDispatcher::message_map().unregister_handler(Message::ID::RSSIStatistics); } void RSSI::paint(Painter& painter) { diff --git a/firmware/application/ui_spectrum.cpp b/firmware/application/ui_spectrum.cpp index 74838210..addd2079 100644 --- a/firmware/application/ui_spectrum.cpp +++ b/firmware/application/ui_spectrum.cpp @@ -21,6 +21,8 @@ #include "ui_spectrum.hpp" +#include "event_m0.hpp" + #include "spectrum_color_lut.hpp" #include "portapack.hpp" @@ -235,13 +237,13 @@ WaterfallWidget::WaterfallWidget() { } void WaterfallWidget::on_show() { - context().message_map().register_handler(Message::ID::ChannelSpectrumConfig, + EventDispatcher::message_map().register_handler(Message::ID::ChannelSpectrumConfig, [this](const Message* const p) { const auto message = *reinterpret_cast(p); this->fifo = message.fifo; } ); - context().message_map().register_handler(Message::ID::DisplayFrameSync, + EventDispatcher::message_map().register_handler(Message::ID::DisplayFrameSync, [this](const Message* const) { if( this->fifo ) { ChannelSpectrum channel_spectrum; @@ -266,8 +268,8 @@ void WaterfallWidget::on_hide() { } ); - context().message_map().unregister_handler(Message::ID::DisplayFrameSync); - context().message_map().unregister_handler(Message::ID::ChannelSpectrumConfig); + EventDispatcher::message_map().unregister_handler(Message::ID::DisplayFrameSync); + EventDispatcher::message_map().unregister_handler(Message::ID::ChannelSpectrumConfig); } void WaterfallWidget::set_parent_rect(const Rect new_parent_rect) { diff --git a/firmware/common/ui_widget.hpp b/firmware/common/ui_widget.hpp index a974631a..f2e18364 100644 --- a/firmware/common/ui_widget.hpp +++ b/firmware/common/ui_widget.hpp @@ -29,8 +29,6 @@ #include "utility.hpp" -#include "message.hpp" - #include #include #include @@ -47,13 +45,8 @@ public: return focus_manager_; } - MessageHandlerMap& message_map() { - return message_map_; - } - private: FocusManager focus_manager_; - MessageHandlerMap message_map_; }; class Widget {