2022-01-04 18:42:28 +00:00
|
|
|
#pragma once
|
2022-07-31 12:11:47 +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
|
|
|
|
2022-02-27 09:20:23 +00:00
|
|
|
enum cannedMessageModuleRunState
|
2022-01-04 18:42:28 +00:00
|
|
|
{
|
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,
|
|
|
|
CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE,
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2022-01-13 08:19:36 +00:00
|
|
|
|
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
|
|
|
|
2022-02-27 09:20:23 +00:00
|
|
|
class CannedMessageModule :
|
2022-03-09 08:01:43 +00:00
|
|
|
public SinglePortModule,
|
2022-01-13 08:19:36 +00:00
|
|
|
public Observable<const UIFrameEvent *>,
|
2022-01-04 18:43:06 +00:00
|
|
|
private concurrency::OSThread
|
2022-01-04 18:42:28 +00:00
|
|
|
{
|
2022-02-27 09:20:23 +00:00
|
|
|
CallbackObserver<CannedMessageModule, const InputEvent *> inputObserver =
|
|
|
|
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();
|
2022-01-18 22:15:54 +00:00
|
|
|
const char* getCurrentMessage();
|
|
|
|
const char* getPrevMessage();
|
|
|
|
const char* getNextMessage();
|
2022-01-09 09:08:31 +00:00
|
|
|
bool shouldDraw();
|
|
|
|
void eventUp();
|
|
|
|
void eventDown();
|
|
|
|
void eventSelect();
|
2022-01-04 18:42:28 +00:00
|
|
|
|
2022-02-27 09:20:23 +00:00
|
|
|
void handleGetCannedMessageModulePart1(const MeshPacket &req, AdminMessage *response);
|
|
|
|
void handleGetCannedMessageModulePart2(const MeshPacket &req, AdminMessage *response);
|
|
|
|
void handleGetCannedMessageModulePart3(const MeshPacket &req, AdminMessage *response);
|
|
|
|
void handleGetCannedMessageModulePart4(const MeshPacket &req, AdminMessage *response);
|
2022-02-21 05:29:15 +00:00
|
|
|
|
2022-02-27 09:20:23 +00:00
|
|
|
void handleSetCannedMessageModulePart1(const char *from_msg);
|
|
|
|
void handleSetCannedMessageModulePart2(const char *from_msg);
|
|
|
|
void handleSetCannedMessageModulePart3(const char *from_msg);
|
|
|
|
void handleSetCannedMessageModulePart4(const char *from_msg);
|
2022-02-21 05:29:15 +00:00
|
|
|
|
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
|
|
|
|
2022-01-04 18:43:06 +00:00
|
|
|
void sendText(
|
|
|
|
NodeNum dest,
|
|
|
|
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(); }
|
|
|
|
virtual Observable<const UIFrameEvent *>* getUIFrameObservable() override { return this; }
|
2022-01-13 07:08:16 +00:00
|
|
|
virtual void drawFrame(
|
2022-01-24 17:24:40 +00:00
|
|
|
OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) override;
|
2022-02-27 10:21:02 +00:00
|
|
|
virtual AdminMessageHandleResult handleAdminMessageForModule(
|
2022-02-21 05:29:15 +00:00
|
|
|
const MeshPacket &mp, AdminMessage *request, AdminMessage *response) 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-01-12 08:26:42 +00:00
|
|
|
|
2022-02-27 09:49:24 +00:00
|
|
|
char messageStore[CANNED_MESSAGE_MODULE_MESSAGES_SIZE+1];
|
|
|
|
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;
|
2022-05-06 13:41:37 +00:00
|
|
|
#endif
|