Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canned message usability improvements #4437

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
11 changes: 10 additions & 1 deletion src/graphics/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "mesh/generated/meshtastic/deviceonly.pb.h"
#include "meshUtils.h"
#include "modules/AdminModule.h"
#include "modules/CannedMessageModule.h"
#include "modules/ExternalNotificationModule.h"
#include "modules/TextMessageModule.h"
#include "sleep.h"
Expand Down Expand Up @@ -2314,9 +2315,17 @@ void Screen::handleOnPress()
{
// If Canned Messages is using the "Scan and Select" input, dismiss the canned message frame when user button is pressed
// Minimize impact as a courtesy, as "scan and select" may be used as default config for some boards
if (scanAndSelectInput != nullptr && scanAndSelectInput->dismissCannedMessageFrame())
// (Fall-through if using auto carousel, to prevent unexpected closing of canned message frame)
if (scanAndSelectInput != nullptr && !config.display.auto_screen_carousel_secs &&
scanAndSelectInput->dismissCannedMessageFrame())
return;
robertfisk marked this conversation as resolved.
Show resolved Hide resolved

// Don't transition away from canned messages if it is active
if (cannedMessageModule->shouldDraw()) {
lastScreenTransition = millis();
return;
}

todd-herbert marked this conversation as resolved.
Show resolved Hide resolved
// If screen was off, just wake it, otherwise advance to next frame
// If we are in a transition, the press must have bounced, drop it.
if (ui->getUiState()->frameState == FIXED) {
Expand Down
40 changes: 12 additions & 28 deletions src/modules/CannedMessageModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,9 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
if (validEvent) {
requestFocus(); // Tell Screen::setFrames to move to our module's frame, next time it runs

// Let runOnce to be called immediately.
if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_SELECT) {
setIntervalFromNow(0); // on fast keypresses, this isn't fast enough.
} else {
runOnce();
}
// Run CannedMessageModule thread now from callee thread context,
// and also schedule it to run later in its own context with the requested delay.
setIntervalFromNow(runOnce());
}

return 0;
Expand Down Expand Up @@ -409,25 +406,18 @@ int32_t CannedMessageModule::runOnce()
if ((this->runState == CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE) ||
(this->runState == CANNED_MESSAGE_RUN_STATE_ACK_NACK_RECEIVED) || (this->runState == CANNED_MESSAGE_RUN_STATE_MESSAGE)) {
// TODO: might have some feedback of sending state
this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
if (this->runState == CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE) {
this->restoreOldState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
}
this->runState = this->restoreOldState;
temporaryMessage = "";
e.action = UIFrameEvent::Action::REGENERATE_FRAMESET; // We want to change the list of frames shown on-screen
this->currentMessageIndex = -1;
this->freetext = ""; // clear freetext
this->cursor = 0;

#if !defined(T_WATCH_S3) && !defined(RAK14014)
this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE;
#endif

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)) {
// Reset module
((millis() - this->lastTouchMillis) >= INACTIVATE_AFTER_MS)) {
// Don't reset module, just hide the frame
e.action = UIFrameEvent::Action::REGENERATE_FRAMESET; // We want to change the list of frames shown on-screen
this->currentMessageIndex = -1;
this->freetext = ""; // clear freetext
this->cursor = 0;

#if !defined(T_WATCH_S3) && !defined(RAK14014)
this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE;
Expand Down Expand Up @@ -480,8 +470,6 @@ int32_t CannedMessageModule::runOnce()
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_UP) {
if (this->messagesCount > 0) {
this->currentMessageIndex = getPrevIndex();
this->freetext = ""; // clear freetext
this->cursor = 0;

#if !defined(T_WATCH_S3) && !defined(RAK14014)
this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE;
Expand All @@ -493,8 +481,6 @@ int32_t CannedMessageModule::runOnce()
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_DOWN) {
if (this->messagesCount > 0) {
this->currentMessageIndex = this->getNextIndex();
this->freetext = ""; // clear freetext
this->cursor = 0;

#if !defined(T_WATCH_S3) && !defined(RAK14014)
this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE;
Expand Down Expand Up @@ -644,13 +630,9 @@ int32_t CannedMessageModule::runOnce()
if (screen)
screen->removeFunctionSymbal("Fn");
}

this->lastTouchMillis = millis();
this->notifyObservers(&e);
return INACTIVATE_AFTER_MS;
}

if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) {
if (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT || this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) {
this->lastTouchMillis = millis();
this->notifyObservers(&e);
return INACTIVATE_AFTER_MS;
Expand Down Expand Up @@ -734,6 +716,7 @@ void CannedMessageModule::showTemporaryMessage(const String &message)
UIFrameEvent e;
e.action = UIFrameEvent::Action::REGENERATE_FRAMESET; // We want to change the list of frames shown on-screen
notifyObservers(&e);
this->restoreOldState = this->runState;
runState = CANNED_MESSAGE_RUN_STATE_MESSAGE;
// run this loop again in 2 seconds, next iteration will clear the display
setIntervalFromNow(2000);
Expand Down Expand Up @@ -1101,6 +1084,7 @@ ProcessMessage CannedMessageModule::handleReceived(const meshtastic_MeshPacket &
UIFrameEvent e;
e.action = UIFrameEvent::Action::REGENERATE_FRAMESET; // We want to change the list of frames shown on-screen
requestFocus(); // Tell Screen::setFrames that our module's frame should be shown, even if not "first" in the frameset
this->restoreOldState = this->runState;
this->runState = CANNED_MESSAGE_RUN_STATE_ACK_NACK_RECEIVED;
this->incoming = service->getNodenumFromRequestId(mp.decoded.request_id);
meshtastic_Routing decoded = meshtastic_Routing_init_default;
Expand Down
1 change: 1 addition & 0 deletions src/modules/CannedMessageModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class CannedMessageModule : public SinglePortModule, public Observable<const UIF

int currentMessageIndex = -1;
cannedMessageModuleRunState runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
cannedMessageModuleRunState restoreOldState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
char payload = 0x00;
unsigned int cursor = 0;
String freetext = ""; // Text Buffer for Freetext Editor
Expand Down
Loading