mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-17 08:12:32 +00:00
51 lines
1.8 KiB
C++
51 lines
1.8 KiB
C++
#include "TextMessageModule.h"
|
|
#include "MeshService.h"
|
|
#include "MessageStore.h"
|
|
#include "NodeDB.h"
|
|
#include "PowerFSM.h"
|
|
#include "buzz.h"
|
|
#include "configuration.h"
|
|
#include "graphics/Screen.h"
|
|
#include "graphics/SharedUIDisplay.h"
|
|
#include "graphics/draw/MessageRenderer.h"
|
|
#include "main.h"
|
|
TextMessageModule *textMessageModule;
|
|
|
|
ProcessMessage TextMessageModule::handleReceived(const meshtastic_MeshPacket &mp)
|
|
{
|
|
#if defined(DEBUG_PORT) && !defined(DEBUG_MUTE)
|
|
auto &p = mp.decoded;
|
|
LOG_INFO("Received text msg from=0x%0x, id=0x%x, msg=%.*s", mp.from, mp.id, p.payload.size, p.payload.bytes);
|
|
#endif
|
|
|
|
// We only store/display messages destined for us.
|
|
devicestate.rx_text_message = mp;
|
|
devicestate.has_rx_text_message = true;
|
|
#if HAS_SCREEN
|
|
// Guard against running in MeshtasticUI
|
|
if (config.display.displaymode != meshtastic_Config_DisplayConfig_DisplayMode_COLOR) {
|
|
// Store in the central message history
|
|
const StoredMessage &sm = messageStore.addFromPacket(mp);
|
|
|
|
// Pass message to renderer (banner + thread switching + scroll reset)
|
|
// Use the global Screen singleton to retrieve the current OLED display
|
|
auto *display = screen ? screen->getDisplayDevice() : nullptr;
|
|
graphics::MessageRenderer::handleNewMessage(display, sm, mp);
|
|
}
|
|
#endif
|
|
// Only trigger screen wake if configuration allows it
|
|
if (shouldWakeOnReceivedMessage()) {
|
|
powerFSM.trigger(EVENT_RECEIVED_MSG);
|
|
}
|
|
|
|
// Notify any observers (e.g. external modules that care about packets)
|
|
notifyObservers(&mp);
|
|
|
|
return ProcessMessage::CONTINUE; // Let others look at this message also if they want
|
|
}
|
|
|
|
bool TextMessageModule::wantPacket(const meshtastic_MeshPacket *p)
|
|
{
|
|
return MeshService::isTextPayload(p);
|
|
}
|