mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-24 23:09:26 -05:00
Removing baseband MessageHandlerMap.
It's a bit heavy (362 bytes smaller with switch/case implementation), hard to access to add/remove handlers, doesn't bubble events like I'd like. (I'm going to bubble events to the baseband processor shortly.)
This commit is contained in:
parent
fea5dd536f
commit
07cd99d85d
@ -121,24 +121,7 @@ static void shutdown() {
|
||||
|
||||
class EventDispatcher {
|
||||
public:
|
||||
MessageHandlerMap& message_handlers() {
|
||||
return message_map;
|
||||
}
|
||||
|
||||
void run() {
|
||||
message_map.register_handler(Message::ID::BasebandConfiguration,
|
||||
[this](const Message* const p) {
|
||||
auto message = reinterpret_cast<const BasebandConfigurationMessage*>(p);
|
||||
this->baseband_thread.set_configuration(message->configuration);
|
||||
}
|
||||
);
|
||||
|
||||
message_map.register_handler(Message::ID::Shutdown,
|
||||
[this](const Message* const) {
|
||||
this->request_stop();
|
||||
}
|
||||
);
|
||||
|
||||
events_initialize(chThdSelf());
|
||||
m0apptxevent_interrupt_enable();
|
||||
|
||||
@ -159,7 +142,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
MessageHandlerMap message_map;
|
||||
BasebandThread baseband_thread;
|
||||
RSSIThread rssi_thread;
|
||||
|
||||
@ -182,10 +164,38 @@ private:
|
||||
void handle_baseband_queue() {
|
||||
std::array<uint8_t, Message::MAX_SIZE> message_buffer;
|
||||
while(Message* const message = shared_memory.baseband_queue.pop(message_buffer)) {
|
||||
message_map.send(message);
|
||||
on_message(message);
|
||||
}
|
||||
}
|
||||
|
||||
void on_message(const Message* const message) {
|
||||
switch(message->id) {
|
||||
case Message::ID::BasebandConfiguration:
|
||||
on_message_baseband_configuration(*reinterpret_cast<const BasebandConfigurationMessage*>(message));
|
||||
break;
|
||||
|
||||
case Message::ID::Shutdown:
|
||||
on_message_shutdown(*reinterpret_cast<const ShutdownMessage*>(message));
|
||||
break;
|
||||
|
||||
default:
|
||||
on_message_default(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void on_message_baseband_configuration(const BasebandConfigurationMessage& message) {
|
||||
baseband_thread.set_configuration(message.configuration);
|
||||
}
|
||||
|
||||
void on_message_shutdown(const ShutdownMessage&) {
|
||||
request_stop();
|
||||
}
|
||||
|
||||
void on_message_default(const Message* const) {
|
||||
// TODO: Pass to active baseband processor.
|
||||
}
|
||||
|
||||
void handle_spectrum() {
|
||||
// TODO: Send this via another message?!
|
||||
baseband_thread.on_update_spectrum();
|
||||
|
Loading…
Reference in New Issue
Block a user