mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-30 19:29:17 +00:00
Cursor editing
This commit is contained in:
parent
d0ad5dd4cf
commit
0a8293a2d6
@ -117,6 +117,7 @@ static uint16_t displayWidth, displayHeight;
|
|||||||
|
|
||||||
#define FONT_HEIGHT_SMALL fontHeight(FONT_SMALL)
|
#define FONT_HEIGHT_SMALL fontHeight(FONT_SMALL)
|
||||||
#define FONT_HEIGHT_MEDIUM fontHeight(FONT_MEDIUM)
|
#define FONT_HEIGHT_MEDIUM fontHeight(FONT_MEDIUM)
|
||||||
|
#define FONT_HEIGHT_LARGE fontHeight(FONT_LARGE)
|
||||||
|
|
||||||
#define getStringCenteredX(s) ((SCREEN_WIDTH - display->getStringWidth(s)) / 2)
|
#define getStringCenteredX(s) ((SCREEN_WIDTH - display->getStringWidth(s)) / 2)
|
||||||
|
|
||||||
|
@ -6,10 +6,26 @@
|
|||||||
#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"
|
||||||
|
|
||||||
// TODO: reuse defined from Screen.cpp
|
#if defined(USE_EINK) || defined(ILI9341_DRIVER)
|
||||||
|
// The screen is bigger so use bigger fonts
|
||||||
|
#define FONT_SMALL ArialMT_Plain_16
|
||||||
|
#define FONT_MEDIUM ArialMT_Plain_24
|
||||||
|
#define FONT_LARGE ArialMT_Plain_24
|
||||||
|
#else
|
||||||
|
#ifdef OLED_RU
|
||||||
|
#define FONT_SMALL ArialMT_Plain_10_RU
|
||||||
|
#else
|
||||||
#define FONT_SMALL ArialMT_Plain_10
|
#define FONT_SMALL ArialMT_Plain_10
|
||||||
|
#endif
|
||||||
#define FONT_MEDIUM ArialMT_Plain_16
|
#define FONT_MEDIUM ArialMT_Plain_16
|
||||||
#define FONT_LARGE ArialMT_Plain_24
|
#define FONT_LARGE ArialMT_Plain_24
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define fontHeight(font) ((font)[1] + 1) // height is position 1
|
||||||
|
|
||||||
|
#define FONT_HEIGHT_SMALL fontHeight(FONT_SMALL)
|
||||||
|
#define FONT_HEIGHT_MEDIUM fontHeight(FONT_MEDIUM)
|
||||||
|
#define FONT_HEIGHT_LARGE fontHeight(FONT_LARGE)
|
||||||
|
|
||||||
// Remove Canned message screen if no action is taken for some milliseconds
|
// Remove Canned message screen if no action is taken for some milliseconds
|
||||||
#define INACTIVATE_AFTER_MS 20000
|
#define INACTIVATE_AFTER_MS 20000
|
||||||
@ -130,7 +146,7 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
|
|||||||
if ((event->inputEvent == static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_BACK)) ||
|
if ((event->inputEvent == static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_BACK)) ||
|
||||||
(event->inputEvent == static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_LEFT)) ||
|
(event->inputEvent == static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_LEFT)) ||
|
||||||
(event->inputEvent == static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT))) {
|
(event->inputEvent == static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT))) {
|
||||||
DEBUG_MSG("Canned message event (back/left/right)\n");
|
DEBUG_MSG("Canned message event (%x)\n",event->kbchar);
|
||||||
if (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {
|
if (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {
|
||||||
// pass the pressed key
|
// pass the pressed key
|
||||||
this->payload = event->kbchar;
|
this->payload = event->kbchar;
|
||||||
@ -191,6 +207,7 @@ int32_t CannedMessageModule::runOnce()
|
|||||||
e.frameChanged = true;
|
e.frameChanged = true;
|
||||||
this->currentMessageIndex = -1;
|
this->currentMessageIndex = -1;
|
||||||
this->freetext = ""; // clear freetext
|
this->freetext = ""; // clear freetext
|
||||||
|
this->cursor = 0;
|
||||||
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
|
||||||
@ -198,6 +215,7 @@ int32_t CannedMessageModule::runOnce()
|
|||||||
e.frameChanged = true;
|
e.frameChanged = true;
|
||||||
this->currentMessageIndex = -1;
|
this->currentMessageIndex = -1;
|
||||||
this->freetext = ""; // clear freetext
|
this->freetext = ""; // clear freetext
|
||||||
|
this->cursor = 0;
|
||||||
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) {
|
||||||
@ -209,6 +227,7 @@ int32_t CannedMessageModule::runOnce()
|
|||||||
this->runState = CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE;
|
this->runState = CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE;
|
||||||
this->currentMessageIndex = -1;
|
this->currentMessageIndex = -1;
|
||||||
this->freetext = ""; // clear freetext
|
this->freetext = ""; // clear freetext
|
||||||
|
this->cursor = 0;
|
||||||
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)) {
|
||||||
@ -219,23 +238,48 @@ int32_t CannedMessageModule::runOnce()
|
|||||||
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_UP) {
|
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_UP) {
|
||||||
this->currentMessageIndex = getPrevIndex();
|
this->currentMessageIndex = getPrevIndex();
|
||||||
this->freetext = ""; // clear freetext
|
this->freetext = ""; // clear freetext
|
||||||
|
this->cursor = 0;
|
||||||
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->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) {
|
||||||
|
DEBUG_MSG("KEYSTROKE (%d):%x\n", this->cursor, this->payload);
|
||||||
e.frameChanged = true;
|
e.frameChanged = true;
|
||||||
switch (this->payload) {
|
switch (this->payload) {
|
||||||
|
case 0xb4: // left
|
||||||
|
if (this->cursor > 0) {
|
||||||
|
this->cursor--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 0xb7: // right
|
||||||
|
if (this->cursor < this->freetext.length()) {
|
||||||
|
this->cursor++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 8: // backspace
|
case 8: // backspace
|
||||||
if (this->freetext.length() > 0) {
|
if (this->freetext.length() > 0) {
|
||||||
this->freetext = this->freetext.substring(0, this->freetext.length() - 1);
|
this->freetext = this->freetext.substring(0, this->freetext.length() - 1);
|
||||||
|
this->cursor--;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
if(this->cursor == this->freetext.length()) {
|
||||||
this->freetext += this->payload;
|
this->freetext += this->payload;
|
||||||
|
} else {
|
||||||
|
this->freetext = this->freetext.substring(0, this->cursor)
|
||||||
|
+ this->payload
|
||||||
|
+ this->freetext.substring(this->cursor);
|
||||||
|
}
|
||||||
|
this->cursor += 1;
|
||||||
|
if (this->freetext.length() > Constants_DATA_PAYLOAD_LEN) {
|
||||||
|
this->cursor = Constants_DATA_PAYLOAD_LEN;
|
||||||
|
this->freetext = this->freetext.substring(0, Constants_DATA_PAYLOAD_LEN);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,20 +346,24 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
|||||||
} else if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_DISABLED) {
|
} else if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_DISABLED) {
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
display->setFont(FONT_SMALL);
|
display->setFont(FONT_SMALL);
|
||||||
display->drawString(10 + x, 0 + y + 16, "Canned Message\nModule disabled.");
|
display->drawString(10 + x, 0 + y + FONT_HEIGHT_SMALL, "Canned Message\nModule disabled.");
|
||||||
}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_MEDIUM);
|
display->setFont(FONT_MEDIUM);
|
||||||
display->drawString(0 + x, 0 + y, "To: Broadcast");
|
display->drawString(0 + x, 0 + y, "To: Broadcast");
|
||||||
display->drawString(0 + x, 0 + y + 16, this->freetext);
|
// used chars right aligned
|
||||||
|
char buffer[9];
|
||||||
|
sprintf(buffer, "%d left", Constants_DATA_PAYLOAD_LEN - this->freetext.length());
|
||||||
|
display->drawString(x + display->getWidth() - display->getStringWidth(buffer), y + 0, buffer);
|
||||||
|
display->drawString(0 + x, 0 + y + FONT_HEIGHT_MEDIUM, cannedMessageModule->drawWithCursor(cannedMessageModule->freetext, cannedMessageModule->cursor));
|
||||||
} else {
|
} else {
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
display->setFont(FONT_SMALL);
|
display->setFont(FONT_SMALL);
|
||||||
display->drawString(0 + x, 0 + y, cannedMessageModule->getPrevMessage());
|
display->drawString(0 + x, 0 + y, cannedMessageModule->getPrevMessage());
|
||||||
display->setFont(FONT_MEDIUM);
|
display->setFont(FONT_MEDIUM);
|
||||||
display->drawString(0 + x, 0 + y + 8, cannedMessageModule->getCurrentMessage());
|
display->drawString(0 + x, 0 + y + FONT_HEIGHT_SMALL, cannedMessageModule->getCurrentMessage());
|
||||||
display->setFont(FONT_SMALL);
|
display->setFont(FONT_SMALL);
|
||||||
display->drawString(0 + x, 0 + y + 24, cannedMessageModule->getNextMessage());
|
display->drawString(0 + x, 0 + y + FONT_HEIGHT_MEDIUM, cannedMessageModule->getNextMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,4 +462,12 @@ void CannedMessageModule::handleSetCannedMessageModuleMessages(const char *from_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String CannedMessageModule::drawWithCursor(String text, int cursor)
|
||||||
|
{
|
||||||
|
String result = text.substring(0, cursor)
|
||||||
|
+ "_"
|
||||||
|
+ text.substring(cursor);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -43,6 +43,8 @@ class CannedMessageModule :
|
|||||||
void handleGetCannedMessageModuleMessages(const MeshPacket &req, AdminMessage *response);
|
void handleGetCannedMessageModuleMessages(const MeshPacket &req, AdminMessage *response);
|
||||||
void handleSetCannedMessageModuleMessages(const char *from_msg);
|
void handleSetCannedMessageModuleMessages(const char *from_msg);
|
||||||
|
|
||||||
|
String drawWithCursor(String text, int cursor);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual int32_t runOnce() override;
|
virtual int32_t runOnce() override;
|
||||||
@ -72,7 +74,8 @@ class CannedMessageModule :
|
|||||||
int currentMessageIndex = -1;
|
int currentMessageIndex = -1;
|
||||||
cannedMessageModuleRunState runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
|
cannedMessageModuleRunState runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
|
||||||
char payload;
|
char payload;
|
||||||
String freetext; // Text Buffer for Freetext Editor
|
int cursor = 0;
|
||||||
|
String freetext = ""; // Text Buffer for Freetext Editor
|
||||||
|
|
||||||
char messageStore[CANNED_MESSAGE_MODULE_MESSAGES_SIZE+1];
|
char messageStore[CANNED_MESSAGE_MODULE_MESSAGES_SIZE+1];
|
||||||
char *messages[CANNED_MESSAGE_MODULE_MESSAGE_MAX_COUNT];
|
char *messages[CANNED_MESSAGE_MODULE_MESSAGE_MAX_COUNT];
|
||||||
|
Loading…
Reference in New Issue
Block a user