mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-29 06:00:33 +00:00
* First try at multimessage storage and display * Nrf built issue fix * Message view mode * Add channel name instead of channel slot * trunk fix * Fix for DM threading * fix for message time * rename of view mode to Conversations * Reply in thread feature * rename Select View Mode to Select Conversation * dismiss all live fix * Messages from phone show on screen * Decoupled message packets from screen.cpp and cleaned up * Cannedmessage cleanup and emotes fixed * Ack on messages sent * Ack message cleanup * Dismiss feature fixed * removed legacy temporary messages * Emote picker fix * Memory size debug * Build error fix * Sanity checks are okay sometimes * Lengthen channel name and finalize cleanup removal of Broadcast * Change DM to @ in order to unify on a single method * Continue unifying display, also show message status on the "isMine" lines * Add context for incoming messages * Better to say "in" vs "on" * crash fix for confirmation nodes * Fix outbound labels based to avoid creating delays * Eink autoscroll dissabled * gating for message storage when not using a screen * revert * Build fail fix * Don't error out with unset MAC address in unit tests * Provide some extra spacing for low hanging characters in messages * Reorder menu options and reword Respond * Reword menus to better reflect actions * Go to thread from favorite screen * Reorder Favorite Action Menu with simple word modifications * Consolidate wording on "Chats" * Mute channel fix * trunk fix * Clean up how muting works along with when we wake the screen * Fix builds for HELTEC_MESH_SOLAR * Signal bars for message ack * fix for notification renderer * Remove duplicate code, fix more Chats, and fix C6L MessageRenderer * Fix to many warnings related to BaseUI * preset aware signal strength display * More C6L fixes and clean up header lines * Use text aligns for message layout where necessary * Attempt to fix memory usage of invalidLifetime * Update channel mute for adjusted protobuf * Missed a comma in merge conflicts * cleanup to get more space * Trunk fixes * Optimize Hi Rez Chirpy to save space * more fixes * More cleanup * Remove used getConversationWith * Remove unused dismissNewestMessage * Fix another build error on occassion * Dimiss key combo function deprecated * More cleanup * Fn symbol code removed * Waypoint cleanup * Trunk fix * Fixup Waypoint screen with BaseUI code * Implement Haruki's ClockRenderer and broadcast decomposeTime across various files. * Revert "Implement Haruki's ClockRenderer and broadcast decomposeTime across various files." This reverts commit2f65721774. * Implement Haruki's ClockRenderer and broadcast decomposeTime across various files. Attempt 2! * remove memory usage debug * Revert only RangeTestModule.cpp change * Switch from dynamic std::string storage to fixed-size char[] * Removing old left over code * More optimization * Free Heap when not on Message screen * build error fixes * Restore ellipsis to end of long names * Remove legacy function renderMessageContent * improved destination filtering * force PKI * cleanup * Shorten longNames to not exceed message popups * log messages sent from apps * Trunk fix * Improve layout of messages screen * Fix potential crash for undefined variable * Revert changes to RedirectablePrint.cpp * Apply shortening to longNames in Select Destination * Fix short name displays * Fix sprintfOverlappingData issue * Fix nullPointerRedundantCheck warning on ESP32 * Add "Delete All Chats" to all chat views * Improve getSafeNodeName / sanitizeString code. * Improve getSafeNodeName further * Restore auto favorite; but only if not CLIENT_BASE * Don't favorite if WE are CLIENT_BASE role * Don't run message persistent in MUI * Fix broken endifs * Unkwnown nodes no longer show as ??? on message thread * More delete options and cleanup of code * fix for delete this chat * Message menu cleanup * trunk fix * Clean up some menu options and remove some Unit C6L ifdefines * Rework Delete flow * Desperate times call for desperate measures * Create a background on the connected icon to reduce overlap impact * Optimize code for background image * Fix for Muzi_Base * Trunk Fixes * Remove the up/down shortcut to launch canned messages (#8370) * Remove the up/down shortcut to launch canned messages * Enabled MQTT and WEBSERVER by default (#8679) Signed-off-by: kur1k0 <zhuzirun@m5stack.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz> --------- Signed-off-by: kur1k0 <zhuzirun@m5stack.com> Co-authored-by: Riker <zhuzirun@m5stack.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * Correct string length calculation for signal bars * Manual message scrolling * Fix * Restore CannedMessages on Home Frame * UpDown situational destination for textMessage * Correct up/down destinations on textMessage frame * Update Screen.h for handleTextMessage * Update Screen.cpp to repair a merge issue * Add nudge scroll on UpDownEncoder devices. * Set nodeName to maximum size * Revert "Set nodeName to maximum size" This reverts commite254f39925. * Reflow Node Lists and TLora Pager Views (#8942) * Add files via upload * Move files into the right place * Short or Long Names for everyone! * Add scrolling to Node list * Pagination fix for Latest to oldest per page * Page counters * Dynamic scaling of column counts based upon screen size, clean up box drawing * Reflow Node Lists and TLora Pager Views (#8942) * Add files via upload * Move files into the right place * Short or Long Names for everyone! * Add scrolling to Node list * Pagination fix for Latest to oldest per page * Page counters * Dynamic scaling of column counts based upon screen size, clean up box drawing * Update exempt labels for stale bot workflow Adds triaged and backlog to the list of exempt labels. * Update naming of Frame Visibility toggles * Fix to scrolling * Fix for content cutting off when from us * Fix for "delete this chat" now it does delete the current one * Rework isHighResolution to be an enum called ScreenResolution * Migrate Unit C6L macro guards into currentResolution UltraLow checks * Mistakes happen - restoring NodeList Renderer line --------- Signed-off-by: kur1k0 <zhuzirun@m5stack.com> Co-authored-by: Jason P <applewiz@mac.com> Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz> Co-authored-by: Riker <zhuzirun@m5stack.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: whywilson <m.tools@qq.com> Co-authored-by: Tom Fifield <tom@tomfifield.net>
271 lines
11 KiB
C++
271 lines
11 KiB
C++
#pragma once
|
|
#if HAS_SCREEN
|
|
#include "ProtobufModule.h"
|
|
#include "input/InputBroker.h"
|
|
|
|
// ============================
|
|
// Enums & Defines
|
|
// ============================
|
|
|
|
enum cannedMessageModuleRunState {
|
|
CANNED_MESSAGE_RUN_STATE_DISABLED,
|
|
CANNED_MESSAGE_RUN_STATE_INACTIVE,
|
|
CANNED_MESSAGE_RUN_STATE_ACTIVE,
|
|
CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE,
|
|
CANNED_MESSAGE_RUN_STATE_ACK_NACK_RECEIVED,
|
|
CANNED_MESSAGE_RUN_STATE_ACTION_SELECT,
|
|
CANNED_MESSAGE_RUN_STATE_ACTION_UP,
|
|
CANNED_MESSAGE_RUN_STATE_ACTION_DOWN,
|
|
CANNED_MESSAGE_RUN_STATE_DESTINATION_SELECTION,
|
|
CANNED_MESSAGE_RUN_STATE_FREETEXT,
|
|
CANNED_MESSAGE_RUN_STATE_MESSAGE_SELECTION,
|
|
CANNED_MESSAGE_RUN_STATE_EMOTE_PICKER
|
|
};
|
|
|
|
enum CannedMessageModuleIconType { shift, backspace, space, enter };
|
|
|
|
#define CANNED_MESSAGE_MODULE_MESSAGE_MAX_COUNT 50
|
|
#define CANNED_MESSAGE_MODULE_MESSAGES_SIZE 800
|
|
|
|
#ifndef CANNED_MESSAGE_MODULE_ENABLE
|
|
#define CANNED_MESSAGE_MODULE_ENABLE 0
|
|
#endif
|
|
|
|
// ============================
|
|
// Data Structures
|
|
// ============================
|
|
|
|
struct Letter {
|
|
String character;
|
|
float width;
|
|
int rectX;
|
|
int rectY;
|
|
int rectWidth;
|
|
int rectHeight;
|
|
};
|
|
|
|
struct NodeEntry {
|
|
meshtastic_NodeInfoLite *node;
|
|
uint32_t lastHeard;
|
|
};
|
|
|
|
// ============================
|
|
// Main Class
|
|
// ============================
|
|
|
|
class CannedMessageModule : public SinglePortModule, public Observable<const UIFrameEvent *>, private concurrency::OSThread
|
|
{
|
|
public:
|
|
CannedMessageModule();
|
|
|
|
void LaunchWithDestination(NodeNum, uint8_t newChannel = 0);
|
|
void LaunchRepeatDestination();
|
|
void LaunchFreetextWithDestination(NodeNum, uint8_t newChannel = 0);
|
|
|
|
// === Emote Picker navigation ===
|
|
int emotePickerIndex = 0; // Tracks currently selected emote in the picker
|
|
|
|
// === Message navigation ===
|
|
const char *getCurrentMessage();
|
|
const char *getPrevMessage();
|
|
const char *getNextMessage();
|
|
const char *getMessageByIndex(int index);
|
|
const char *getNodeName(NodeNum node);
|
|
|
|
// === State/UI ===
|
|
bool shouldDraw();
|
|
bool hasMessages();
|
|
void resetSearch();
|
|
void updateDestinationSelectionList();
|
|
void drawDestinationSelectionScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
|
|
bool isCharInputAllowed() const;
|
|
String drawWithCursor(String text, int cursor);
|
|
|
|
// === Emote Picker ===
|
|
int handleEmotePickerInput(const InputEvent *event);
|
|
void drawEmotePickerScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
|
|
|
|
// === Admin Handlers ===
|
|
void handleGetCannedMessageModuleMessages(const meshtastic_MeshPacket &req, meshtastic_AdminMessage *response);
|
|
void handleSetCannedMessageModuleMessages(const char *from_msg);
|
|
|
|
#ifdef RAK14014
|
|
cannedMessageModuleRunState getRunState() const { return runState; }
|
|
#endif
|
|
|
|
// === Packet Interest Filter ===
|
|
virtual bool wantPacket(const meshtastic_MeshPacket *p) override
|
|
{
|
|
if (p->rx_rssi != 0)
|
|
lastRxRssi = p->rx_rssi;
|
|
if (p->rx_snr > 0)
|
|
lastRxSnr = p->rx_snr;
|
|
return (p->decoded.portnum == meshtastic_PortNum_ROUTING_APP) ? waitingForAck : false;
|
|
}
|
|
|
|
protected:
|
|
// === Thread Entry Point ===
|
|
virtual int32_t runOnce() override;
|
|
|
|
// === Transmission ===
|
|
void sendText(NodeNum dest, ChannelIndex channel, const char *message, bool wantReplies);
|
|
void drawHeader(OLEDDisplay *display, int16_t x, int16_t y, char *buffer);
|
|
int splitConfiguredMessages();
|
|
int getNextIndex();
|
|
int getPrevIndex();
|
|
|
|
#if defined(USE_VIRTUAL_KEYBOARD)
|
|
void drawKeyboard(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
|
|
String keyForCoordinates(uint x, uint y);
|
|
void drawShiftIcon(OLEDDisplay *display, int x, int y, float scale = 1);
|
|
void drawBackspaceIcon(OLEDDisplay *display, int x, int y, float scale = 1);
|
|
void drawEnterIcon(OLEDDisplay *display, int x, int y, float scale = 1);
|
|
#endif
|
|
|
|
// === Input Handling ===
|
|
int handleInputEvent(const InputEvent *event);
|
|
virtual bool wantUIFrame() override { return shouldDraw(); }
|
|
virtual Observable<const UIFrameEvent *> *getUIFrameObservable() override { return this; }
|
|
virtual bool interceptingKeyboardInput() override;
|
|
virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) override;
|
|
virtual AdminMessageHandleResult handleAdminMessageForModule(const meshtastic_MeshPacket &mp,
|
|
meshtastic_AdminMessage *request,
|
|
meshtastic_AdminMessage *response) override;
|
|
|
|
virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override;
|
|
|
|
void loadProtoForModule();
|
|
bool saveProtoForModule();
|
|
void installDefaultCannedMessageModuleConfig();
|
|
|
|
private:
|
|
// === Input Observers ===
|
|
CallbackObserver<CannedMessageModule, const InputEvent *> inputObserver =
|
|
CallbackObserver<CannedMessageModule, const InputEvent *>(this, &CannedMessageModule::handleInputEvent);
|
|
|
|
// === Display and UI ===
|
|
int displayHeight = 64;
|
|
int destIndex = 0;
|
|
int scrollIndex = 0;
|
|
int visibleRows = 0;
|
|
bool needsUpdate = true;
|
|
unsigned long lastUpdateMillis = 0;
|
|
String searchQuery;
|
|
String freetext;
|
|
|
|
// === Message Storage ===
|
|
char messageBuffer[CANNED_MESSAGE_MODULE_MESSAGES_SIZE + 1];
|
|
char *messages[CANNED_MESSAGE_MODULE_MESSAGE_MAX_COUNT];
|
|
int messagesCount = 0;
|
|
int currentMessageIndex = -1;
|
|
|
|
// === Routing & Acknowledgment ===
|
|
NodeNum dest = NODENUM_BROADCAST; // Destination node for outgoing messages (default: broadcast)
|
|
NodeNum incoming = NODENUM_BROADCAST; // Source node from which last ACK/NACK was received
|
|
NodeNum lastSentNode = 0; // Tracks the most recent node we sent a message to (for UI display)
|
|
ChannelIndex channel = 0; // Channel index used when sending a message
|
|
|
|
bool ack = false; // True = ACK received, False = NACK or failed
|
|
bool waitingForAck = false; // True if we're expecting an ACK and should monitor routing packets
|
|
float lastRxSnr = 0; // SNR from last received ACK (used for diagnostics/UI)
|
|
int32_t lastRxRssi = 0; // RSSI from last received ACK (used for diagnostics/UI)
|
|
uint32_t lastRequestId = 0; // tracks the request_id of our last sent packet
|
|
|
|
// === State Tracking ===
|
|
cannedMessageModuleRunState runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
|
|
char highlight = 0x00;
|
|
char payload = 0x00;
|
|
unsigned int cursor = 0;
|
|
unsigned long lastTouchMillis = 0;
|
|
uint32_t lastFilterUpdate = 0;
|
|
static constexpr uint32_t filterDebounceMs = 30;
|
|
std::vector<uint8_t> activeChannelIndices;
|
|
std::vector<NodeEntry> filteredNodes;
|
|
|
|
#if defined(USE_VIRTUAL_KEYBOARD)
|
|
bool shift = false;
|
|
int charSet = 0; // 0=ABC, 1=123
|
|
#endif
|
|
|
|
bool isUpEvent(const InputEvent *event);
|
|
bool isDownEvent(const InputEvent *event);
|
|
bool isSelectEvent(const InputEvent *event);
|
|
bool handleTabSwitch(const InputEvent *event);
|
|
int handleDestinationSelectionInput(const InputEvent *event, bool isUp, bool isDown, bool isSelect);
|
|
bool handleMessageSelectorInput(const InputEvent *event, bool isUp, bool isDown, bool isSelect);
|
|
bool handleFreeTextInput(const InputEvent *event);
|
|
|
|
#if defined(USE_VIRTUAL_KEYBOARD)
|
|
Letter keyboard[2][4][10] = {{{{"Q", 20, 0, 0, 0, 0},
|
|
{"W", 22, 0, 0, 0, 0},
|
|
{"E", 17, 0, 0, 0, 0},
|
|
{"R", 16.5, 0, 0, 0, 0},
|
|
{"T", 14, 0, 0, 0, 0},
|
|
{"Y", 15, 0, 0, 0, 0},
|
|
{"U", 16.5, 0, 0, 0, 0},
|
|
{"I", 5, 0, 0, 0, 0},
|
|
{"O", 19.5, 0, 0, 0, 0},
|
|
{"P", 15.5, 0, 0, 0, 0}},
|
|
{{"A", 14, 0, 0, 0, 0},
|
|
{"S", 15, 0, 0, 0, 0},
|
|
{"D", 16.5, 0, 0, 0, 0},
|
|
{"F", 15, 0, 0, 0, 0},
|
|
{"G", 17, 0, 0, 0, 0},
|
|
{"H", 15.5, 0, 0, 0, 0},
|
|
{"J", 12, 0, 0, 0, 0},
|
|
{"K", 15.5, 0, 0, 0, 0},
|
|
{"L", 14, 0, 0, 0, 0},
|
|
{"", 0, 0, 0, 0, 0}},
|
|
{{"⇧", 20, 0, 0, 0, 0},
|
|
{"Z", 14, 0, 0, 0, 0},
|
|
{"X", 14.5, 0, 0, 0, 0},
|
|
{"C", 15.5, 0, 0, 0, 0},
|
|
{"V", 13.5, 0, 0, 0, 0},
|
|
{"B", 15, 0, 0, 0, 0},
|
|
{"N", 15, 0, 0, 0, 0},
|
|
{"M", 17, 0, 0, 0, 0},
|
|
{"⌫", 20, 0, 0, 0, 0},
|
|
{"", 0, 0, 0, 0, 0}},
|
|
{{"123", 42, 0, 0, 0, 0},
|
|
{" ", 64, 0, 0, 0, 0},
|
|
{"↵", 36, 0, 0, 0, 0},
|
|
{"", 0, 0, 0, 0, 0},
|
|
{"", 0, 0, 0, 0, 0},
|
|
{"", 0, 0, 0, 0, 0},
|
|
{"", 0, 0, 0, 0, 0},
|
|
{"", 0, 0, 0, 0, 0},
|
|
{"", 0, 0, 0, 0, 0},
|
|
{"", 0, 0, 0, 0, 0}}},
|
|
{{{"1", 12, 0, 0, 0, 0},
|
|
{"2", 13.5, 0, 0, 0, 0},
|
|
{"3", 12.5, 0, 0, 0, 0},
|
|
{"4", 14, 0, 0, 0, 0},
|
|
{"5", 14, 0, 0, 0, 0},
|
|
{"6", 14, 0, 0, 0, 0},
|
|
{"7", 13.5, 0, 0, 0, 0},
|
|
{"8", 14, 0, 0, 0, 0},
|
|
{"9", 14, 0, 0, 0, 0},
|
|
{"0", 14, 0, 0, 0, 0}},
|
|
{{"-", 8, 0, 0, 0, 0},
|
|
{"/", 8, 0, 0, 0, 0},
|
|
{":", 4.5, 0, 0, 0, 0},
|
|
{";", 4.5, 0, 0, 0, 0},
|
|
{"(", 7, 0, 0, 0, 0},
|
|
{")", 6.5, 0, 0, 0, 0},
|
|
{"$", 12.5, 0, 0, 0, 0},
|
|
{"&", 15, 0, 0, 0, 0},
|
|
{"@", 21.5, 0, 0, 0, 0},
|
|
{"\"", 8, 0, 0, 0, 0}},
|
|
{{".", 8, 0, 0, 0, 0},
|
|
{",", 8, 0, 0, 0, 0},
|
|
{"?", 10, 0, 0, 0, 0},
|
|
{"!", 10, 0, 0, 0, 0},
|
|
{"'", 10, 0, 0, 0, 0},
|
|
{"⌫", 20, 0, 0, 0, 0}},
|
|
{{"ABC", 50, 0, 0, 0, 0}, {" ", 64, 0, 0, 0, 0}, {"↵", 36, 0, 0, 0, 0}}}};
|
|
#endif
|
|
};
|
|
|
|
extern CannedMessageModule *cannedMessageModule;
|
|
#endif
|