Display sending state.

pull/1090/head
Balazs Kelemen 2022-01-04 22:02:16 +01:00
rodzic 4a29aef19e
commit b3ddf16d64
3 zmienionych plików z 43 dodań i 26 usunięć

Wyświetl plik

@ -290,19 +290,22 @@ static void drawCannedMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *sta
{
displayedNodeNum = 0; // Not currently showing a node pane
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(FONT_SMALL);
display->drawString(0 + x, 0 + y, cannedMessagePlugin->getPrevMessage());
display->setFont(FONT_MEDIUM);
display->drawString(0 + x, 0 + y + 8, cannedMessagePlugin->getCurrentMessage());
display->setFont(FONT_SMALL);
display->drawString(0 + x, 0 + y + 24, cannedMessagePlugin->getNextMessage());
// the max length of this buffer is much longer than we can possibly print
// static char tempBuf[96];
// snprintf(tempBuf, sizeof(tempBuf), " %s", mp.decoded.payload.bytes);
// display->drawStringMaxWidth(4 + x, 10 + y, SCREEN_WIDTH - (6 + x), tempBuf);
if (cannedMessagePlugin->getSendingState() == SENDING_STATE_NONE)
{
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(FONT_SMALL);
display->drawString(0 + x, 0 + y, cannedMessagePlugin->getPrevMessage());
display->setFont(FONT_MEDIUM);
display->drawString(0 + x, 0 + y + 8, cannedMessagePlugin->getCurrentMessage());
display->setFont(FONT_SMALL);
display->drawString(0 + x, 0 + y + 24, cannedMessagePlugin->getNextMessage());
}
else
{
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->setFont(FONT_MEDIUM);
display->drawString(display->getWidth()/2 + x, 0 + y + 12, "Sending...");
}
}
/// Draw a series of fields in a column, wrapping to multiple colums if needed

Wyświetl plik

@ -51,9 +51,8 @@ void CannedMessagePlugin::sendText(NodeNum dest,
{
MeshPacket *p = allocDataPacket();
p->to = dest;
const char *replyStr = "This is a canned message";
p->decoded.payload.size = strlen(replyStr); // You must specify how many bytes are in the reply
memcpy(p->decoded.payload.bytes, replyStr, p->decoded.payload.size);
p->decoded.payload.size = strlen(message);
memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size);
// PacketId prevPacketId = p->id; // In case we need it later.
@ -65,7 +64,13 @@ void CannedMessagePlugin::sendText(NodeNum dest,
int32_t CannedMessagePlugin::runOnce()
{
if ((this->action != ACTION_NONE)
if (this->sendingState == SENDING_STATE_ACTIVE)
{
// TODO: might have some feedback of sendig state
this->sendingState = SENDING_STATE_NONE;
this->notifyObservers(NULL);
}
else if ((this->action != ACTION_NONE)
&& (this->currentMessageIndex == -1))
{
this->currentMessageIndex = 0;
@ -78,6 +83,9 @@ int32_t CannedMessagePlugin::runOnce()
NODENUM_BROADCAST,
cannedMessagePluginMessages[this->currentMessageIndex],
true);
this->sendingState = SENDING_STATE_ACTIVE;
this->currentMessageIndex = -1;
return 2000;
}
else if (this->action == ACTION_UP)
{

Wyświetl plik

@ -15,26 +15,27 @@ enum cannedMessagePluginActionType
ACTION_DOWN
};
enum cannedMessagePluginSendigState
{
SENDING_STATE_NONE,
SENDING_STATE_ACTIVE
};
#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",
"Need helping hand",
"Help me 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"
"We have company"
};
typedef struct _CannedMessagePluginStatus
{
int dummy;
} CannedMessagePluginStatus;
class CannedMessagePlugin :
public SinglePortPlugin,
public Observable<const meshtastic::Status *>,
@ -59,7 +60,11 @@ class CannedMessagePlugin :
}
bool shouldDraw()
{
return currentMessageIndex != -1;
return (currentMessageIndex != -1) || (this->sendingState != SENDING_STATE_NONE);
}
cannedMessagePluginSendigState getSendingState()
{
return this->sendingState;
}
protected:
@ -106,6 +111,7 @@ class CannedMessagePlugin :
volatile int rotaryLevelA = LOW;
volatile int rotaryLevelB = LOW;
int currentMessageIndex = -1;
cannedMessagePluginSendigState sendingState = SENDING_STATE_NONE;
};
extern CannedMessagePlugin *cannedMessagePlugin;