mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-20 01:32:40 +00:00
I don't like this formatting but I need trunk to STFU
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
#if HAS_SCREEN
|
||||
#include "CannedMessageModule.h"
|
||||
#include "FSCommon.h"
|
||||
#include "NodeDB.h"
|
||||
#include "MeshService.h"
|
||||
#include "NodeDB.h"
|
||||
#include "PowerFSM.h" // neede for button bypass
|
||||
#include "mesh/generated/meshtastic/cannedmessages.pb.h"
|
||||
|
||||
@@ -149,10 +149,10 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
|
||||
this->lastTouchMillis = 0;
|
||||
validEvent = true;
|
||||
}
|
||||
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_RIGHT))) {
|
||||
LOG_DEBUG("Canned message event (%x)\n",event->kbchar);
|
||||
LOG_DEBUG("Canned message event (%x)\n", event->kbchar);
|
||||
if (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {
|
||||
// pass the pressed key
|
||||
this->payload = event->kbchar;
|
||||
@@ -163,7 +163,8 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
|
||||
if (event->inputEvent == static_cast<char>(ANYKEY)) {
|
||||
LOG_DEBUG("Canned message event any key pressed\n");
|
||||
// when inactive, this will switch to the freetext mode
|
||||
if ((this->runState == CANNED_MESSAGE_RUN_STATE_INACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_DISABLED)) {
|
||||
if ((this->runState == CANNED_MESSAGE_RUN_STATE_INACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) ||
|
||||
(this->runState == CANNED_MESSAGE_RUN_STATE_DISABLED)) {
|
||||
this->runState = CANNED_MESSAGE_RUN_STATE_FREETEXT;
|
||||
}
|
||||
// pass the pressed key
|
||||
@@ -176,7 +177,7 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
|
||||
// this will send the text immediately on matrix press
|
||||
this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_SELECT;
|
||||
this->payload = MATRIXKEY;
|
||||
this->currentMessageIndex = event->kbchar -1;
|
||||
this->currentMessageIndex = event->kbchar - 1;
|
||||
this->lastTouchMillis = millis();
|
||||
validEvent = true;
|
||||
}
|
||||
@@ -224,7 +225,8 @@ int32_t CannedMessageModule::runOnce()
|
||||
this->cursor = 0;
|
||||
this->destSelect = false;
|
||||
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
|
||||
LOG_DEBUG("Reset due to lack of activity.\n");
|
||||
e.frameChanged = true;
|
||||
@@ -245,7 +247,7 @@ int32_t CannedMessageModule::runOnce()
|
||||
}
|
||||
} else {
|
||||
if ((this->messagesCount > this->currentMessageIndex) && (strlen(this->messages[this->currentMessageIndex]) > 0)) {
|
||||
if(strcmp (this->messages[this->currentMessageIndex], "~") == 0) {
|
||||
if (strcmp(this->messages[this->currentMessageIndex], "~") == 0) {
|
||||
powerFSM.trigger(EVENT_PRESS);
|
||||
return INT32_MAX;
|
||||
} else {
|
||||
@@ -264,7 +266,7 @@ int32_t CannedMessageModule::runOnce()
|
||||
this->destSelect = false;
|
||||
this->notifyObservers(&e);
|
||||
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)) {
|
||||
this->currentMessageIndex = 0;
|
||||
LOG_DEBUG("First touch (%d):%s\n", this->currentMessageIndex, this->getCurrentMessage());
|
||||
e.frameChanged = true;
|
||||
@@ -290,81 +292,81 @@ int32_t CannedMessageModule::runOnce()
|
||||
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {
|
||||
e.frameChanged = true;
|
||||
switch (this->payload) {
|
||||
case 0xb4: // left
|
||||
if (this->destSelect){
|
||||
size_t numNodes = nodeDB.getNumNodes();
|
||||
if(this->dest == NODENUM_BROADCAST) {
|
||||
this->dest = nodeDB.getNodeNum();
|
||||
}
|
||||
for (unsigned int i = 0; i < numNodes; i++) {
|
||||
if (nodeDB.getNodeByIndex(i)->num == this->dest) {
|
||||
this->dest = (i > 0) ? nodeDB.getNodeByIndex(i-1)->num : nodeDB.getNodeByIndex(numNodes-1)->num;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(this->dest == nodeDB.getNodeNum()) {
|
||||
this->dest = NODENUM_BROADCAST;
|
||||
}
|
||||
}else{
|
||||
if (this->cursor > 0) {
|
||||
this->cursor--;
|
||||
case 0xb4: // left
|
||||
if (this->destSelect) {
|
||||
size_t numNodes = nodeDB.getNumNodes();
|
||||
if (this->dest == NODENUM_BROADCAST) {
|
||||
this->dest = nodeDB.getNodeNum();
|
||||
}
|
||||
for (unsigned int i = 0; i < numNodes; i++) {
|
||||
if (nodeDB.getNodeByIndex(i)->num == this->dest) {
|
||||
this->dest = (i > 0) ? nodeDB.getNodeByIndex(i - 1)->num : nodeDB.getNodeByIndex(numNodes - 1)->num;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0xb7: // right
|
||||
if (this->destSelect){
|
||||
size_t numNodes = nodeDB.getNumNodes();
|
||||
if(this->dest == NODENUM_BROADCAST) {
|
||||
this->dest = nodeDB.getNodeNum();
|
||||
}
|
||||
for (unsigned int i = 0; i < numNodes; i++) {
|
||||
if (nodeDB.getNodeByIndex(i)->num == this->dest) {
|
||||
this->dest = (i < numNodes-1) ? nodeDB.getNodeByIndex(i+1)->num : nodeDB.getNodeByIndex(0)->num;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(this->dest == nodeDB.getNodeNum()) {
|
||||
this->dest = NODENUM_BROADCAST;
|
||||
}
|
||||
}else{
|
||||
if (this->cursor < this->freetext.length()) {
|
||||
this->cursor++;
|
||||
}
|
||||
if (this->dest == nodeDB.getNodeNum()) {
|
||||
this->dest = NODENUM_BROADCAST;
|
||||
}
|
||||
break;
|
||||
case 0x08: // backspace
|
||||
if (this->freetext.length() > 0) {
|
||||
if(this->cursor == this->freetext.length()) {
|
||||
this->freetext = this->freetext.substring(0, this->freetext.length() - 1);
|
||||
} else {
|
||||
this->freetext = this->freetext.substring(0, this->cursor - 1) + this->freetext.substring(this->cursor, this->freetext.length());
|
||||
}
|
||||
} else {
|
||||
if (this->cursor > 0) {
|
||||
this->cursor--;
|
||||
}
|
||||
break;
|
||||
case 0x09: // tab
|
||||
if(this->destSelect) {
|
||||
this->destSelect = false;
|
||||
}
|
||||
break;
|
||||
case 0xb7: // right
|
||||
if (this->destSelect) {
|
||||
size_t numNodes = nodeDB.getNumNodes();
|
||||
if (this->dest == NODENUM_BROADCAST) {
|
||||
this->dest = nodeDB.getNodeNum();
|
||||
}
|
||||
for (unsigned int i = 0; i < numNodes; i++) {
|
||||
if (nodeDB.getNodeByIndex(i)->num == this->dest) {
|
||||
this->dest = (i < numNodes - 1) ? nodeDB.getNodeByIndex(i + 1)->num : nodeDB.getNodeByIndex(0)->num;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this->dest == nodeDB.getNodeNum()) {
|
||||
this->dest = NODENUM_BROADCAST;
|
||||
}
|
||||
} else {
|
||||
if (this->cursor < this->freetext.length()) {
|
||||
this->cursor++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0x08: // backspace
|
||||
if (this->freetext.length() > 0) {
|
||||
if (this->cursor == this->freetext.length()) {
|
||||
this->freetext = this->freetext.substring(0, this->freetext.length() - 1);
|
||||
} else {
|
||||
this->destSelect = true;
|
||||
this->freetext = this->freetext.substring(0, this->cursor - 1) +
|
||||
this->freetext.substring(this->cursor, this->freetext.length());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if(this->cursor == this->freetext.length()) {
|
||||
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;
|
||||
this->cursor--;
|
||||
}
|
||||
break;
|
||||
case 0x09: // tab
|
||||
if (this->destSelect) {
|
||||
this->destSelect = false;
|
||||
} else {
|
||||
this->destSelect = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (this->cursor == this->freetext.length()) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
this->lastTouchMillis = millis();
|
||||
this->notifyObservers(&e);
|
||||
return INACTIVATE_AFTER_MS;
|
||||
@@ -376,7 +378,7 @@ int32_t CannedMessageModule::runOnce()
|
||||
return INACTIVATE_AFTER_MS;
|
||||
}
|
||||
|
||||
return INT32_MAX;
|
||||
return INT32_MAX;
|
||||
}
|
||||
|
||||
const char *CannedMessageModule::getCurrentMessage()
|
||||
@@ -391,14 +393,15 @@ const char *CannedMessageModule::getNextMessage()
|
||||
{
|
||||
return this->messages[this->getNextIndex()];
|
||||
}
|
||||
const char* CannedMessageModule::getNodeName(NodeNum node) {
|
||||
if (node == NODENUM_BROADCAST){
|
||||
const char *CannedMessageModule::getNodeName(NodeNum node)
|
||||
{
|
||||
if (node == NODENUM_BROADCAST) {
|
||||
return "Broadcast";
|
||||
}else{
|
||||
} else {
|
||||
NodeInfo *info = nodeDB.getNode(node);
|
||||
if(info != NULL) {
|
||||
if (info != NULL) {
|
||||
return info->user.long_name;
|
||||
}else{
|
||||
} else {
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
@@ -444,7 +447,7 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display->setFont(FONT_SMALL);
|
||||
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->setFont(FONT_SMALL);
|
||||
if (this->destSelect) {
|
||||
@@ -460,7 +463,9 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
||||
display->drawString(x + display->getWidth() - display->getStringWidth(buffer) - 1, 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 {
|
||||
if (this->messagesCount > 0) {
|
||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
@@ -479,7 +484,7 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
||||
void CannedMessageModule::loadProtoForModule()
|
||||
{
|
||||
if (!nodeDB.loadProto(cannedMessagesConfigFile, CannedMessageModuleConfig_size, sizeof(CannedMessageModuleConfig),
|
||||
&CannedMessageModuleConfig_msg, &cannedMessageModuleConfig)) {
|
||||
&CannedMessageModuleConfig_msg, &cannedMessageModuleConfig)) {
|
||||
installDefaultCannedMessageModuleConfig();
|
||||
}
|
||||
}
|
||||
@@ -498,8 +503,8 @@ bool CannedMessageModule::saveProtoForModule()
|
||||
FS.mkdir("/prefs");
|
||||
#endif
|
||||
|
||||
okay &= nodeDB.saveProto(cannedMessagesConfigFile, CannedMessageModuleConfig_size,
|
||||
&CannedMessageModuleConfig_msg, &cannedMessageModuleConfig);
|
||||
okay &= nodeDB.saveProto(cannedMessagesConfigFile, CannedMessageModuleConfig_size, &CannedMessageModuleConfig_msg,
|
||||
&cannedMessageModuleConfig);
|
||||
|
||||
return okay;
|
||||
}
|
||||
@@ -549,13 +554,13 @@ AdminMessageHandleResult CannedMessageModule::handleAdminMessageForModule(const
|
||||
void CannedMessageModule::handleGetCannedMessageModuleMessages(const MeshPacket &req, AdminMessage *response)
|
||||
{
|
||||
LOG_DEBUG("*** handleGetCannedMessageModuleMessages\n");
|
||||
if(req.decoded.want_response) {
|
||||
if (req.decoded.want_response) {
|
||||
response->which_payload_variant = AdminMessage_get_canned_message_module_messages_response_tag;
|
||||
strncpy(response->get_canned_message_module_messages_response, cannedMessageModuleConfig.messages, sizeof(response->get_canned_message_module_messages_response));
|
||||
strncpy(response->get_canned_message_module_messages_response, cannedMessageModuleConfig.messages,
|
||||
sizeof(response->get_canned_message_module_messages_response));
|
||||
} // Don't send anything if not instructed to. Better than asserting.
|
||||
}
|
||||
|
||||
|
||||
void CannedMessageModule::handleSetCannedMessageModuleMessages(const char *from_msg)
|
||||
{
|
||||
int changed = 0;
|
||||
@@ -573,9 +578,7 @@ void CannedMessageModule::handleSetCannedMessageModuleMessages(const char *from_
|
||||
|
||||
String CannedMessageModule::drawWithCursor(String text, int cursor)
|
||||
{
|
||||
String result = text.substring(0, cursor)
|
||||
+ "_"
|
||||
+ text.substring(cursor);
|
||||
String result = text.substring(0, cursor) + "_" + text.substring(cursor);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user