2022-01-04 18:42:28 +00:00
|
|
|
#pragma once
|
|
|
|
#include "SinglePortPlugin.h"
|
|
|
|
|
2022-01-04 18:43:06 +00:00
|
|
|
enum cannedMessagePluginRotaryStateType
|
2022-01-04 18:42:28 +00:00
|
|
|
{
|
|
|
|
EVENT_OCCURRED,
|
|
|
|
EVENT_CLEARED
|
|
|
|
};
|
|
|
|
|
|
|
|
enum cannedMessagePluginActionType
|
|
|
|
{
|
|
|
|
ACTION_NONE,
|
|
|
|
ACTION_PRESSED,
|
|
|
|
ACTION_UP,
|
|
|
|
ACTION_DOWN
|
|
|
|
};
|
|
|
|
|
2022-01-04 18:43:06 +00:00
|
|
|
#define CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_LEN 50
|
|
|
|
|
|
|
|
static char cannedMessagePluginMessages[][CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_LEN] =
|
|
|
|
{
|
|
|
|
"I need a helping hand",
|
|
|
|
"I need help with saw",
|
|
|
|
"I need an alpinist",
|
|
|
|
"I need ambulance",
|
|
|
|
"I'm fine",
|
|
|
|
"I'm already waiting",
|
|
|
|
"I will be late",
|
|
|
|
"I couldn't join",
|
|
|
|
"We have got company"
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _CannedMessagePluginStatus
|
|
|
|
{
|
|
|
|
int dummy;
|
|
|
|
} CannedMessagePluginStatus;
|
|
|
|
|
|
|
|
class CannedMessagePlugin :
|
|
|
|
public SinglePortPlugin,
|
|
|
|
public Observable<const meshtastic::Status *>,
|
|
|
|
private concurrency::OSThread
|
2022-01-04 18:42:28 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CannedMessagePlugin();
|
|
|
|
void select();
|
|
|
|
void directionA();
|
|
|
|
void directionB();
|
2022-01-04 19:41:45 +00:00
|
|
|
String getCurrentMessage()
|
2022-01-04 18:43:06 +00:00
|
|
|
{
|
|
|
|
return cannedMessagePluginMessages[this->currentMessageIndex];
|
|
|
|
}
|
2022-01-04 19:41:45 +00:00
|
|
|
String getPrevMessage()
|
|
|
|
{
|
|
|
|
return cannedMessagePluginMessages[this->getPrevIndex()];
|
|
|
|
}
|
|
|
|
String getNextMessage()
|
|
|
|
{
|
|
|
|
return cannedMessagePluginMessages[this->getNextIndex()];
|
|
|
|
}
|
2022-01-04 18:43:06 +00:00
|
|
|
bool shouldDraw()
|
|
|
|
{
|
|
|
|
return currentMessageIndex != -1;
|
|
|
|
}
|
2022-01-04 18:42:28 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual int32_t runOnce();
|
|
|
|
|
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-04 19:41:45 +00:00
|
|
|
int getNextIndex()
|
|
|
|
{
|
|
|
|
if (this->currentMessageIndex >=
|
|
|
|
(sizeof(cannedMessagePluginMessages) / CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_LEN) - 1)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this->currentMessageIndex + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int getPrevIndex()
|
|
|
|
{
|
|
|
|
if (this->currentMessageIndex <= 0)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
sizeof(cannedMessagePluginMessages) / CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_LEN - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this->currentMessageIndex - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-04 18:42:28 +00:00
|
|
|
// TODO: make this configurable
|
|
|
|
volatile cannedMessagePluginActionType cwRotationMeaning = ACTION_UP;
|
|
|
|
|
|
|
|
volatile cannedMessagePluginActionType action = ACTION_NONE;
|
2022-01-04 18:43:06 +00:00
|
|
|
volatile cannedMessagePluginRotaryStateType rotaryStateCW = EVENT_CLEARED;
|
|
|
|
volatile cannedMessagePluginRotaryStateType rotaryStateCCW = EVENT_CLEARED;
|
2022-01-04 18:42:28 +00:00
|
|
|
volatile int rotaryLevelA = LOW;
|
|
|
|
volatile int rotaryLevelB = LOW;
|
2022-01-04 18:43:06 +00:00
|
|
|
int currentMessageIndex = -1;
|
2022-01-04 18:42:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern CannedMessagePlugin *cannedMessagePlugin;
|