2022-01-04 18:42:28 +00:00
|
|
|
#pragma once
|
2022-10-13 13:44:27 +00:00
|
|
|
#if HAS_SCREEN
|
2022-03-09 08:01:43 +00:00
|
|
|
#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 {
|
2022-02-21 05:29:15 +00:00
|
|
|
CANNED_MESSAGE_RUN_STATE_DISABLED,
|
2022-01-19 08:55:06 +00:00
|
|
|
CANNED_MESSAGE_RUN_STATE_INACTIVE,
|
|
|
|
CANNED_MESSAGE_RUN_STATE_ACTIVE,
|
2022-09-20 11:50:18 +00:00
|
|
|
CANNED_MESSAGE_RUN_STATE_FREETEXT,
|
2022-01-19 08:55:06 +00:00
|
|
|
CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE,
|
2023-12-11 14:11:10 +00:00
|
|
|
CANNED_MESSAGE_RUN_STATE_ACK_NACK_RECEIVED,
|
2022-01-19 08:55:06 +00:00
|
|
|
CANNED_MESSAGE_RUN_STATE_ACTION_SELECT,
|
|
|
|
CANNED_MESSAGE_RUN_STATE_ACTION_UP,
|
2022-02-21 05:29:15 +00:00
|
|
|
CANNED_MESSAGE_RUN_STATE_ACTION_DOWN,
|
2022-01-04 21:02:16 +00:00
|
|
|
};
|
|
|
|
|
2023-12-11 22:49:33 +00:00
|
|
|
enum cannedMessageDestinationType {
|
|
|
|
CANNED_MESSAGE_DESTINATION_TYPE_NONE,
|
|
|
|
CANNED_MESSAGE_DESTINATION_TYPE_NODE,
|
|
|
|
CANNED_MESSAGE_DESTINATION_TYPE_CHANNEL
|
|
|
|
};
|
|
|
|
|
2022-02-27 09:49:24 +00:00
|
|
|
#define CANNED_MESSAGE_MODULE_MESSAGE_MAX_COUNT 50
|
2022-01-18 22:15:54 +00:00
|
|
|
/**
|
2022-02-27 09:20:23 +00:00
|
|
|
* Sum of CannedMessageModuleConfig part sizes.
|
2022-01-18 22:15:54 +00:00
|
|
|
*/
|
2022-02-27 09:49:24 +00:00
|
|
|
#define CANNED_MESSAGE_MODULE_MESSAGES_SIZE 800
|
2022-01-04 18:43:06 +00:00
|
|
|
|
2023-08-16 20:07:22 +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();
|
2023-07-30 12:51:26 +00:00
|
|
|
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();
|
2023-08-22 14:23:02 +00:00
|
|
|
// void eventUp();
|
|
|
|
// void eventDown();
|
|
|
|
// void eventSelect();
|
2022-01-04 18:42:28 +00:00
|
|
|
|
2023-01-21 17:22:19 +00:00
|
|
|
void handleGetCannedMessageModuleMessages(const meshtastic_MeshPacket &req, meshtastic_AdminMessage *response);
|
2022-08-16 02:06:55 +00:00
|
|
|
void handleSetCannedMessageModuleMessages(const char *from_msg);
|
2022-02-21 05:29:15 +00:00
|
|
|
|
2022-09-20 14:21:32 +00:00
|
|
|
String drawWithCursor(String text, int cursor);
|
|
|
|
|
2023-08-22 14:23:02 +00:00
|
|
|
/*
|
|
|
|
-Override the wantPacket method. We need the Routing Messages to look for ACKs.
|
|
|
|
*/
|
|
|
|
virtual bool wantPacket(const meshtastic_MeshPacket *p) override
|
|
|
|
{
|
|
|
|
switch (p->decoded.portnum) {
|
|
|
|
case meshtastic_PortNum_TEXT_MESSAGE_APP:
|
|
|
|
case meshtastic_PortNum_ROUTING_APP:
|
|
|
|
return true;
|
|
|
|
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
|
|
|
|
2023-12-11 22:49:33 +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();
|
2022-01-04 19:41:45 +00:00
|
|
|
|
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,
|
2023-01-21 17:22:19 +00:00
|
|
|
meshtastic_AdminMessage *response) override;
|
2022-02-21 05:29:15 +00:00
|
|
|
|
2023-08-22 14:23:02 +00:00
|
|
|
/** 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-21 05:29:15 +00:00
|
|
|
|
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;
|
2022-10-06 20:34:55 +00:00
|
|
|
char payload = 0x00;
|
2022-09-23 17:52:42 +00:00
|
|
|
unsigned int cursor = 0;
|
2023-12-11 22:49:33 +00:00
|
|
|
String freetext = ""; // Text Buffer for Freetext Editor
|
2022-10-06 20:34:55 +00:00
|
|
|
NodeNum dest = NODENUM_BROADCAST;
|
2023-12-11 22:49:33 +00:00
|
|
|
ChannelIndex channel = 0;
|
|
|
|
cannedMessageDestinationType destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE;
|
|
|
|
uint8_t numChannels = 0;
|
|
|
|
ChannelIndex indexChannels[MAX_NUM_CHANNELS] = {0};
|
2023-08-22 14:23:02 +00:00
|
|
|
NodeNum incoming = NODENUM_BROADCAST;
|
2023-08-22 18:29:52 +00:00
|
|
|
bool ack = false; // True means ACK, false means NAK (error_reason != NONE)
|
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;
|
2022-01-04 18:42:28 +00:00
|
|
|
};
|
|
|
|
|
2022-02-27 09:20:23 +00:00
|
|
|
extern CannedMessageModule *cannedMessageModule;
|
2023-08-22 18:29:52 +00:00
|
|
|
#endif
|