firmware/src/plugins/CannedMessagePlugin.h

70 lines
1.9 KiB
C
Raw Normal View History

2022-01-04 18:42:28 +00:00
#pragma once
#include "SinglePortPlugin.h"
2022-01-12 08:26:42 +00:00
#include "input/InputBroker.h"
2022-01-04 18:42:28 +00:00
enum cannedMessagePluginActionType
{
2022-01-09 09:08:31 +00:00
CANNED_MESSAGE_ACTION_NONE,
CANNED_MESSAGE_ACTION_SELECT,
CANNED_MESSAGE_ACTION_UP,
CANNED_MESSAGE_ACTION_DOWN
2022-01-04 18:42:28 +00:00
};
2022-01-04 21:02:16 +00:00
enum cannedMessagePluginSendigState
{
SENDING_STATE_NONE,
SENDING_STATE_ACTIVE
};
2022-01-13 08:19:36 +00:00
2022-01-12 08:26:42 +00:00
#define CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_COUNT 50
2022-01-04 18:43:06 +00:00
class CannedMessagePlugin :
public SinglePortPlugin,
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-01-09 09:08:31 +00:00
CallbackObserver<CannedMessagePlugin, const InputEvent *> inputObserver =
CallbackObserver<CannedMessagePlugin, const InputEvent *>(
this, &CannedMessagePlugin::handleInputEvent);
2022-01-04 18:42:28 +00:00
public:
2022-01-11 15:02:55 +00:00
CannedMessagePlugin();
2022-01-09 09:08:31 +00:00
String getCurrentMessage();
String getPrevMessage();
String getNextMessage();
bool shouldDraw();
cannedMessagePluginSendigState getSendingState();
void eventUp();
void eventDown();
void eventSelect();
2022-01-04 18:42:28 +00:00
protected:
2022-01-13 11:51:36 +00:00
virtual int32_t runOnce();
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-09 09:08:31 +00:00
int handleInputEvent(const InputEvent *event);
2022-01-13 07:08:16 +00:00
virtual bool wantUIFrame() { return this->shouldDraw(); }
2022-01-13 08:19:36 +00:00
virtual Observable<const UIFrameEvent *>* getUIFrameObservable() { return this; }
2022-01-13 07:08:16 +00:00
virtual void drawFrame(
OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
2022-01-04 18:42:28 +00:00
2022-01-09 09:08:31 +00:00
volatile cannedMessagePluginActionType action = CANNED_MESSAGE_ACTION_NONE;
2022-01-04 18:43:06 +00:00
int currentMessageIndex = -1;
2022-01-04 21:02:16 +00:00
cannedMessagePluginSendigState sendingState = SENDING_STATE_NONE;
2022-01-12 08:26:42 +00:00
char *messages[CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_COUNT];
int messagesCount = 0;
2022-01-13 11:51:36 +00:00
unsigned long lastTouchMillis = 0;
2022-01-04 18:42:28 +00:00
};
extern CannedMessagePlugin *cannedMessagePlugin;