mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-17 18:42:10 +00:00
Reset plugin in case of inactivity.
This commit is contained in:
parent
c5b95ed3c0
commit
33f08364e4
@ -2,13 +2,13 @@
|
|||||||
#include "CannedMessagePlugin.h"
|
#include "CannedMessagePlugin.h"
|
||||||
#include "MeshService.h"
|
#include "MeshService.h"
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
// TODO: reuse defined from Screen.cpp
|
// TODO: reuse defined from Screen.cpp
|
||||||
#define FONT_SMALL ArialMT_Plain_10
|
#define FONT_SMALL ArialMT_Plain_10
|
||||||
#define FONT_MEDIUM ArialMT_Plain_16
|
#define FONT_MEDIUM ArialMT_Plain_16
|
||||||
#define FONT_LARGE ArialMT_Plain_24
|
#define FONT_LARGE ArialMT_Plain_24
|
||||||
|
|
||||||
|
// Remove Canned message screen if no action is taken for some milliseconds
|
||||||
|
#define INACTIVATE_AFTER_MS 20000
|
||||||
|
|
||||||
CannedMessagePlugin *cannedMessagePlugin;
|
CannedMessagePlugin *cannedMessagePlugin;
|
||||||
|
|
||||||
@ -38,8 +38,10 @@ int CannedMessagePlugin::splitConfiguredMessages()
|
|||||||
{
|
{
|
||||||
int messageIndex = 0;
|
int messageIndex = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
this->messages[messageIndex++] = radioConfig.preferences.canned_message_plugin_messages;
|
this->messages[messageIndex++] =
|
||||||
int upTo = strlen(radioConfig.preferences.canned_message_plugin_messages) - 1;
|
radioConfig.preferences.canned_message_plugin_messages;
|
||||||
|
int upTo =
|
||||||
|
strlen(radioConfig.preferences.canned_message_plugin_messages) - 1;
|
||||||
|
|
||||||
while (i < upTo)
|
while (i < upTo)
|
||||||
{
|
{
|
||||||
@ -47,7 +49,8 @@ int CannedMessagePlugin::splitConfiguredMessages()
|
|||||||
{
|
{
|
||||||
// Message ending found, replace it with string-end character.
|
// Message ending found, replace it with string-end character.
|
||||||
radioConfig.preferences.canned_message_plugin_messages[i] = '\0';
|
radioConfig.preferences.canned_message_plugin_messages[i] = '\0';
|
||||||
DEBUG_MSG("CannedMessage %d is: '%s'\n", messageIndex-1, this->messages[messageIndex-1]);
|
DEBUG_MSG("CannedMessage %d is: '%s'\n",
|
||||||
|
messageIndex-1, this->messages[messageIndex-1]);
|
||||||
|
|
||||||
if (messageIndex >= CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_COUNT)
|
if (messageIndex >= CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_COUNT)
|
||||||
{
|
{
|
||||||
@ -63,7 +66,8 @@ int CannedMessagePlugin::splitConfiguredMessages()
|
|||||||
}
|
}
|
||||||
if (strlen(this->messages[messageIndex-1]) > 0)
|
if (strlen(this->messages[messageIndex-1]) > 0)
|
||||||
{
|
{
|
||||||
DEBUG_MSG("CannedMessage %d is: '%s'\n", messageIndex-1, this->messages[messageIndex-1]);
|
DEBUG_MSG("CannedMessage %d is: '%s'\n",
|
||||||
|
messageIndex-1, this->messages[messageIndex-1]);
|
||||||
this->messagesCount = messageIndex;
|
this->messagesCount = messageIndex;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -108,8 +112,7 @@ int CannedMessagePlugin::handleInputEvent(const InputEvent *event)
|
|||||||
if (validEvent)
|
if (validEvent)
|
||||||
{
|
{
|
||||||
// Let runOnce to be called immediately.
|
// Let runOnce to be called immediately.
|
||||||
runned(millis());
|
setIntervalFromNow(0);
|
||||||
setInterval(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -121,6 +124,7 @@ void CannedMessagePlugin::sendText(NodeNum dest,
|
|||||||
{
|
{
|
||||||
MeshPacket *p = allocDataPacket();
|
MeshPacket *p = allocDataPacket();
|
||||||
p->to = dest;
|
p->to = dest;
|
||||||
|
p->want_ack = true;
|
||||||
p->decoded.payload.size = strlen(message);
|
p->decoded.payload.size = strlen(message);
|
||||||
memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size);
|
memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size);
|
||||||
if (radioConfig.preferences.canned_message_plugin_send_bell)
|
if (radioConfig.preferences.canned_message_plugin_send_bell)
|
||||||
@ -151,6 +155,7 @@ int32_t CannedMessagePlugin::runOnce()
|
|||||||
{
|
{
|
||||||
// TODO: might have some feedback of sendig state
|
// TODO: might have some feedback of sendig state
|
||||||
this->sendingState = SENDING_STATE_NONE;
|
this->sendingState = SENDING_STATE_NONE;
|
||||||
|
e.frameChanged = true;
|
||||||
this->notifyObservers(&e);
|
this->notifyObservers(&e);
|
||||||
}
|
}
|
||||||
else if ((this->action != CANNED_MESSAGE_ACTION_NONE)
|
else if ((this->action != CANNED_MESSAGE_ACTION_NONE)
|
||||||
@ -183,8 +188,19 @@ int32_t CannedMessagePlugin::runOnce()
|
|||||||
}
|
}
|
||||||
if (this->action != CANNED_MESSAGE_ACTION_NONE)
|
if (this->action != CANNED_MESSAGE_ACTION_NONE)
|
||||||
{
|
{
|
||||||
|
this->lastTouchMillis = millis();
|
||||||
this->action = CANNED_MESSAGE_ACTION_NONE;
|
this->action = CANNED_MESSAGE_ACTION_NONE;
|
||||||
this->notifyObservers(&e);
|
this->notifyObservers(&e);
|
||||||
|
return INACTIVATE_AFTER_MS;
|
||||||
|
}
|
||||||
|
if ((millis() - this->lastTouchMillis) > INACTIVATE_AFTER_MS)
|
||||||
|
{
|
||||||
|
// Reset plugin
|
||||||
|
DEBUG_MSG("Reset due the lack of activity.\n");
|
||||||
|
e.frameChanged = true;
|
||||||
|
this->currentMessageIndex = -1;
|
||||||
|
this->sendingState = SENDING_STATE_NONE;
|
||||||
|
this->notifyObservers(&e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 30000; // TODO: should return MAX_VAL
|
return 30000; // TODO: should return MAX_VAL
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <OLEDDisplay.h>
|
|
||||||
#include "SinglePortPlugin.h"
|
#include "SinglePortPlugin.h"
|
||||||
#include "input/InputBroker.h"
|
#include "input/InputBroker.h"
|
||||||
|
|
||||||
@ -41,7 +40,7 @@ class CannedMessagePlugin :
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual int32_t runOnce();
|
virtual int32_t runOnce();
|
||||||
|
|
||||||
void sendText(
|
void sendText(
|
||||||
NodeNum dest,
|
NodeNum dest,
|
||||||
@ -64,6 +63,7 @@ class CannedMessagePlugin :
|
|||||||
|
|
||||||
char *messages[CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_COUNT];
|
char *messages[CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_COUNT];
|
||||||
int messagesCount = 0;
|
int messagesCount = 0;
|
||||||
|
unsigned long lastTouchMillis = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern CannedMessagePlugin *cannedMessagePlugin;
|
extern CannedMessagePlugin *cannedMessagePlugin;
|
||||||
|
@ -72,8 +72,7 @@ int32_t RotaryEncoderInterruptBase::runOnce()
|
|||||||
void RotaryEncoderInterruptBase::intPressHandler()
|
void RotaryEncoderInterruptBase::intPressHandler()
|
||||||
{
|
{
|
||||||
this->action = ROTARY_ACTION_PRESSED;
|
this->action = ROTARY_ACTION_PRESSED;
|
||||||
runned(millis());
|
setIntervalFromNow(20); // TODO: this modifies a non-volatile variable!
|
||||||
setInterval(20); // TODO: this modifies a non-volatile variable!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotaryEncoderInterruptBase::intAHandler()
|
void RotaryEncoderInterruptBase::intAHandler()
|
||||||
@ -143,8 +142,7 @@ RotaryEncoderInterruptBaseStateType RotaryEncoderInterruptBase::intHandler(
|
|||||||
// Logic to prevent bouncing.
|
// Logic to prevent bouncing.
|
||||||
newState = ROTARY_EVENT_CLEARED;
|
newState = ROTARY_EVENT_CLEARED;
|
||||||
}
|
}
|
||||||
runned(millis());
|
setIntervalFromNow(50); // TODO: this modifies a non-volatile variable!
|
||||||
setInterval(50); // TODO: this modifies a non-volatile variable!
|
|
||||||
|
|
||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user