Adding screen frame

This commit is contained in:
Balazs Kelemen
2022-01-04 19:43:06 +01:00
parent 2b588f1567
commit 7b8849493f
4 changed files with 118 additions and 20 deletions

View File

@@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "mesh-pb-constants.h"
#include "mesh/Channels.h"
#include "plugins/TextMessagePlugin.h"
#include "plugins/CannedMessagePlugin.h"
#include "sleep.h"
#include "target_specific.h"
#include "utils.h"
@@ -285,6 +286,21 @@ static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state
display->drawStringMaxWidth(4 + x, 10 + y, SCREEN_WIDTH - (6 + x), tempBuf);
}
static void drawCannedMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
displayedNodeNum = 0; // Not currently showing a node pane
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(FONT_MEDIUM);
display->drawString(0 + x, 0 + y, cannedMessagePlugin->getCurrentSelection());
// the max length of this buffer is much longer than we can possibly print
// static char tempBuf[96];
// snprintf(tempBuf, sizeof(tempBuf), " %s", mp.decoded.payload.bytes);
// display->drawStringMaxWidth(4 + x, 10 + y, SCREEN_WIDTH - (6 + x), tempBuf);
}
/// Draw a series of fields in a column, wrapping to multiple colums if needed
static void drawColumns(OLEDDisplay *display, int16_t x, int16_t y, const char **fields)
{
@@ -820,6 +836,8 @@ void Screen::setup()
nodeStatusObserver.observe(&nodeStatus->onNewStatus);
if (textMessagePlugin)
textMessageObserver.observe(textMessagePlugin);
if (cannedMessagePlugin)
cannedMessageObserver.observe(cannedMessagePlugin);
}
void Screen::forceDisplay()
@@ -996,6 +1014,9 @@ void Screen::setFrames()
if (devicestate.has_rx_text_message && shouldDrawMessage(&devicestate.rx_text_message)) {
normalFrames[numframes++] = drawTextMessageFrame;
}
if (cannedMessagePlugin->shouldDraw()) {
normalFrames[numframes++] = drawCannedMessageFrame;
}
// then all the nodes
// We only show a few nodes in our scrolling list - because meshes with many nodes would have too many screens
@@ -1457,4 +1478,14 @@ int Screen::handleTextMessage(const MeshPacket *packet)
return 0;
}
int Screen::handleCannedMessage(const meshtastic::Status *packet)
{
if (showingNormalScreen) {
setFrames(); // Regen the list of screens (will show new text message)
}
ui.switchToFrame(1);
return 0;
}
} // namespace graphics