meshtastic-firmware/src/modules/CannedMessageModule.h

226 wiersze
9.2 KiB
C
Czysty Zwykły widok Historia

2022-01-04 18:42:28 +00:00
#pragma once
2022-10-13 13:44:27 +00:00
#if HAS_SCREEN
#include "ProtobufModule.h"
2022-01-12 08:26:42 +00:00
#include "input/InputBroker.h"
2022-01-04 18:42:28 +00:00
2023-01-21 13:34:29 +00:00
enum cannedMessageModuleRunState {
CANNED_MESSAGE_RUN_STATE_DISABLED,
2022-01-19 08:55:06 +00:00
CANNED_MESSAGE_RUN_STATE_INACTIVE,
CANNED_MESSAGE_RUN_STATE_ACTIVE,
CANNED_MESSAGE_RUN_STATE_FREETEXT,
2022-01-19 08:55:06 +00:00
CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE,
CANNED_MESSAGE_RUN_STATE_ACK_NACK_RECEIVED,
CANNED_MESSAGE_RUN_STATE_MESSAGE,
2022-01-19 08:55:06 +00:00
CANNED_MESSAGE_RUN_STATE_ACTION_SELECT,
CANNED_MESSAGE_RUN_STATE_ACTION_UP,
CANNED_MESSAGE_RUN_STATE_ACTION_DOWN,
2022-01-04 21:02:16 +00:00
};
enum cannedMessageDestinationType {
CANNED_MESSAGE_DESTINATION_TYPE_NONE,
CANNED_MESSAGE_DESTINATION_TYPE_NODE,
CANNED_MESSAGE_DESTINATION_TYPE_CHANNEL
};
enum CannedMessageModuleIconType { shift, backspace, space, enter };
struct Letter {
String character;
float width;
int rectX;
int rectY;
int rectWidth;
int rectHeight;
};
2022-02-27 09:49:24 +00:00
#define CANNED_MESSAGE_MODULE_MESSAGE_MAX_COUNT 50
/**
2022-02-27 09:20:23 +00:00
* Sum of CannedMessageModuleConfig part sizes.
*/
2022-02-27 09:49:24 +00:00
#define CANNED_MESSAGE_MODULE_MESSAGES_SIZE 800
2022-01-04 18:43:06 +00:00
#ifndef CANNED_MESSAGE_MODULE_ENABLE
#define CANNED_MESSAGE_MODULE_ENABLE 0
#endif
2023-01-21 13:34:29 +00:00
class CannedMessageModule : public SinglePortModule, public Observable<const UIFrameEvent *>, private concurrency::OSThread
2022-01-04 18:42:28 +00:00
{
2022-02-27 09:20:23 +00:00
CallbackObserver<CannedMessageModule, const InputEvent *> inputObserver =
2023-01-21 13:34:29 +00:00
CallbackObserver<CannedMessageModule, const InputEvent *>(this, &CannedMessageModule::handleInputEvent);
2022-01-04 18:42:28 +00:00
public:
2022-02-27 09:20:23 +00:00
CannedMessageModule();
2023-01-21 13:34:29 +00:00
const char *getCurrentMessage();
const char *getPrevMessage();
const char *getNextMessage();
const char *getMessageByIndex(int index);
2023-01-21 13:34:29 +00:00
const char *getNodeName(NodeNum node);
2022-01-09 09:08:31 +00:00
bool shouldDraw();
bool hasMessages();
// void eventUp();
// void eventDown();
// void eventSelect();
2022-01-04 18:42:28 +00:00
void handleGetCannedMessageModuleMessages(const meshtastic_MeshPacket &req, meshtastic_AdminMessage *response);
void handleSetCannedMessageModuleMessages(const char *from_msg);
void showTemporaryMessage(const String &message);
2022-09-20 14:21:32 +00:00
String drawWithCursor(String text, int cursor);
/*
-Override the wantPacket method. We need the Routing Messages to look for ACKs.
*/
virtual bool wantPacket(const meshtastic_MeshPacket *p) override
{
if (p->rx_rssi != 0) {
this->lastRxRssi = p->rx_rssi;
}
if (p->rx_snr > 0) {
this->lastRxSnr = p->rx_snr;
}
switch (p->decoded.portnum) {
case meshtastic_PortNum_ROUTING_APP:
Show specific frame when updating screen (#4264) * Updated setFrames in Screen.cpp Added code to attempt to revert back to the same frame that user was on prior to setFrame reload. * Space added Screen.cpp * Update Screen.cpp Make screen to revert to Frame 0 if the originally displayed frame is no longer there. * Update Screen.cpp Inserted boolean holdPosition into setFrames to indicate the requirement to stay on the same frame ( if =true) or else it will switch to new frame . Only Screen::handleStatusUpdate calls with setFrame(true). ( For Node Updates) All other types of updates call as before setFrame(), so it will change focus as needed. * Hold position, even if number of frames increases * Hold position, if handling an outgoing text message * Update Screen.cpp * Reverted chnages related to devicestate.has_rx_text_message * Reset to master * CannedMessages only handles routing packets when waiting for ACK Previously, this was calling Screen::setFrames at unexpected times * Gather position info about screen frames while regenerating * Make admin module observable Notify only when relevant. Currently: only to handle remove_nodenum. * Optionally specify which frame to focus when setFrames runs * UIFrameEvent uses enum instead of multiple booleans * Allow modules to request their own frame to be focussed This is done internally by calling MeshModule::requestFocus() Easier this way, insteady of passing the info in the UIFrameEvent: * Modules don't always know whether they should be focussed until after the UIFrameEvent has been raised, in dramFrame * Don't have to pass reference to module instance as parameter though several methods * E-Ink screensaver uses FOCUS_PRESERVE Previously, it had its own basic implementation of this. * Spelling: regional variant * trunk * Fix HAS_SCREEN guarding * More HAS_SCREEN guarding --------- Co-authored-by: BIST <77391720+slash-bit@users.noreply.github.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: slash-bit <v-b2@live.com>
2024-07-11 23:51:26 +00:00
return waitingForAck;
default:
return false;
}
}
2022-01-04 18:42:28 +00:00
protected:
2022-01-24 17:24:40 +00:00
virtual int32_t runOnce() override;
2022-01-04 18:42:28 +00:00
void sendText(NodeNum dest, ChannelIndex channel, const char *message, bool wantReplies);
2022-01-04 18:42:28 +00:00
2022-01-12 08:26:42 +00:00
int splitConfiguredMessages();
2022-01-09 09:08:31 +00:00
int getNextIndex();
int getPrevIndex();
#if defined(T_WATCH_S3) || defined(RAK14014)
void drawKeyboard(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
String keyForCoordinates(uint x, uint y);
bool shift = false;
int charSet = 0;
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
char highlight = 0x00;
2022-01-09 09:08:31 +00:00
int handleInputEvent(const InputEvent *event);
2022-01-24 17:24:40 +00:00
virtual bool wantUIFrame() override { return this->shouldDraw(); }
2023-01-21 13:34:29 +00:00
virtual Observable<const UIFrameEvent *> *getUIFrameObservable() override { return this; }
virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) override;
2023-01-21 17:39:58 +00:00
virtual AdminMessageHandleResult handleAdminMessageForModule(const meshtastic_MeshPacket &mp,
meshtastic_AdminMessage *request,
meshtastic_AdminMessage *response) override;
/** Called to handle a particular incoming message
* @return ProcessMessage::STOP if you've guaranteed you've handled this message and no other handlers should be considered
* for it
*/
virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override;
2022-02-27 10:21:02 +00:00
void loadProtoForModule();
bool saveProtoForModule();
2022-02-27 09:20:23 +00:00
void installDefaultCannedMessageModuleConfig();
2022-01-04 18:42:28 +00:00
2022-01-04 18:43:06 +00:00
int currentMessageIndex = -1;
2022-02-27 09:20:23 +00:00
cannedMessageModuleRunState runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
char payload = 0x00;
unsigned int cursor = 0;
String freetext = ""; // Text Buffer for Freetext Editor
NodeNum dest = NODENUM_BROADCAST;
ChannelIndex channel = 0;
cannedMessageDestinationType destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE;
uint8_t numChannels = 0;
ChannelIndex indexChannels[MAX_NUM_CHANNELS] = {0};
NodeNum incoming = NODENUM_BROADCAST;
Show specific frame when updating screen (#4264) * Updated setFrames in Screen.cpp Added code to attempt to revert back to the same frame that user was on prior to setFrame reload. * Space added Screen.cpp * Update Screen.cpp Make screen to revert to Frame 0 if the originally displayed frame is no longer there. * Update Screen.cpp Inserted boolean holdPosition into setFrames to indicate the requirement to stay on the same frame ( if =true) or else it will switch to new frame . Only Screen::handleStatusUpdate calls with setFrame(true). ( For Node Updates) All other types of updates call as before setFrame(), so it will change focus as needed. * Hold position, even if number of frames increases * Hold position, if handling an outgoing text message * Update Screen.cpp * Reverted chnages related to devicestate.has_rx_text_message * Reset to master * CannedMessages only handles routing packets when waiting for ACK Previously, this was calling Screen::setFrames at unexpected times * Gather position info about screen frames while regenerating * Make admin module observable Notify only when relevant. Currently: only to handle remove_nodenum. * Optionally specify which frame to focus when setFrames runs * UIFrameEvent uses enum instead of multiple booleans * Allow modules to request their own frame to be focussed This is done internally by calling MeshModule::requestFocus() Easier this way, insteady of passing the info in the UIFrameEvent: * Modules don't always know whether they should be focussed until after the UIFrameEvent has been raised, in dramFrame * Don't have to pass reference to module instance as parameter though several methods * E-Ink screensaver uses FOCUS_PRESERVE Previously, it had its own basic implementation of this. * Spelling: regional variant * trunk * Fix HAS_SCREEN guarding * More HAS_SCREEN guarding --------- Co-authored-by: BIST <77391720+slash-bit@users.noreply.github.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: slash-bit <v-b2@live.com>
2024-07-11 23:51:26 +00:00
bool ack = false; // True means ACK, false means NAK (error_reason != NONE)
bool waitingForAck = false; // Are currently interested in routing packets?
float lastRxSnr = 0;
int32_t lastRxRssi = 0;
2022-01-12 08:26:42 +00:00
2023-01-21 13:34:29 +00:00
char messageStore[CANNED_MESSAGE_MODULE_MESSAGES_SIZE + 1];
2022-02-27 09:49:24 +00:00
char *messages[CANNED_MESSAGE_MODULE_MESSAGE_MAX_COUNT];
2022-01-12 08:26:42 +00:00
int messagesCount = 0;
2022-01-13 11:51:36 +00:00
unsigned long lastTouchMillis = 0;
String temporaryMessage;
#if defined(T_WATCH_S3) || defined(RAK14014)
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
2022-01-04 18:42:28 +00:00
};
2022-02-27 09:20:23 +00:00
extern CannedMessageModule *cannedMessageModule;
2024-09-06 02:32:24 +00:00
#endif