mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-01-07 23:07:43 +00:00
Hide implementation of MessageHandlerMap.
This commit is contained in:
parent
2aa8ae0d1f
commit
a7226820d0
@ -184,10 +184,7 @@ private:
|
|||||||
while( !shared_memory.application_queue.is_empty() ) {
|
while( !shared_memory.application_queue.is_empty() ) {
|
||||||
auto message = shared_memory.application_queue.pop();
|
auto message = shared_memory.application_queue.pop();
|
||||||
|
|
||||||
auto& fn = context.message_map[message->id];
|
context.message_map.send(message);
|
||||||
if( fn ) {
|
|
||||||
fn(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
message->state = Message::State::Free;
|
message->state = Message::State::Free;
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,15 @@
|
|||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
void Audio::on_show() {
|
void Audio::on_show() {
|
||||||
context().message_map[Message::ID::AudioStatistics] = [this](const Message* const p) {
|
context().message_map.register_handler(Message::ID::AudioStatistics,
|
||||||
this->on_statistics_update(static_cast<const AudioStatisticsMessage*>(p)->statistics);
|
[this](const Message* const p) {
|
||||||
};
|
this->on_statistics_update(static_cast<const AudioStatisticsMessage*>(p)->statistics);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::on_hide() {
|
void Audio::on_hide() {
|
||||||
context().message_map[Message::ID::AudioStatistics] = nullptr;
|
context().message_map.unregister_handler(Message::ID::AudioStatistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::paint(Painter& painter) {
|
void Audio::paint(Painter& painter) {
|
||||||
|
@ -26,13 +26,15 @@
|
|||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
void Channel::on_show() {
|
void Channel::on_show() {
|
||||||
context().message_map[Message::ID::ChannelStatistics] = [this](const Message* const p) {
|
context().message_map.register_handler(Message::ID::ChannelStatistics,
|
||||||
this->on_statistics_update(static_cast<const ChannelStatisticsMessage*>(p)->statistics);
|
[this](const Message* const p) {
|
||||||
};
|
this->on_statistics_update(static_cast<const ChannelStatisticsMessage*>(p)->statistics);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Channel::on_hide() {
|
void Channel::on_hide() {
|
||||||
context().message_map[Message::ID::ChannelStatistics] = nullptr;
|
context().message_map.unregister_handler(Message::ID::ChannelStatistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Channel::paint(Painter& painter) {
|
void Channel::paint(Painter& painter) {
|
||||||
|
@ -40,13 +40,15 @@ BasebandStatsView::BasebandStatsView() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BasebandStatsView::on_show() {
|
void BasebandStatsView::on_show() {
|
||||||
context().message_map[Message::ID::BasebandStatistics] = [this](const Message* const p) {
|
context().message_map.register_handler(Message::ID::BasebandStatistics,
|
||||||
this->on_statistics_update(static_cast<const BasebandStatisticsMessage*>(p)->statistics);
|
[this](const Message* const p) {
|
||||||
};
|
this->on_statistics_update(static_cast<const BasebandStatisticsMessage*>(p)->statistics);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasebandStatsView::on_hide() {
|
void BasebandStatsView::on_hide() {
|
||||||
context().message_map[Message::ID::BasebandStatistics] = nullptr;
|
context().message_map.unregister_handler(Message::ID::BasebandStatistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -481,15 +481,17 @@ ReceiverView::ReceiverView(
|
|||||||
|
|
||||||
receiver_model.enable();
|
receiver_model.enable();
|
||||||
|
|
||||||
context().message_map[Message::ID::FSKPacket] = [](const Message* const p) {
|
context().message_map.register_handler(Message::ID::FSKPacket,
|
||||||
const auto message = static_cast<const FSKPacketMessage*>(p);
|
[](const Message* const p) {
|
||||||
(void)message;
|
const auto message = static_cast<const FSKPacketMessage*>(p);
|
||||||
};
|
(void)message;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReceiverView::~ReceiverView() {
|
ReceiverView::~ReceiverView() {
|
||||||
context().message_map[Message::ID::FSKPacket] = nullptr;
|
context().message_map.unregister_handler(Message::ID::FSKPacket);
|
||||||
|
|
||||||
// TODO: Manipulating audio codec here, and in ui_receiver.cpp. Good to do
|
// TODO: Manipulating audio codec here, and in ui_receiver.cpp. Good to do
|
||||||
// both?
|
// both?
|
||||||
audio_codec.headphone_mute();
|
audio_codec.headphone_mute();
|
||||||
|
@ -26,13 +26,15 @@
|
|||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
void RSSI::on_show() {
|
void RSSI::on_show() {
|
||||||
context().message_map[Message::ID::RSSIStatistics] = [this](const Message* const p) {
|
context().message_map.register_handler(Message::ID::RSSIStatistics,
|
||||||
this->on_statistics_update(static_cast<const RSSIStatisticsMessage*>(p)->statistics);
|
[this](const Message* const p) {
|
||||||
};
|
this->on_statistics_update(static_cast<const RSSIStatisticsMessage*>(p)->statistics);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RSSI::on_hide() {
|
void RSSI::on_hide() {
|
||||||
context().message_map[Message::ID::RSSIStatistics] = nullptr;
|
context().message_map.unregister_handler(Message::ID::RSSIStatistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RSSI::paint(Painter& painter) {
|
void RSSI::paint(Painter& painter) {
|
||||||
|
@ -233,13 +233,15 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void on_show() override {
|
void on_show() override {
|
||||||
context().message_map[Message::ID::ChannelSpectrum] = [this](const Message* const p) {
|
context().message_map.register_handler(Message::ID::ChannelSpectrum,
|
||||||
this->on_channel_spectrum(reinterpret_cast<const ChannelSpectrumMessage*>(p)->spectrum);
|
[this](const Message* const p) {
|
||||||
};
|
this->on_channel_spectrum(reinterpret_cast<const ChannelSpectrumMessage*>(p)->spectrum);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_hide() override {
|
void on_hide() override {
|
||||||
context().message_map[Message::ID::ChannelSpectrum] = nullptr;
|
context().message_map.unregister_handler(Message::ID::ChannelSpectrum);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_parent_rect(const Rect new_parent_rect) override {
|
void set_parent_rect(const Rect new_parent_rect) override {
|
||||||
|
@ -481,14 +481,16 @@ public:
|
|||||||
MessageHandlerMap& message_handlers
|
MessageHandlerMap& message_handlers
|
||||||
) : message_handlers(message_handlers)
|
) : message_handlers(message_handlers)
|
||||||
{
|
{
|
||||||
message_handlers[Message::ID::FSKConfiguration] = [this](const Message* const p) {
|
message_handlers.register_handler(Message::ID::FSKConfiguration,
|
||||||
auto m = reinterpret_cast<const FSKConfigurationMessage*>(p);
|
[this](const Message* const p) {
|
||||||
this->configure(m->configuration);
|
auto m = reinterpret_cast<const FSKConfigurationMessage*>(p);
|
||||||
};
|
this->configure(m->configuration);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
~FSKProcessor() {
|
~FSKProcessor() {
|
||||||
message_handlers[Message::ID::FSKConfiguration] = nullptr;
|
message_handlers.unregister_handler(Message::ID::FSKConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
void configure(const FSKConfiguration new_configuration) {
|
void configure(const FSKConfiguration new_configuration) {
|
||||||
@ -736,10 +738,7 @@ private:
|
|||||||
while( !shared_memory.baseband_queue.is_empty() ) {
|
while( !shared_memory.baseband_queue.is_empty() ) {
|
||||||
auto message = shared_memory.baseband_queue.pop();
|
auto message = shared_memory.baseband_queue.pop();
|
||||||
|
|
||||||
auto& fn = message_map[message->id];
|
message_map.send(message);
|
||||||
if( fn ) {
|
|
||||||
fn(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
message->state = Message::State::Free;
|
message->state = Message::State::Free;
|
||||||
}
|
}
|
||||||
@ -804,49 +803,51 @@ int main(void) {
|
|||||||
EventDispatcher event_dispatcher;
|
EventDispatcher event_dispatcher;
|
||||||
auto& message_handlers = event_dispatcher.message_handlers();
|
auto& message_handlers = event_dispatcher.message_handlers();
|
||||||
|
|
||||||
message_handlers[Message::ID::BasebandConfiguration] = [&message_handlers](const Message* const p) {
|
message_handlers.register_handler(Message::ID::BasebandConfiguration,
|
||||||
auto message = reinterpret_cast<const BasebandConfigurationMessage*>(p);
|
[&message_handlers](const Message* const p) {
|
||||||
if( message->configuration.mode != baseband_configuration.mode ) {
|
auto message = reinterpret_cast<const BasebandConfigurationMessage*>(p);
|
||||||
|
if( message->configuration.mode != baseband_configuration.mode ) {
|
||||||
|
|
||||||
// TODO: Timing problem around disabling DMA and nulling and deleting old processor
|
// TODO: Timing problem around disabling DMA and nulling and deleting old processor
|
||||||
auto old_p = baseband_processor;
|
auto old_p = baseband_processor;
|
||||||
baseband_processor = nullptr;
|
baseband_processor = nullptr;
|
||||||
delete old_p;
|
delete old_p;
|
||||||
|
|
||||||
switch(message->configuration.mode) {
|
switch(message->configuration.mode) {
|
||||||
case 0:
|
case 0:
|
||||||
baseband_processor = new NarrowbandAMAudio();
|
baseband_processor = new NarrowbandAMAudio();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
baseband_processor = new NarrowbandFMAudio();
|
baseband_processor = new NarrowbandFMAudio();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
baseband_processor = new WidebandFMAudio();
|
baseband_processor = new WidebandFMAudio();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
baseband_processor = new FSKProcessor(message_handlers);
|
baseband_processor = new FSKProcessor(message_handlers);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if( baseband_processor ) {
|
|
||||||
if( direction == baseband::Direction::Receive ) {
|
|
||||||
rf::rssi::start();
|
|
||||||
}
|
}
|
||||||
baseband::dma::enable(direction);
|
|
||||||
} else {
|
|
||||||
baseband::dma::disable();
|
|
||||||
rf::rssi::stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
baseband_configuration = message->configuration;
|
if( baseband_processor ) {
|
||||||
};
|
if( direction == baseband::Direction::Receive ) {
|
||||||
|
rf::rssi::start();
|
||||||
|
}
|
||||||
|
baseband::dma::enable(direction);
|
||||||
|
} else {
|
||||||
|
baseband::dma::disable();
|
||||||
|
rf::rssi::stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
baseband_configuration = message->configuration;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
/* TODO: Ensure DMAs are configured to point at first LLI in chain. */
|
/* TODO: Ensure DMAs are configured to point at first LLI in chain. */
|
||||||
|
|
||||||
|
@ -246,12 +246,19 @@ class MessageHandlerMap {
|
|||||||
public:
|
public:
|
||||||
using MessageHandler = std::function<void(const Message* const p)>;
|
using MessageHandler = std::function<void(const Message* const p)>;
|
||||||
|
|
||||||
MessageHandler& operator[](Message::ID n) {
|
void register_handler(const Message::ID id, MessageHandler&& handler) {
|
||||||
return map_[toUType(n)];
|
map_[toUType(id)] = std::move(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
const MessageHandler& operator[](Message::ID n) const {
|
void unregister_handler(const Message::ID id) {
|
||||||
return map_[toUType(n)];
|
map_[toUType(id)] = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void send(const Message* const message) {
|
||||||
|
auto& fn = map_[toUType(message->id)];
|
||||||
|
if( fn ) {
|
||||||
|
fn(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user