mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-19 19:42:32 +00:00
Finalize destination selection. Primary Channel only for now.
This commit is contained in:
parent
2d4bfe183c
commit
a5761069ca
@ -2,6 +2,7 @@
|
|||||||
#if HAS_SCREEN
|
#if HAS_SCREEN
|
||||||
#include "CannedMessageModule.h"
|
#include "CannedMessageModule.h"
|
||||||
#include "FSCommon.h"
|
#include "FSCommon.h"
|
||||||
|
#include "NodeDB.h"
|
||||||
#include "MeshService.h"
|
#include "MeshService.h"
|
||||||
#include "PowerFSM.h" // neede for button bypass
|
#include "PowerFSM.h" // neede for button bypass
|
||||||
#include "mesh/generated/cannedmessages.pb.h"
|
#include "mesh/generated/cannedmessages.pb.h"
|
||||||
@ -222,6 +223,7 @@ int32_t CannedMessageModule::runOnce()
|
|||||||
this->currentMessageIndex = -1;
|
this->currentMessageIndex = -1;
|
||||||
this->freetext = ""; // clear freetext
|
this->freetext = ""; // clear freetext
|
||||||
this->cursor = 0;
|
this->cursor = 0;
|
||||||
|
this->destSelect = false;
|
||||||
this->notifyObservers(&e);
|
this->notifyObservers(&e);
|
||||||
} else if (((this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT)) && (millis() - this->lastTouchMillis) > INACTIVATE_AFTER_MS) {
|
} else if (((this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT)) && (millis() - this->lastTouchMillis) > INACTIVATE_AFTER_MS) {
|
||||||
// Reset module
|
// Reset module
|
||||||
@ -230,6 +232,7 @@ int32_t CannedMessageModule::runOnce()
|
|||||||
this->currentMessageIndex = -1;
|
this->currentMessageIndex = -1;
|
||||||
this->freetext = ""; // clear freetext
|
this->freetext = ""; // clear freetext
|
||||||
this->cursor = 0;
|
this->cursor = 0;
|
||||||
|
this->destSelect = false;
|
||||||
this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
|
this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
|
||||||
this->notifyObservers(&e);
|
this->notifyObservers(&e);
|
||||||
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_SELECT) {
|
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_SELECT) {
|
||||||
@ -254,6 +257,7 @@ int32_t CannedMessageModule::runOnce()
|
|||||||
this->currentMessageIndex = -1;
|
this->currentMessageIndex = -1;
|
||||||
this->freetext = ""; // clear freetext
|
this->freetext = ""; // clear freetext
|
||||||
this->cursor = 0;
|
this->cursor = 0;
|
||||||
|
this->destSelect = false;
|
||||||
this->notifyObservers(&e);
|
this->notifyObservers(&e);
|
||||||
return 2000;
|
return 2000;
|
||||||
} else if ((this->runState != CANNED_MESSAGE_RUN_STATE_FREETEXT) && (this->currentMessageIndex == -1)) {
|
} else if ((this->runState != CANNED_MESSAGE_RUN_STATE_FREETEXT) && (this->currentMessageIndex == -1)) {
|
||||||
@ -265,25 +269,67 @@ int32_t CannedMessageModule::runOnce()
|
|||||||
this->currentMessageIndex = getPrevIndex();
|
this->currentMessageIndex = getPrevIndex();
|
||||||
this->freetext = ""; // clear freetext
|
this->freetext = ""; // clear freetext
|
||||||
this->cursor = 0;
|
this->cursor = 0;
|
||||||
|
this->destSelect = false;
|
||||||
this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE;
|
this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE;
|
||||||
DEBUG_MSG("MOVE UP (%d):%s\n", this->currentMessageIndex, this->getCurrentMessage());
|
DEBUG_MSG("MOVE UP (%d):%s\n", this->currentMessageIndex, this->getCurrentMessage());
|
||||||
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_DOWN) {
|
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_DOWN) {
|
||||||
this->currentMessageIndex = this->getNextIndex();
|
this->currentMessageIndex = this->getNextIndex();
|
||||||
this->freetext = ""; // clear freetext
|
this->freetext = ""; // clear freetext
|
||||||
this->cursor = 0;
|
this->cursor = 0;
|
||||||
|
this->destSelect = false;
|
||||||
this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE;
|
this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE;
|
||||||
DEBUG_MSG("MOVE DOWN (%d):%s\n", this->currentMessageIndex, this->getCurrentMessage());
|
DEBUG_MSG("MOVE DOWN (%d):%s\n", this->currentMessageIndex, this->getCurrentMessage());
|
||||||
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {
|
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {
|
||||||
e.frameChanged = true;
|
e.frameChanged = true;
|
||||||
switch (this->payload) {
|
switch (this->payload) {
|
||||||
case 0xb4: // left
|
case 0xb4: // left
|
||||||
if (this->cursor > 0) {
|
if (this->destSelect){
|
||||||
this->cursor--;
|
size_t numNodes = nodeDB.getNumNodes();
|
||||||
|
if(this->dest == NODENUM_BROADCAST) {
|
||||||
|
this->dest = nodeDB.getNodeNum();
|
||||||
|
DEBUG_MSG("Replacing NodeNum_BROADCAST with %x\n",nodeDB.getNodeNum());
|
||||||
|
}
|
||||||
|
for (int i = 0; i < numNodes; i++) {
|
||||||
|
DEBUG_MSG("Considering %x\n",nodeDB.getNodeByIndex(i)->num);
|
||||||
|
if (nodeDB.getNodeByIndex(i)->num == this->dest) {
|
||||||
|
DEBUG_MSG("Match - advance %i-\n",i);
|
||||||
|
this->dest = (i > 0) ? nodeDB.getNodeByIndex(i-1)->num : nodeDB.getNodeByIndex(numNodes-1)->num;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(this->dest == nodeDB.getNodeNum()) {
|
||||||
|
this->dest = NODENUM_BROADCAST;
|
||||||
|
DEBUG_MSG("Replacing %x with NodeNum_BROADCAST\n",nodeDB.getNodeNum());
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if (this->cursor > 0) {
|
||||||
|
this->cursor--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0xb7: // right
|
case 0xb7: // right
|
||||||
if (this->cursor < this->freetext.length()) {
|
if (this->destSelect){
|
||||||
this->cursor++;
|
size_t numNodes = nodeDB.getNumNodes();
|
||||||
|
if(this->dest == NODENUM_BROADCAST) {
|
||||||
|
this->dest = nodeDB.getNodeNum();
|
||||||
|
DEBUG_MSG("Replacing NodeNum_BROADCAST with %x\n",nodeDB.getNodeNum());
|
||||||
|
}
|
||||||
|
for (int i = 0; i < numNodes; i++) {
|
||||||
|
DEBUG_MSG("Considering %x\n",nodeDB.getNodeByIndex(i)->num);
|
||||||
|
if (nodeDB.getNodeByIndex(i)->num == this->dest) {
|
||||||
|
DEBUG_MSG("Match - advance %i+\n",i);
|
||||||
|
this->dest = (i < numNodes-1) ? nodeDB.getNodeByIndex(i+1)->num : nodeDB.getNodeByIndex(0)->num;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(this->dest == nodeDB.getNodeNum()) {
|
||||||
|
this->dest = NODENUM_BROADCAST;
|
||||||
|
DEBUG_MSG("Replacing %x with NodeNum_BROADCAST\n",nodeDB.getNodeNum());
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if (this->cursor < this->freetext.length()) {
|
||||||
|
this->cursor++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x08: // backspace
|
case 0x08: // backspace
|
||||||
@ -345,6 +391,19 @@ const char *CannedMessageModule::getNextMessage()
|
|||||||
{
|
{
|
||||||
return this->messages[this->getNextIndex()];
|
return this->messages[this->getNextIndex()];
|
||||||
}
|
}
|
||||||
|
const char* CannedMessageModule::getNodeName(NodeNum node) {
|
||||||
|
if (node == NODENUM_BROADCAST){
|
||||||
|
return "Broadcast";
|
||||||
|
}else{
|
||||||
|
NodeInfo *info = nodeDB.getNode(node);
|
||||||
|
if(info != NULL) {
|
||||||
|
return info->user.long_name;
|
||||||
|
}else{
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool CannedMessageModule::shouldDraw()
|
bool CannedMessageModule::shouldDraw()
|
||||||
{
|
{
|
||||||
if (!moduleConfig.canned_message.enabled) {
|
if (!moduleConfig.canned_message.enabled) {
|
||||||
@ -386,11 +445,16 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
|||||||
}else if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {
|
}else if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
display->setFont(FONT_SMALL);
|
display->setFont(FONT_SMALL);
|
||||||
display->drawString(0 + x, 0 + y, "To: Broadcast");
|
if (this->destSelect) {
|
||||||
|
display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL);
|
||||||
|
display->setColor(BLACK);
|
||||||
|
}
|
||||||
|
char buffer[50];
|
||||||
|
display->drawStringf(0 + x, 0 + y, buffer, "To: %s", cannedMessageModule->getNodeName(this->dest));
|
||||||
// used chars right aligned
|
// used chars right aligned
|
||||||
char buffer[9];
|
|
||||||
sprintf(buffer, "%d left", Constants_DATA_PAYLOAD_LEN - this->freetext.length());
|
sprintf(buffer, "%d left", Constants_DATA_PAYLOAD_LEN - this->freetext.length());
|
||||||
display->drawString(x + display->getWidth() - display->getStringWidth(buffer), y + 0, buffer);
|
display->drawString(x + display->getWidth() - display->getStringWidth(buffer), y + 0, buffer);
|
||||||
|
display->setColor(WHITE);
|
||||||
display->drawStringMaxWidth(0 + x, 0 + y + FONT_HEIGHT_SMALL, x + display->getWidth(), cannedMessageModule->drawWithCursor(cannedMessageModule->freetext, cannedMessageModule->cursor));
|
display->drawStringMaxWidth(0 + x, 0 + y + FONT_HEIGHT_SMALL, x + display->getWidth(), cannedMessageModule->drawWithCursor(cannedMessageModule->freetext, cannedMessageModule->cursor));
|
||||||
} else {
|
} else {
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
|
@ -35,6 +35,7 @@ class CannedMessageModule :
|
|||||||
const char* getCurrentMessage();
|
const char* getCurrentMessage();
|
||||||
const char* getPrevMessage();
|
const char* getPrevMessage();
|
||||||
const char* getNextMessage();
|
const char* getNextMessage();
|
||||||
|
const char* getNodeName(NodeNum node);
|
||||||
bool shouldDraw();
|
bool shouldDraw();
|
||||||
void eventUp();
|
void eventUp();
|
||||||
void eventDown();
|
void eventDown();
|
||||||
|
Loading…
Reference in New Issue
Block a user