Add MeshPocket message board and worldwide map
This commit is contained in:
1 parent
7d0709bf03
commit
5d31a839c5
41 files changed
+6852
-7
No files matched your search
@@ -6,6 +6,7 @@
|
||||
#include <helpers/SensorManager.h>
|
||||
#include <helpers/MultiSerialInterface.h>
|
||||
#include <Arduino.h>
|
||||
#include <helpers/ui/PocketGuiConfig.h>
|
||||
|
||||
#ifdef PIN_BUZZER
|
||||
#include <helpers/ui/buzzer.h>
|
||||
@@ -100,6 +101,12 @@ public:
|
||||
int channel_idx = -1,
|
||||
const char* channel_name = nullptr,
|
||||
int queue_index = -1) = 0;
|
||||
#if UI_POCKET_GUI
|
||||
virtual void channelMessageSent(int channel_idx, const char* channel_name,
|
||||
const char* sender, const char* text, size_t length) {
|
||||
(void)channel_idx; (void)channel_name; (void)sender; (void)text; (void)length;
|
||||
}
|
||||
#endif
|
||||
virtual void notify(UIEventType t = UIEventType::none) = 0;
|
||||
virtual bool supportsDisplayRotation() const { return false; }
|
||||
virtual bool setDisplayRotationDegrees(uint16_t degrees) {
|
||||
|
||||
@@ -763,6 +763,27 @@ bool DataStore::saveReaderBookmark(mesh::bible::Position pos) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UI_POCKET_GUI
|
||||
bool DataStore::loadPocketGuiSettings(mesh::ui::pocket::Settings& settings) {
|
||||
if (_primary_storage_unavailable || _fs == nullptr) return false;
|
||||
File file = openRead(_fs, "/pocket.ui");
|
||||
if (!file) return false;
|
||||
uint8_t bytes[mesh::ui::pocket::SETTINGS_RECORD_SIZE];
|
||||
const bool read = file.size() == sizeof(bytes)
|
||||
&& file.read(bytes, sizeof(bytes)) == sizeof(bytes);
|
||||
file.close();
|
||||
return read && mesh::ui::pocket::decodeSettings(settings, bytes, sizeof(bytes), MAX_GROUP_CHANNELS);
|
||||
}
|
||||
|
||||
bool DataStore::savePocketGuiSettings(const mesh::ui::pocket::Settings& settings) {
|
||||
if (_primary_storage_unavailable || _volatile_primary_fs || _fs == nullptr) return false;
|
||||
uint8_t bytes[mesh::ui::pocket::SETTINGS_RECORD_SIZE];
|
||||
if (!mesh::ui::pocket::encodeSettings(settings, bytes, sizeof(bytes), MAX_GROUP_CHANNELS)) return false;
|
||||
mesh::AtomicFileWriter file(_fs, "/pocket.ui");
|
||||
return file && file.write(bytes, sizeof(bytes)) == sizeof(bytes) && file.commit();
|
||||
}
|
||||
#endif
|
||||
|
||||
File DataStore::openRead(FILESYSTEM* fs, const char* filename) {
|
||||
return mesh::openFileRead(fs, filename);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
#include <helpers/ContactSecretCache.h>
|
||||
#endif
|
||||
#include <helpers/CompanionReaderConfig.h>
|
||||
#include <helpers/ui/PocketGuiConfig.h>
|
||||
#if UI_POCKET_GUI
|
||||
#include <helpers/ui/PocketGuiSettings.h>
|
||||
#endif
|
||||
#if defined(ESP32_PLATFORM)
|
||||
namespace mesh { class ContactFileTransaction; }
|
||||
#endif
|
||||
@@ -235,6 +239,10 @@ public:
|
||||
bool loadPrefs(CompanionNodePrefs& prefs, double& node_lat,
|
||||
double& node_lon);
|
||||
bool savePrefs(const CompanionNodePrefs& prefs, double node_lat, double node_lon);
|
||||
#if UI_POCKET_GUI
|
||||
bool loadPocketGuiSettings(mesh::ui::pocket::Settings& settings);
|
||||
bool savePocketGuiSettings(const mesh::ui::pocket::Settings& settings);
|
||||
#endif
|
||||
#if COMPANION_FEATURE_READER
|
||||
bool loadReaderBookmark(mesh::bible::Position& pos);
|
||||
bool saveReaderBookmark(mesh::bible::Position pos);
|
||||
|
||||
@@ -6266,7 +6266,12 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
bool success = getChannel(channel_idx, channel);
|
||||
#if MESH_ENABLE_MESHTEXT_CHAT
|
||||
if (success && isMeshtextChannel(channel)) {
|
||||
if (sendMeshtextText(channel, text, len - i)) writeOKFrame();
|
||||
if (sendMeshtextText(channel, text, len - i)) {
|
||||
#if UI_POCKET_GUI
|
||||
if (_ui) _ui->channelMessageSent(channel_idx, channel.name, _prefs.node_name, text, len - i);
|
||||
#endif
|
||||
writeOKFrame();
|
||||
}
|
||||
else writeErrFrame(ERR_CODE_BAD_STATE);
|
||||
} else
|
||||
#endif
|
||||
@@ -6274,6 +6279,9 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
&& parseCompanionChannelAlias(channel.name).kind == CompanionChannelKind::Meshtext) {
|
||||
writeErrFrame(ERR_CODE_UNSUPPORTED_CMD);
|
||||
} else if (success && sendGroupMessage(msg_timestamp, channel.channel, _prefs.node_name, text, len - i)) {
|
||||
#if UI_POCKET_GUI
|
||||
if (_ui) _ui->channelMessageSent(channel_idx, channel.name, _prefs.node_name, text, len - i);
|
||||
#endif
|
||||
writeOKFrame();
|
||||
} else {
|
||||
writeErrFrame(ERR_CODE_NOT_FOUND); // bad channel_idx
|
||||
|
||||
@@ -584,6 +584,10 @@ public:
|
||||
bool loadReaderBookmark(mesh::bible::Position& pos) { return _store->loadReaderBookmark(pos); }
|
||||
bool saveReaderBookmark(mesh::bible::Position pos) { return _store->saveReaderBookmark(pos); }
|
||||
#endif
|
||||
#if UI_POCKET_GUI
|
||||
bool loadPocketGuiSettings(mesh::ui::pocket::Settings& settings) { return _store->loadPocketGuiSettings(settings); }
|
||||
bool savePocketGuiSettings(const mesh::ui::pocket::Settings& settings) { return _store->savePocketGuiSettings(settings); }
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
bool setGpsEnabled(bool enabled);
|
||||
|
||||
@@ -0,0 +1,385 @@
|
||||
#pragma once
|
||||
|
||||
#include <helpers/ui/PocketGuiConfig.h>
|
||||
|
||||
#if UI_POCKET_GUI
|
||||
|
||||
// Message-board layout adapted from jackywashere's MeshCore Mesh Pocket
|
||||
// MessageBoard (MIT), https://github.com/jackywashere/MeshCore-Mesh-Pocket-MessageBoard.
|
||||
// The existing companion history, notifications and navigation remain shared.
|
||||
|
||||
#include <helpers/ui/GxEPDDisplay.h>
|
||||
#include <helpers/ui/PocketGuiSettings.h>
|
||||
#include <U8g2_for_Adafruit_GFX.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace mesh {
|
||||
namespace ui {
|
||||
namespace pocket {
|
||||
|
||||
struct Frame {
|
||||
uint32_t now = 0;
|
||||
uint64_t heard_millis = 0;
|
||||
float tz_offset = 0;
|
||||
int battery_percent = 0;
|
||||
const char* connection = nullptr;
|
||||
int page_index = 0;
|
||||
int page_count = 1;
|
||||
const char* hint = nullptr;
|
||||
int rotation = 3;
|
||||
};
|
||||
|
||||
class PocketGui {
|
||||
static constexpr int HEADER_HEIGHT = 14;
|
||||
static constexpr int FOOTER_HEIGHT = 14;
|
||||
static constexpr uint32_t VALID_TIME = 1735689600UL;
|
||||
struct Line { uint8_t start, length; };
|
||||
|
||||
GxEPDDisplay* _display = nullptr;
|
||||
Adafruit_GFX* _gfx = nullptr;
|
||||
U8G2_FOR_ADAFRUIT_GFX _font;
|
||||
bool _ready = false;
|
||||
Settings _settings;
|
||||
Frame _frame;
|
||||
BoardState _board;
|
||||
int _width = 250, _height = 122;
|
||||
uint16_t _ink = GxEPD_BLACK, _paper = GxEPD_WHITE;
|
||||
char _scratch[192];
|
||||
|
||||
void hash(const void* value, size_t size) { _display->crcAdd(value, size); }
|
||||
void hashGeometry(int a, int b = 0, int c = 0, int d = 0) {
|
||||
const int value[] = {a, b, c, d};
|
||||
hash(value, sizeof(value));
|
||||
}
|
||||
void normal() { _font.setForegroundColor(_ink); _font.setBackgroundColor(_paper); }
|
||||
void inverse() { _font.setForegroundColor(_paper); _font.setBackgroundColor(_ink); }
|
||||
void font(bool bold = false, bool large = false) {
|
||||
const uint8_t key = (bold ? 1 : 0) | (large ? 2 : 0);
|
||||
hash(&key, 1);
|
||||
_font.setFont(large ? (bold ? u8g2_font_helvB10_tf : u8g2_font_helvR10_tf)
|
||||
: (bold ? u8g2_font_helvB08_tf : u8g2_font_helvR08_tf));
|
||||
}
|
||||
int textWidth(const char* value) { return _font.getUTF8Width(value); }
|
||||
void fitText(char* value, int maximum_width) {
|
||||
while (textWidth(value) > maximum_width && value[0] != 0) {
|
||||
const size_t length = strlen(value);
|
||||
size_t previous = 0, cursor = 0;
|
||||
while (cursor < length) { previous = cursor; cursor = nextUtf8Character(value, cursor, length); }
|
||||
value[previous] = 0;
|
||||
}
|
||||
}
|
||||
void textRight(int x, int y, const char* value) { text(x - textWidth(value), y, value); }
|
||||
void textCentre(int x, int y, const char* value) { text(x - textWidth(value) / 2, y, value); }
|
||||
void fill(int x, int y, int width, int height, bool erase = false) {
|
||||
hashGeometry(x, y, width, height);
|
||||
hash(&erase, sizeof(erase));
|
||||
_gfx->fillRect(x, y, width, height, erase ? _paper : _ink);
|
||||
}
|
||||
void dots(int left, int right, int y) {
|
||||
hashGeometry(left, right, y);
|
||||
for (int x = left; x < right; x += 3) _gfx->drawPixel(x, y, _ink);
|
||||
}
|
||||
void textPart(int x, int y, const char* value, size_t length) {
|
||||
if (length >= sizeof(_scratch)) length = sizeof(_scratch) - 1;
|
||||
memcpy(_scratch, value, length);
|
||||
_scratch[length] = 0;
|
||||
text(x, y, _scratch);
|
||||
}
|
||||
int widthPart(const char* value, size_t length) {
|
||||
if (length >= sizeof(_scratch)) length = sizeof(_scratch) - 1;
|
||||
memcpy(_scratch, value, length);
|
||||
_scratch[length] = 0;
|
||||
return textWidth(_scratch);
|
||||
}
|
||||
int wrap(const char* value, int first_width, int width, Line* lines, int capacity) {
|
||||
const size_t length = strlen(value);
|
||||
size_t position = 0;
|
||||
int count = 0;
|
||||
while (position < length && count < capacity) {
|
||||
if (count != 0) while (position < length && value[position] == ' ') ++position;
|
||||
if (position == length) break;
|
||||
const int available = count == 0 ? first_width : width;
|
||||
size_t cursor = position, last_fit = position, last_space = position;
|
||||
while (cursor < length) {
|
||||
const size_t next = nextUtf8Character(value, cursor, length);
|
||||
if (widthPart(value + position, next - position) > available) break;
|
||||
if (value[cursor] == ' ') last_space = cursor;
|
||||
cursor = next;
|
||||
last_fit = next;
|
||||
}
|
||||
if (last_fit == position) {
|
||||
if (count == 0 && first_width < width) {
|
||||
lines[count++] = {(uint8_t)position, 0};
|
||||
continue;
|
||||
}
|
||||
last_fit = nextUtf8Character(value, position, length);
|
||||
} else if (last_fit < length && last_space > position) {
|
||||
last_fit = last_space;
|
||||
}
|
||||
lines[count++] = {(uint8_t)position, (uint8_t)(last_fit - position)};
|
||||
position = last_fit;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
void clock(char* output, size_t size, uint32_t timestamp) const {
|
||||
const int64_t local = (int64_t)timestamp + (int32_t)(_frame.tz_offset * 3600.0f);
|
||||
int32_t seconds = (int32_t)(local % 86400);
|
||||
if (seconds < 0) seconds += 86400;
|
||||
snprintf(output, size, "%02u:%02u", (unsigned)(seconds / 3600),
|
||||
(unsigned)(seconds / 60 % 60));
|
||||
}
|
||||
void messageTime(char* output, size_t size, uint64_t heard_millis) const {
|
||||
const uint32_t age = messageAgeSeconds(_frame.heard_millis, heard_millis);
|
||||
if (age >= 20UL * 3600UL)
|
||||
snprintf(output, size, "%lud", (unsigned long)((age + 43200) / 86400));
|
||||
else if (_frame.now >= VALID_TIME && age <= _frame.now - VALID_TIME)
|
||||
clock(output, size, _frame.now - (uint32_t)age);
|
||||
else if (age >= 3600) snprintf(output, size, "%luh", (unsigned long)(age / 3600));
|
||||
else if (age >= 60) snprintf(output, size, "%lum", (unsigned long)(age / 60));
|
||||
else snprintf(output, size, "now");
|
||||
}
|
||||
|
||||
public:
|
||||
void begin(GxEPDDisplay& display, const Settings& settings, const Frame& frame) {
|
||||
_display = &display;
|
||||
_settings = settings;
|
||||
_frame = frame;
|
||||
display.setNativeRotation((frame.rotation + (settings.flip ? 2 : 0)) & 3);
|
||||
_gfx = &display.gfx();
|
||||
if (!_ready) { _font.begin(*_gfx); _ready = true; }
|
||||
_width = _gfx->width(); _height = _gfx->height();
|
||||
_ink = settings.dark ? GxEPD_WHITE : GxEPD_BLACK;
|
||||
_paper = settings.dark ? GxEPD_BLACK : GxEPD_WHITE;
|
||||
_gfx->fillScreen(_paper);
|
||||
_font.setFontMode(1); _font.setFontDirection(0);
|
||||
normal();
|
||||
const uint8_t appearance[] = {(uint8_t)frame.rotation, settings.flip, settings.dark};
|
||||
hash(appearance, sizeof(appearance));
|
||||
}
|
||||
int width() const { return _width; }
|
||||
int height() const { return _height; }
|
||||
int bodyTop() const { return HEADER_HEIGHT + 2; }
|
||||
int bodyBottom() const { return _height - FOOTER_HEIGHT - 2; }
|
||||
Adafruit_GFX& gfx() { return *_gfx; }
|
||||
uint16_t ink() const { return _ink; }
|
||||
uint16_t paper() const { return _paper; }
|
||||
void text(int x, int y, const char* value) {
|
||||
hashGeometry(x, y);
|
||||
hash(value, strlen(value));
|
||||
_font.drawUTF8(x, y, value);
|
||||
}
|
||||
void line(int x0, int y0, int x1, int y1) {
|
||||
hashGeometry(x0, y0, x1, y1);
|
||||
_gfx->drawLine(x0, y0, x1, y1, _ink);
|
||||
}
|
||||
void label(int x, int y, const char* value, bool bold = false) {
|
||||
font(bold);
|
||||
if (value != nullptr && x >= 0 && x < _width) {
|
||||
sanitizeText(_scratch, sizeof(_scratch), value, strlen(value));
|
||||
fitText(_scratch, _width - x);
|
||||
text(x, y, _scratch);
|
||||
}
|
||||
font();
|
||||
}
|
||||
void marker(int x, int y, bool self = false) {
|
||||
hashGeometry(x, y, self);
|
||||
_gfx->fillCircle(x, y, self ? 3 : 2, _ink);
|
||||
if (self) _gfx->drawCircle(x, y, 5, _ink);
|
||||
}
|
||||
void header(const char* title, const char* centre = nullptr) {
|
||||
fill(0, 0, _width, HEADER_HEIGHT);
|
||||
inverse(); font(true);
|
||||
char title_text[48];
|
||||
sanitizeText(title_text, sizeof(title_text), title, strlen(title));
|
||||
fitText(title_text, _width / 2 - 4);
|
||||
text(3, 10, title_text);
|
||||
const int title_end = 3 + textWidth(title_text);
|
||||
char status[16];
|
||||
const int battery = _frame.battery_percent < 0 ? 0 : _frame.battery_percent > 100 ? 100 : _frame.battery_percent;
|
||||
snprintf(status, sizeof(status), "%d%%", battery);
|
||||
textRight(_width - 3, 10, status);
|
||||
int right = _width - 8 - textWidth(status);
|
||||
if (_frame.connection != nullptr && _frame.connection[0] != 0) {
|
||||
const int connection_width = textWidth(_frame.connection);
|
||||
if (right - connection_width > title_end + 5) {
|
||||
textRight(right, 10, _frame.connection);
|
||||
right -= connection_width + 5;
|
||||
}
|
||||
}
|
||||
if (centre == nullptr && _frame.now >= VALID_TIME) {
|
||||
clock(status, sizeof(status), _frame.now); centre = status;
|
||||
}
|
||||
if (centre != nullptr) {
|
||||
const int centre_width = textWidth(centre);
|
||||
int x = (_width - centre_width) / 2;
|
||||
if (x + centre_width > right) x = right - centre_width;
|
||||
if (x > title_end + 5) text(x, 10, centre);
|
||||
}
|
||||
normal();
|
||||
}
|
||||
void footer(const char* hint = nullptr) {
|
||||
fill(0, _height - FOOTER_HEIGHT, _width, FOOTER_HEIGHT, true);
|
||||
dots(2, _width - 2, _height - FOOTER_HEIGHT);
|
||||
font(); normal();
|
||||
if (hint == nullptr) hint = _frame.hint != nullptr ? _frame.hint : "click next / 2x back";
|
||||
char hint_text[96];
|
||||
sanitizeText(hint_text, sizeof(hint_text), hint, strlen(hint));
|
||||
fitText(hint_text, _width - 6);
|
||||
text(3, _height - 3, hint_text);
|
||||
if (_frame.page_count > 1 && _frame.page_count <= 16) {
|
||||
const int step = 5;
|
||||
const int left = _width - 4 - (_frame.page_count - 1) * step;
|
||||
if (textWidth(hint_text) + 7 < left) {
|
||||
for (int i = 0; i < _frame.page_count; ++i) {
|
||||
const int x = left + i * step;
|
||||
if (i == _frame.page_index) _gfx->fillRect(x - 1, _height - 8, 3, 3, _ink);
|
||||
else _gfx->drawPixel(x, _height - 7, _ink);
|
||||
}
|
||||
hashGeometry(_frame.page_index, _frame.page_count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename History>
|
||||
unsigned boardCount(const History& history) const {
|
||||
unsigned count = 0;
|
||||
for (size_t age = 0; age < history.count(); ++age) {
|
||||
const auto* entry = history.newest(age);
|
||||
if (entry != nullptr && entry->channel_idx == _settings.channel) ++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
template <typename History>
|
||||
bool scrollOlder(const History& history) { return _board.scrollOlder(boardCount(history)); }
|
||||
bool scrollOlder(unsigned count) { return _board.scrollOlder(count); }
|
||||
bool scrollNewer() { return _board.scrollNewer(); }
|
||||
bool isScrolled() const { return _board.scroll != 0; }
|
||||
void resetScroll() { _board.scroll = 0; }
|
||||
void messageAdded() { _board.messageAdded(); }
|
||||
|
||||
template <typename History>
|
||||
void renderBoard(History& history, const char* channel_name) {
|
||||
char title[42], centre[18];
|
||||
snprintf(title, sizeof(title), "# %s", channel_name == nullptr ? "Channel" : channel_name);
|
||||
const unsigned count = boardCount(history);
|
||||
_board.clamp(count);
|
||||
if (_board.scroll != 0) snprintf(centre, sizeof(centre), "%u newer", _board.scroll);
|
||||
header(title, _board.scroll != 0 ? centre : nullptr);
|
||||
if (count == 0) {
|
||||
font(true); textCentre(_width / 2, 54, "Listening for messages");
|
||||
font(); textCentre(_width / 2, 72, "hold to browse / settings picks channel");
|
||||
footer(); return;
|
||||
}
|
||||
|
||||
const bool large = _settings.text_large != 0;
|
||||
font(false, large);
|
||||
const int ascent = _font.getFontAscent();
|
||||
const int line_height = ascent - _font.getFontDescent() + (large ? 2 : 1);
|
||||
int y = bodyBottom();
|
||||
unsigned filtered_age = 0;
|
||||
for (size_t age = 0; age < history.count() && y >= bodyTop(); ++age) {
|
||||
const auto* entry = history.newest(age);
|
||||
if (entry == nullptr || entry->channel_idx != _settings.channel) continue;
|
||||
if (filtered_age++ < _board.scroll) continue;
|
||||
BoardMessageView message;
|
||||
parseBoardMessage(entry->origin, entry->message, entry->own_sent, message);
|
||||
char sender[64], body[192], timestamp[16];
|
||||
sanitizeText(sender, sizeof(sender), message.sender, message.sender_length);
|
||||
truncateCharacters(sender, nameCharacters(_settings));
|
||||
sanitizeText(body, sizeof(body), message.text, strlen(message.text));
|
||||
messageTime(timestamp, sizeof(timestamp), entry->heard_millis);
|
||||
font(true, large);
|
||||
int name_width = sender[0] == 0 ? 0 : textWidth(sender) + (entry->own_sent ? 9 : 5);
|
||||
// Long full names must leave room for the timestamp and message text.
|
||||
fitText(sender, _width / 2 - (entry->own_sent ? 9 : 5));
|
||||
name_width = sender[0] == 0 ? 0 : textWidth(sender) + (entry->own_sent ? 9 : 5);
|
||||
font(); const int time_width = textWidth(timestamp);
|
||||
font(false, large);
|
||||
Line lines[24];
|
||||
int line_count = wrap(body, _width - 10 - name_width - time_width,
|
||||
_width - 4, lines, 24);
|
||||
if (line_count == 0) { lines[0] = {0, 0}; line_count = 1; }
|
||||
const int top = y - line_count * line_height + 1;
|
||||
bool shown = false;
|
||||
for (int i = 0; i < line_count; ++i) {
|
||||
const int line_top = top + i * line_height;
|
||||
if (line_top < bodyTop()) continue;
|
||||
const int baseline = line_top + ascent;
|
||||
int x = 2;
|
||||
if (i == 0) {
|
||||
if (sender[0] != 0) {
|
||||
font(true, large);
|
||||
if (entry->own_sent) {
|
||||
fill(x, line_top - 1, name_width - 3, line_height + 1);
|
||||
inverse(); text(x + 3, baseline, sender); normal();
|
||||
} else text(x, baseline, sender);
|
||||
x += name_width;
|
||||
}
|
||||
font(); textRight(_width - 2, baseline, timestamp);
|
||||
shown = true;
|
||||
}
|
||||
font(false, large);
|
||||
if (lines[i].length != 0) {
|
||||
textPart(x, baseline, body + lines[i].start, lines[i].length);
|
||||
shown = true;
|
||||
}
|
||||
}
|
||||
if (shown && _display->isOn()) history.markRead(entry);
|
||||
y = top - 5;
|
||||
if (y > bodyTop()) dots(2, _width - 2, y + 2);
|
||||
}
|
||||
footer();
|
||||
}
|
||||
|
||||
void renderSettings(unsigned selected, bool editing, const char* channel_name = nullptr) {
|
||||
header("Settings", editing ? "editing" : nullptr);
|
||||
static const char* const names[] = {"Channel", "Text", "Names", "Screen", "Theme", "Return", "Clean", "Map zoom"};
|
||||
static const char* const idle[] = {"30 seconds", "1 minute", "5 minutes", "Never"};
|
||||
static const char* const clean[] = {"10 updates", "30 updates", "60 updates", "Manual"};
|
||||
for (unsigned row = 0; row < SETTINGS_COUNT; ++row) {
|
||||
const int y = bodyTop() + row * 11;
|
||||
if (row == selected && editing) { fill(1, y - 1, _width - 2, 11); inverse(); }
|
||||
else normal();
|
||||
font(row == selected && editing);
|
||||
text(4, y + 8, names[row]);
|
||||
char value[40];
|
||||
switch (row) {
|
||||
case 0:
|
||||
if (channel_name != nullptr && channel_name[0] != 0)
|
||||
sanitizeText(value, sizeof(value), channel_name, strlen(channel_name));
|
||||
else snprintf(value, sizeof(value), "Channel %u", _settings.channel);
|
||||
truncateCharacters(value, 19); break;
|
||||
case 1: snprintf(value, sizeof(value), "%s", _settings.text_large ? "Large" : "Small"); break;
|
||||
case 2:
|
||||
if (nameCharacters(_settings) == 0) snprintf(value, sizeof(value), "Full");
|
||||
else snprintf(value, sizeof(value), "%u characters", nameCharacters(_settings));
|
||||
break;
|
||||
case 3: snprintf(value, sizeof(value), "%s", _settings.flip ? "Flipped" : "Normal"); break;
|
||||
case 4: snprintf(value, sizeof(value), "%s", _settings.dark ? "Dark" : "Light"); break;
|
||||
case 5: snprintf(value, sizeof(value), "%s", idle[_settings.idle <= 3 ? _settings.idle : 1]); break;
|
||||
case 6: snprintf(value, sizeof(value), "%s", clean[_settings.refresh <= 3 ? _settings.refresh : 1]); break;
|
||||
default: snprintf(value, sizeof(value), "%u km", (unsigned)mapHeightKm(_settings)); break;
|
||||
}
|
||||
textRight(_width - 4, y + 8, value);
|
||||
}
|
||||
normal(); footer();
|
||||
}
|
||||
|
||||
void renderMapChrome(unsigned actual_height_km = 0) {
|
||||
char range[24];
|
||||
snprintf(range, sizeof(range), "%u km", actual_height_km != 0
|
||||
? actual_height_km : (unsigned)mapHeightKm(_settings));
|
||||
header("Map", range);
|
||||
footer();
|
||||
}
|
||||
void mapEmpty(const char* message) {
|
||||
font(true); textCentre(_width / 2, 54, message);
|
||||
font(); textCentre(_width / 2, 72, "Set location in the companion app");
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace pocket
|
||||
} // namespace ui
|
||||
} // namespace mesh
|
||||
|
||||
#endif // UI_POCKET_GUI
|
||||
@@ -24,6 +24,10 @@
|
||||
#include "target.h"
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#if UI_POCKET_GUI
|
||||
#include "PocketGui.h"
|
||||
#include <helpers/ui/PocketWorldMap.h>
|
||||
#endif
|
||||
#if defined(ENABLE_WIFI_INTERFACE) || defined(WIFI_SSID)
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
@@ -416,6 +420,11 @@ public:
|
||||
class HomeScreen : public UIScreen {
|
||||
enum HomePage {
|
||||
FIRST,
|
||||
#if UI_POCKET_GUI
|
||||
MAP,
|
||||
STATUS,
|
||||
SETTINGS,
|
||||
#endif
|
||||
#if UI_MESSAGES_HOME_PAGE == 1
|
||||
MESSAGES,
|
||||
#endif
|
||||
@@ -463,6 +472,16 @@ class HomeScreen : public UIScreen {
|
||||
uint32_t _radio_profile_page_started_at = 0;
|
||||
uint8_t _radio_status_page = 0;
|
||||
bool _dual_radio_enabled_seen = false;
|
||||
#if UI_POCKET_GUI
|
||||
mesh::ui::pocket::PocketGui _pocket;
|
||||
bool _pocket_editing = false;
|
||||
bool _pocket_browsing = false;
|
||||
bool _pocket_zooming = false;
|
||||
bool _pocket_dirty = false;
|
||||
uint8_t _pocket_setting = 0;
|
||||
uint32_t _pocket_last_input = 0;
|
||||
uint32_t _pocket_save_retry = 0;
|
||||
#endif
|
||||
AdvertPath recent[UI_RECENT_LIST_SIZE];
|
||||
#if !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
||||
DiscoveredNode discovered[UI_RECENT_LIST_SIZE];
|
||||
@@ -620,6 +639,10 @@ class HomeScreen : public UIScreen {
|
||||
}
|
||||
|
||||
void movePage(int direction) {
|
||||
#if UI_POCKET_GUI
|
||||
flushPocketSettings();
|
||||
_pocket_editing = _pocket_browsing = _pocket_zooming = false;
|
||||
#endif
|
||||
do {
|
||||
_page = (_page + HomePage::Count + direction) % HomePage::Count;
|
||||
} while (!isPageVisible(_page));
|
||||
@@ -636,7 +659,268 @@ class HomeScreen : public UIScreen {
|
||||
: UI_RADIO_REFRESH_MILLIS;
|
||||
}
|
||||
|
||||
#if UI_POCKET_GUI
|
||||
void displayForceClean() { _task->cleanPocketDisplay(); }
|
||||
|
||||
void cyclePocketChannel(int direction) {
|
||||
auto& settings = _task->pocketSettings();
|
||||
const int previous = settings.channel;
|
||||
int selected = previous;
|
||||
for (int attempt = 0; attempt < MAX_GROUP_CHANNELS; ++attempt) {
|
||||
selected = (selected + MAX_GROUP_CHANNELS + direction) % MAX_GROUP_CHANNELS;
|
||||
ChannelDetails channel;
|
||||
if (the_mesh.getChannel(selected, channel) && channel.name[0]) {
|
||||
settings.channel = selected;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_pocket_dirty |= previous != settings.channel;
|
||||
_pocket.resetScroll();
|
||||
}
|
||||
|
||||
static bool pocketLocation(double latitude, double longitude) {
|
||||
return isfinite(latitude) && isfinite(longitude)
|
||||
&& latitude >= -90 && latitude <= 90 && longitude >= -180 && longitude <= 180
|
||||
&& (latitude != 0 || longitude != 0);
|
||||
}
|
||||
|
||||
__attribute__((noinline)) void renderPocketMap() {
|
||||
using namespace mesh::ui::pocket;
|
||||
const auto& settings = _task->pocketSettings();
|
||||
const double own_lat = sensors.node_lat, own_lon = sensors.node_lon;
|
||||
const bool have_own = pocketLocation(own_lat, own_lon);
|
||||
double latitude = own_lat, longitude = own_lon;
|
||||
bool located = have_own;
|
||||
ContactInfo contact;
|
||||
if (!located) {
|
||||
auto contacts = the_mesh.startContactsIterator();
|
||||
while (contacts.hasNext(&the_mesh, contact)) {
|
||||
latitude = contact.gps_lat * 1e-6;
|
||||
longitude = contact.gps_lon * 1e-6;
|
||||
if (pocketLocation(latitude, longitude)) { located = true; break; }
|
||||
}
|
||||
}
|
||||
MapView view = {located ? latitude : 0, located ? longitude : 0,
|
||||
located ? mapHeightKm(settings) : 20000, _pocket.width(),
|
||||
_pocket.bodyBottom() - _pocket.bodyTop()};
|
||||
if (!renderWorldMap(view, [](void* context, int x0, int y0, int x1, int y1) {
|
||||
auto& gui = *static_cast<PocketGui*>(context);
|
||||
gui.line(x0, y0 + gui.bodyTop(), x1, y1 + gui.bodyTop());
|
||||
}, &_pocket)) {
|
||||
_pocket.label(3, 40, "Map unavailable");
|
||||
}
|
||||
int x, y;
|
||||
unsigned shown = 0, labels = 0;
|
||||
auto contacts = the_mesh.startContactsIterator();
|
||||
while (contacts.hasNext(&the_mesh, contact)) {
|
||||
latitude = contact.gps_lat * 1e-6; longitude = contact.gps_lon * 1e-6;
|
||||
if (!pocketLocation(latitude, longitude)
|
||||
|| !projectWorldPoint(view, latitude, longitude, x, y)) continue;
|
||||
_pocket.marker(x, y + _pocket.bodyTop());
|
||||
++shown;
|
||||
if (view.height_km <= 50 && labels < 4 && x < view.width - 52 && y >= 10) {
|
||||
char name[12];
|
||||
sanitizeText(name, sizeof(name), contact.name, strnlen(contact.name, sizeof(contact.name)));
|
||||
truncateCharacters(name, 8);
|
||||
_pocket.label(x + 4, y + _pocket.bodyTop() - 3, name);
|
||||
++labels;
|
||||
}
|
||||
}
|
||||
if (have_own && projectWorldPoint(view, own_lat, own_lon, x, y))
|
||||
_pocket.marker(x, y + _pocket.bodyTop(), true);
|
||||
char summary[40];
|
||||
if (located) snprintf(summary, sizeof(summary), "%u nodes%s", shown,
|
||||
view.height_km < 100 ? " / coarse coast" : "");
|
||||
else snprintf(summary, sizeof(summary), "World / no node locations");
|
||||
_pocket.label(3, _pocket.bodyTop() + 9, summary);
|
||||
_pocket.renderMapChrome((unsigned)view.height_km);
|
||||
}
|
||||
|
||||
int renderPocket(DisplayDriver& display) {
|
||||
using namespace mesh::ui::pocket;
|
||||
const auto& settings = _task->pocketSettings();
|
||||
Frame frame;
|
||||
const uint32_t uptime_now = millis();
|
||||
_uptime_millis += uint32_t(uptime_now - _uptime_last_millis);
|
||||
_uptime_last_millis = uptime_now;
|
||||
frame.now = _rtc->getCurrentTime(); frame.heard_millis = companionMessageNowMillis();
|
||||
frame.tz_offset = _node_prefs->tz_offset;
|
||||
frame.battery_percent = (int(_task->getBattMilliVolts()) - BATT_MIN_MILLIVOLTS)
|
||||
* 100 / (BATT_MAX_MILLIVOLTS - BATT_MIN_MILLIVOLTS);
|
||||
#if defined(NRF52_POWER_MANAGEMENT)
|
||||
frame.battery_percent = mesh::power::configuredBatteryPercent(_task->getBattMilliVolts());
|
||||
#endif
|
||||
frame.connection = _task->connectedClientLabel();
|
||||
frame.page_count = frame.page_index = 0;
|
||||
for (unsigned page = 0; page < HomePage::Count; ++page) if (isPageVisible(page)) {
|
||||
if (page < _page) ++frame.page_index;
|
||||
++frame.page_count;
|
||||
}
|
||||
frame.rotation = DISPLAY_ROTATION;
|
||||
if (_pocket_browsing) frame.hint = "1x older 2x newer hold exit";
|
||||
else if (_pocket_zooming) frame.hint = "1x zoom in 2x out hold done";
|
||||
else if (_pocket_editing) frame.hint = "1x value 2x field hold save";
|
||||
else if (isRadioPage()) frame.hint = "click next 2x back hold Reader";
|
||||
else if (_page == HomePage::FIRST) frame.hint = "click next 2x back hold browse";
|
||||
else if (_page == HomePage::MAP) frame.hint = "click next 2x back hold zoom";
|
||||
else if (_page == HomePage::SETTINGS) frame.hint = "click next 2x back hold edit";
|
||||
else frame.hint = "click next 2x back hold action";
|
||||
static_cast<GxEPDDisplay&>(display).setMaxPartialRefresh(refreshCount(settings));
|
||||
_pocket.begin(static_cast<GxEPDDisplay&>(display), settings, frame);
|
||||
ChannelDetails channel;
|
||||
char channel_name[32] = {};
|
||||
if (the_mesh.getChannel(settings.channel, channel))
|
||||
StrHelper::strncpy(channel_name, channel.name, sizeof(channel_name));
|
||||
if (_page == HomePage::FIRST) _task->renderPocketBoard(_pocket);
|
||||
else if (_page == HomePage::MAP) { renderPocketMap(); return 10000; }
|
||||
else if (_page == HomePage::SETTINGS) _pocket.renderSettings(_pocket_setting, _pocket_editing, channel_name);
|
||||
else {
|
||||
char text[80];
|
||||
int y = _pocket.bodyTop() + 10;
|
||||
auto row = [&](const char* value) {
|
||||
if (y <= _pocket.bodyBottom() - 2) _pocket.label(4, y, value);
|
||||
y += 14;
|
||||
};
|
||||
if (_page == HomePage::STATUS) {
|
||||
_pocket.header("Status", (_radio_status_page & 1) ? "2 / 2" : "1 / 2");
|
||||
if ((_radio_status_page & 1) == 0) {
|
||||
snprintf(text, sizeof(text), "Uptime %lu min battery %u mV", (unsigned long)(_uptime_millis / 60000), _task->getBattMilliVolts()); row(text);
|
||||
snprintf(text, sizeof(text), "RX %lu flood / %lu direct", (unsigned long)the_mesh.getNumRecvFlood(), (unsigned long)the_mesh.getNumRecvDirect()); row(text);
|
||||
snprintf(text, sizeof(text), "TX %lu flood / %lu direct", (unsigned long)the_mesh.getNumSentFlood(), (unsigned long)the_mesh.getNumSentDirect()); row(text);
|
||||
snprintf(text, sizeof(text), "Inbox %d / %d errors %04X", _task->getMsgCount(), the_mesh.getOfflineQueueCapacity(), the_mesh.getErrFlags()); row(text);
|
||||
mesh::Utils::toHex(text, the_mesh.self_id.pub_key, 6); row(text);
|
||||
} else {
|
||||
const auto status = radioProfileSystemStatus(*_node_prefs);
|
||||
snprintf(text, sizeof(text), "Power saving %s / GPS %s", status.powersaving_enabled ? "on" : "off", status.gps_enabled ? "on" : "off"); row(text);
|
||||
snprintf(text, sizeof(text), "FEM %s / RX boost %s", status.fem_enabled ? "on" : "off", status.rx_boosted_gain ? "on" : "off"); row(text);
|
||||
snprintf(text, sizeof(text), "RX power saving %s / CAD %s", status.rx_powersaving_enabled ? "on" : "off", status.cad_enabled ? "on" : "off"); row(text);
|
||||
mesh::ui::formatRadioProfileNoiseFloor(text, sizeof(text), "Radio 1 noise", status.noise_floor_1, status.noise_floor_1_seconds); row(text);
|
||||
}
|
||||
} else if (_page == HomePage::RECENT) {
|
||||
_pocket.header("Recently heard");
|
||||
const int count = the_mesh.getRecentlyHeard(recent, UI_RECENT_LIST_SIZE);
|
||||
for (int i = 0; i < count && y <= _pocket.bodyBottom(); ++i) {
|
||||
char name[40]; sanitizeText(name, sizeof(name), recent[i].name, strnlen(recent[i].name, sizeof(recent[i].name)));
|
||||
snprintf(text, sizeof(text), "%.28s %lum", name, (unsigned long)((frame.now - recent[i].recv_timestamp) / 60)); row(text);
|
||||
}
|
||||
if (!count) row("No adverts heard yet");
|
||||
} else if (_page == HomePage::RADIO_STATUS) {
|
||||
_pocket.header("Radio status", (_radio_status_page & 1) ? "2 / 2" : "1 / 2");
|
||||
const auto status = radioProfileSystemStatus(*_node_prefs);
|
||||
if ((_radio_status_page & 1) == 0) {
|
||||
snprintf(text, sizeof(text), "Power saving %s / GPS %s", status.powersaving_enabled ? "on" : "off", status.gps_enabled ? "on" : "off"); row(text);
|
||||
snprintf(text, sizeof(text), "FEM %s / RX boost %s", status.fem_enabled ? "on" : "off", status.rx_boosted_gain ? "on" : "off"); row(text);
|
||||
snprintf(text, sizeof(text), "RX power saving %s / CAD %s", status.rx_powersaving_enabled ? "on" : "off", status.cad_enabled ? "on" : "off"); row(text);
|
||||
} else {
|
||||
mesh::ui::formatRadioProfileNoiseFloor(text, sizeof(text), "Radio 1 noise", status.noise_floor_1, status.noise_floor_1_seconds); row(text);
|
||||
mesh::ui::formatRadioProfileNoiseFloor(text, sizeof(text), "Radio 2 noise", status.noise_floor_2, status.noise_floor_2_seconds); row(text);
|
||||
snprintf(text, sizeof(text), "Radio2 %s%s / cross %s", status.secondary_mode == mesh::RadioProfileMode::RxTx ? "RX/TX" : "RX",
|
||||
status.secondary_temporary ? " temporary" : "", status.cross == mesh::RadioCrossMode::Off ? "off" : status.cross == mesh::RadioCrossMode::On ? "on" : "auto"); row(text);
|
||||
}
|
||||
row("Hold for more status");
|
||||
} else if (_page == HomePage::RADIO || _page == HomePage::RADIO2) {
|
||||
const auto* radio = the_mesh.getProfileRadio();
|
||||
const auto* profiles = radio ? radio->profiles() : nullptr;
|
||||
const bool secondary = _page == HomePage::RADIO2 && profiles && profiles->enabled();
|
||||
_pocket.header(secondary ? "Radio 2" : "Network");
|
||||
mesh::RadioProfileParams params;
|
||||
if (profiles && profiles->enabled()) params = profiles->params(secondary ? 1 : 0);
|
||||
else { params.freq = _node_prefs->freq; params.bw = _node_prefs->bw; params.sf = _node_prefs->sf; params.cr = _node_prefs->cr; }
|
||||
snprintf(text, sizeof(text), "%.3f MHz / %.2f kHz", params.freq, params.bw); row(text);
|
||||
snprintf(text, sizeof(text), "SF%u CR%u / %d dBm", params.sf, params.cr, _node_prefs->tx_power_dbm); row(text);
|
||||
snprintf(text, sizeof(text), "Noise %.1f dBm / RX boost %s", radio_driver.getNoiseFloorDbm(secondary ? 1 : 0), _node_prefs->rx_boosted_gain ? "on" : "off"); row(text);
|
||||
if (profiles && profiles->enabled()) {
|
||||
snprintf(text, sizeof(text), "Radio2 %s%s / cross %s", profiles->secondary.mode == mesh::RadioProfileMode::RxTx ? "RX/TX" : "RX",
|
||||
profiles->secondary_temporary ? " temporary" : "", profiles->cross == mesh::RadioCrossMode::Off ? "off" : profiles->cross == mesh::RadioCrossMode::On ? "on" : "auto"); row(text);
|
||||
snprintf(text, sizeof(text), "Switches %lu / failures %lu", (unsigned long)profiles->switches, (unsigned long)profiles->switch_failures); row(text);
|
||||
} else row("Radio2 off");
|
||||
#if UI_MESSAGES_HOME_PAGE == 1
|
||||
} else if (_page == HomePage::MESSAGES) {
|
||||
_pocket.header(_task->inboxTitle()); _task->renderPocketInbox(_pocket);
|
||||
#endif
|
||||
#if defined(BLE_PIN_CODE)
|
||||
} else if (_page == HomePage::BLUETOOTH) {
|
||||
_pocket.header("Bluetooth"); row(_task->isBluetoothEnabled() ? "Bluetooth enabled" : "Bluetooth disabled");
|
||||
row(_task->hasBluetoothConnection() ? "App connected" : "Waiting for an app"); row("Hold to toggle Bluetooth");
|
||||
#endif
|
||||
} else if (_page == HomePage::ADVERT) {
|
||||
_pocket.header("Advert"); row("Hold to send a local advert");
|
||||
snprintf(text, sizeof(text), "Node: %.31s", _node_prefs->node_name); row(text);
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
} else if (_page == HomePage::GPS) {
|
||||
_pocket.header("Location");
|
||||
snprintf(text, sizeof(text), "Latitude %.6f", sensors.node_lat); row(text);
|
||||
snprintf(text, sizeof(text), "Longitude %.6f", sensors.node_lon); row(text);
|
||||
row(_task->getGPSState() ? "GPS enabled" : "GPS disabled"); row("Hold to toggle GPS");
|
||||
#endif
|
||||
#if UI_SENSORS_PAGE == 1
|
||||
} else if (_page == HomePage::SENSORS) {
|
||||
_pocket.header("Sensors"); refresh_sensors();
|
||||
LPPReader readings(sensors_lpp.getBuffer(), sensors_lpp.getSize());
|
||||
uint8_t channel_id, type;
|
||||
for (int i = 0; i < sensors_scroll_offset && readings.readHeader(channel_id, type); ++i)
|
||||
readings.skipData(type);
|
||||
while (y <= _pocket.bodyBottom() - 2 && readings.readHeader(channel_id, type)) {
|
||||
float value;
|
||||
switch (type) {
|
||||
case LPP_GPS: {
|
||||
float lat, lon, alt; readings.readGPS(lat, lon, alt);
|
||||
snprintf(text, sizeof(text), "GPS %.4f / %.4f", lat, lon); break;
|
||||
}
|
||||
case LPP_VOLTAGE: readings.readVoltage(value); snprintf(text, sizeof(text), "Voltage %.2f V", value); break;
|
||||
case LPP_CURRENT: readings.readCurrent(value); snprintf(text, sizeof(text), "Current %.3f A", value); break;
|
||||
case LPP_TEMPERATURE: readings.readTemperature(value); snprintf(text, sizeof(text), "Temperature %.2f C", value); break;
|
||||
case LPP_RELATIVE_HUMIDITY: readings.readRelativeHumidity(value); snprintf(text, sizeof(text), "Humidity %.2f %%", value); break;
|
||||
case LPP_BAROMETRIC_PRESSURE: readings.readPressure(value); snprintf(text, sizeof(text), "Pressure %.2f hPa", value); break;
|
||||
case LPP_ALTITUDE: readings.readAltitude(value); snprintf(text, sizeof(text), "Altitude %.0f m", value); break;
|
||||
case LPP_POWER: readings.readPower(value); snprintf(text, sizeof(text), "Power %.2f W", value); break;
|
||||
default: readings.skipData(type); continue;
|
||||
}
|
||||
row(text);
|
||||
}
|
||||
if (y == _pocket.bodyTop() + 10) row("No sensor readings");
|
||||
if (sensors_scroll) sensors_scroll_offset = (sensors_scroll_offset + 1) % sensors_nb;
|
||||
#endif
|
||||
#if !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
||||
} else if (_page == HomePage::DISCOVERY) {
|
||||
_pocket.header("Repeaters nearby");
|
||||
const int count = the_mesh.getDiscoveredNodes(discovered, UI_RECENT_LIST_SIZE);
|
||||
for (int i = 0; i < count && y <= _pocket.bodyBottom(); ++i) {
|
||||
char name[33]; StrHelper::strncpy(name, discovered[i].name, sizeof(name));
|
||||
if (!name[0] || !discovery_disp_names) mesh::Utils::toHex(name, discovered[i].pubkey_prefix, 4);
|
||||
snprintf(text, sizeof(text), "%.28s %.1f dB", name, discovered[i].snr_in); row(text);
|
||||
}
|
||||
if (!count) row("Hold to discover nearby repeaters");
|
||||
#endif
|
||||
#ifndef UI_NO_HIBERNATE
|
||||
} else if (_page == HomePage::SHUTDOWN) {
|
||||
_pocket.header("Power"); row("Hold to shut down");
|
||||
#endif
|
||||
} else _pocket.header(_node_prefs->node_name);
|
||||
_pocket.footer();
|
||||
}
|
||||
return 5000;
|
||||
}
|
||||
#endif
|
||||
|
||||
public:
|
||||
#if UI_POCKET_GUI
|
||||
bool isPocketBoard() const { return _page == HomePage::FIRST; }
|
||||
void pocketMessageAdded(int channel) {
|
||||
if (channel == _task->pocketSettings().channel) _pocket.messageAdded();
|
||||
}
|
||||
bool flushPocketSettings() {
|
||||
if (!_pocket_dirty) return true;
|
||||
if (!the_mesh.savePocketGuiSettings(_task->pocketSettings())) {
|
||||
_pocket_save_retry = millis() + 30000;
|
||||
_task->showAlert("Settings save failed", 1500);
|
||||
return false;
|
||||
}
|
||||
_pocket_dirty = false;
|
||||
_pocket_save_retry = 0;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
HomeScreen(UITask* task, mesh::RTCClock* rtc, SensorManager* sensors, CompanionNodePrefs* node_prefs)
|
||||
: _task(task), _rtc(rtc), _sensors(sensors), _node_prefs(node_prefs), _page(0),
|
||||
_shutdown_init(false),
|
||||
@@ -652,7 +936,15 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
void showFirstPage() { _page = HomePage::FIRST; }
|
||||
void showFirstPage() {
|
||||
#if UI_POCKET_GUI
|
||||
flushPocketSettings();
|
||||
_pocket_editing = _pocket_browsing = _pocket_zooming = false;
|
||||
_pocket.resetScroll();
|
||||
_pocket_last_input = millis();
|
||||
#endif
|
||||
_page = HomePage::FIRST;
|
||||
}
|
||||
#if COMPANION_FEATURE_READER
|
||||
bool isRadioPage() const {
|
||||
return _page == HomePage::RADIO || _page == HomePage::RADIO2;
|
||||
@@ -672,6 +964,20 @@ public:
|
||||
#endif
|
||||
|
||||
void poll() override {
|
||||
#if UI_POCKET_GUI
|
||||
const uint32_t pocket_now = millis();
|
||||
if (_pocket_dirty && _pocket_save_retry && int32_t(pocket_now - _pocket_save_retry) >= 0)
|
||||
flushPocketSettings();
|
||||
const uint32_t idle = mesh::ui::pocket::idleMillis(_task->pocketSettings());
|
||||
if (idle && uint32_t(pocket_now - _pocket_last_input) >= idle
|
||||
&& (_page != HomePage::FIRST || _pocket_browsing)) {
|
||||
flushPocketSettings();
|
||||
_pocket_editing = _pocket_browsing = _pocket_zooming = false;
|
||||
_pocket.resetScroll();
|
||||
_page = HomePage::FIRST;
|
||||
_task->gotoHomeScreen();
|
||||
}
|
||||
#endif
|
||||
if (_dual_radio_enabled_seen != the_mesh.isDualRadioActive()) {
|
||||
resetRadioProfileDisplayPage();
|
||||
}
|
||||
@@ -704,6 +1010,9 @@ public:
|
||||
}
|
||||
|
||||
int render(DisplayDriver& display) override {
|
||||
#if UI_POCKET_GUI
|
||||
return renderPocket(display);
|
||||
#endif
|
||||
display.setTextSize(1);
|
||||
const int normal_line = !display.useSmallMessageFont()
|
||||
&& display.renderWidth() == display.width() ? display.textLineHeight() : 11;
|
||||
@@ -1322,6 +1631,56 @@ public:
|
||||
bool handleInput(char c) override {
|
||||
// Navigation codes exceed 0x7f; keep them valid with signed char too.
|
||||
const uint8_t key = static_cast<uint8_t>(c);
|
||||
#if UI_POCKET_GUI
|
||||
_pocket_last_input = millis();
|
||||
auto& settings = _task->pocketSettings();
|
||||
if (_page == HomePage::SETTINGS && key == KEY_ENTER) {
|
||||
_pocket_editing = !_pocket_editing;
|
||||
if (!_pocket_editing) flushPocketSettings();
|
||||
return true;
|
||||
}
|
||||
if (_page == HomePage::SETTINGS && _pocket_editing) {
|
||||
if (key == KEY_PREV || key == KEY_LEFT) {
|
||||
_pocket_setting = (_pocket_setting + 1) % mesh::ui::pocket::SETTINGS_COUNT;
|
||||
return true;
|
||||
}
|
||||
if (key == KEY_NEXT || key == KEY_RIGHT) {
|
||||
const uint8_t previous_dark = settings.dark, previous_flip = settings.flip;
|
||||
if (_pocket_setting == 0) cyclePocketChannel(1);
|
||||
else mesh::ui::pocket::cycleSetting(settings, _pocket_setting, MAX_GROUP_CHANNELS);
|
||||
_pocket_dirty = true;
|
||||
if (previous_dark != settings.dark || previous_flip != settings.flip) displayForceClean();
|
||||
_pocket.resetScroll();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (_page == HomePage::FIRST) {
|
||||
if (key == KEY_ENTER) { _pocket_browsing = !_pocket_browsing; return true; }
|
||||
if (key == KEY_DOWN || key == KEY_UP) {
|
||||
cyclePocketChannel(key == KEY_DOWN ? 1 : -1);
|
||||
flushPocketSettings();
|
||||
return true;
|
||||
}
|
||||
if (_pocket_browsing) {
|
||||
if (key == KEY_NEXT || key == KEY_RIGHT) { _pocket.scrollOlder(_task->pocketBoardCount()); return true; }
|
||||
if (key == KEY_PREV || key == KEY_LEFT) { _pocket.scrollNewer(); return true; }
|
||||
}
|
||||
}
|
||||
if (_page == HomePage::MAP) {
|
||||
if (key == KEY_ENTER) {
|
||||
_pocket_zooming = !_pocket_zooming;
|
||||
if (!_pocket_zooming) flushPocketSettings();
|
||||
return true;
|
||||
}
|
||||
if (_pocket_zooming && (key == KEY_NEXT || key == KEY_RIGHT || key == KEY_PREV || key == KEY_LEFT)) {
|
||||
const bool closer = key == KEY_NEXT || key == KEY_RIGHT;
|
||||
if (closer && settings.map_zoom < 8) ++settings.map_zoom;
|
||||
if (!closer && settings.map_zoom > 0) --settings.map_zoom;
|
||||
_pocket_dirty = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (key == KEY_LEFT || key == KEY_PREV) {
|
||||
movePage(-1);
|
||||
return true;
|
||||
@@ -1344,7 +1703,11 @@ public:
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
if (key == KEY_ENTER && _page == HomePage::RADIO_STATUS) {
|
||||
if (key == KEY_ENTER && (_page == HomePage::RADIO_STATUS
|
||||
#if UI_POCKET_GUI
|
||||
|| _page == HomePage::STATUS
|
||||
#endif
|
||||
)) {
|
||||
_radio_status_page++;
|
||||
return true;
|
||||
}
|
||||
@@ -1615,6 +1978,19 @@ public:
|
||||
#endif
|
||||
explicit MsgPreviewScreen(UITask* task)
|
||||
: _task(task), view_offset(0), channel_filter(CHANNEL_FILTER_ALL) {}
|
||||
#if UI_POCKET_GUI
|
||||
MessageHistory& pocketHistory() { return history; }
|
||||
const MessageHistory& pocketHistory() const { return history; }
|
||||
void addSent(int channel_idx, const char* channel_name, const char* sender,
|
||||
const char* text, size_t length) {
|
||||
char message[UI_MSG_PREVIEW_SIZE];
|
||||
if (length >= sizeof(message)) length = sizeof(message) - 1;
|
||||
memcpy(message, text, length);
|
||||
message[length] = 0;
|
||||
history.add(companionMessageNowMillis(), channel_idx, channel_name, sender,
|
||||
message, -1, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool hasMessages() const {
|
||||
for (size_t age = 0; age < history.count(); ++age)
|
||||
@@ -1952,6 +2328,10 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, CompanionNode
|
||||
#endif
|
||||
|
||||
_node_prefs = node_prefs;
|
||||
#if UI_POCKET_GUI
|
||||
the_mesh.loadPocketGuiSettings(_pocket_settings);
|
||||
if (_display) _display->forceFullRefresh();
|
||||
#endif
|
||||
|
||||
if (_display != NULL) {
|
||||
_display->servicePower(_board->isExternalPowered() || _board->isUsbHostConnected(), hasConnection());
|
||||
@@ -2031,6 +2411,50 @@ void UITask::renderMessageSummary(DisplayDriver& display) const {
|
||||
static_cast<const MsgPreviewScreen*>(msg_preview)->renderSummary(display);
|
||||
}
|
||||
|
||||
#if UI_POCKET_GUI
|
||||
void UITask::renderPocketBoard(mesh::ui::pocket::PocketGui& gui) const {
|
||||
ChannelDetails channel;
|
||||
char name[32] = {};
|
||||
if (the_mesh.getChannel(_pocket_settings.channel, channel))
|
||||
StrHelper::strncpy(name, channel.name, sizeof(name));
|
||||
gui.renderBoard(static_cast<MsgPreviewScreen*>(msg_preview)->pocketHistory(), name);
|
||||
}
|
||||
|
||||
unsigned UITask::pocketBoardCount() const {
|
||||
const auto& history = static_cast<const MsgPreviewScreen*>(msg_preview)->pocketHistory();
|
||||
unsigned count = 0;
|
||||
for (size_t age = 0; age < history.count(); ++age)
|
||||
if (history.newest(age)->channel_idx == _pocket_settings.channel) ++count;
|
||||
return count;
|
||||
}
|
||||
|
||||
void UITask::renderPocketInbox(mesh::ui::pocket::PocketGui& gui) const {
|
||||
const auto& history = static_cast<const MsgPreviewScreen*>(msg_preview)->pocketHistory();
|
||||
int y = gui.bodyTop() + 10;
|
||||
for (size_t age = 0; age < history.count() && y + 13 <= gui.bodyBottom(); ++age) {
|
||||
const auto* entry = history.newest(age);
|
||||
if (mesh::ui::displayPowerPrefs().inbox == mesh::ui::DisplayInboxMode::Pending
|
||||
&& entry->queue_index < 0) continue;
|
||||
if (mesh::ui::displayPowerPrefs().inbox == mesh::ui::DisplayInboxMode::Unread
|
||||
&& !entry->unread) continue;
|
||||
char label[48];
|
||||
mesh::ui::CompanionMessageHistory<32, UI_MSG_PREVIEW_SIZE>::threadLabel(*entry, label, sizeof(label));
|
||||
mesh::ui::pocket::truncateCharacters(label, 32);
|
||||
gui.label(4, y, label, entry->unread);
|
||||
y += 15;
|
||||
}
|
||||
if (y == gui.bodyTop() + 10) gui.label(4, y, "No messages");
|
||||
}
|
||||
|
||||
void UITask::channelMessageSent(int channel_idx, const char* channel_name,
|
||||
const char* sender, const char* text, size_t length) {
|
||||
if (!msg_preview || channel_idx < 0 || channel_idx >= MAX_GROUP_CHANNELS) return;
|
||||
static_cast<MsgPreviewScreen*>(msg_preview)->addSent(channel_idx, channel_name, sender, text, length);
|
||||
static_cast<HomeScreen*>(home)->pocketMessageAdded(channel_idx);
|
||||
if (_display && _display->isOn()) _next_refresh = millis();
|
||||
}
|
||||
#endif
|
||||
|
||||
void UITask::notify(UIEventType t) {
|
||||
#if defined(PIN_BUZZER)
|
||||
if (_notification_outputs & mesh::notify::Sound) switch(t){
|
||||
@@ -2079,6 +2503,9 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text,
|
||||
((MsgPreviewScreen *)msg_preview)
|
||||
->addPreview(path_len, from_name, text, channel_idx, channel_name,
|
||||
queue_index, !hasConnection());
|
||||
#if UI_POCKET_GUI
|
||||
static_cast<HomeScreen*>(home)->pocketMessageAdded(channel_idx);
|
||||
#endif
|
||||
if (hasConnection()) {
|
||||
// Keep history, but do not change the page or wake for a connected client.
|
||||
_deferred_msg_preview = false;
|
||||
@@ -2092,6 +2519,12 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text,
|
||||
// Queue incoming messages without stealing the reader's page.
|
||||
_deferred_msg_preview = true;
|
||||
}
|
||||
#endif
|
||||
#if UI_POCKET_GUI
|
||||
else if (channel_idx >= 0 && curr == home && static_cast<HomeScreen*>(home)->isPocketBoard()) {
|
||||
// Keep the live channel board visible while retaining normal notifications.
|
||||
_deferred_msg_preview = false;
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
setCurrScreen(msg_preview);
|
||||
@@ -2130,6 +2563,10 @@ void UITask::userLedHandler() {
|
||||
}
|
||||
|
||||
void UITask::setCurrScreen(UIScreen* c) {
|
||||
#if UI_POCKET_GUI
|
||||
if (curr == home && c != home) static_cast<HomeScreen*>(home)->flushPocketSettings();
|
||||
if (curr != c && _pocket_settings.dark && _display) _display->forceFullRefresh();
|
||||
#endif
|
||||
#if COMPANION_FEATURE_READER
|
||||
if (isReaderActive() && c != reader
|
||||
&& !static_cast<ReaderScreen*>(reader)->flush()) {
|
||||
@@ -2666,6 +3103,9 @@ char UITask::handleMultiClick(char c, bool backwards) {
|
||||
if (_display != NULL && (curr == msg_preview
|
||||
#if COMPANION_FEATURE_READER
|
||||
|| isReaderActive()
|
||||
#endif
|
||||
#if UI_POCKET_GUI
|
||||
|| (curr == home && static_cast<HomeScreen*>(home)->isPocketBoard())
|
||||
#endif
|
||||
)) {
|
||||
return checkDisplayOn(backwards ? KEY_UP : KEY_DOWN);
|
||||
|
||||
@@ -27,6 +27,10 @@
|
||||
#include "../AbstractUITask.h"
|
||||
#include "../NodePrefs.h"
|
||||
#include <helpers/CompanionReaderConfig.h>
|
||||
#if UI_POCKET_GUI
|
||||
#include <helpers/ui/PocketGuiSettings.h>
|
||||
namespace mesh { namespace ui { namespace pocket { class PocketGui; } } }
|
||||
#endif
|
||||
|
||||
class UITask : public AbstractUITask {
|
||||
DisplayDriver* _display;
|
||||
@@ -100,6 +104,9 @@ class UITask : public AbstractUITask {
|
||||
UIScreen* home;
|
||||
UIScreen* msg_preview = nullptr;
|
||||
UIScreen* curr;
|
||||
#if UI_POCKET_GUI
|
||||
mesh::ui::pocket::Settings _pocket_settings;
|
||||
#endif
|
||||
#if COMPANION_FEATURE_READER
|
||||
UIScreen* reader = nullptr;
|
||||
#endif
|
||||
@@ -148,6 +155,15 @@ public:
|
||||
int getMsgCount() const { return _msgcount; }
|
||||
int getPreviewCount() const;
|
||||
void renderMessageSummary(DisplayDriver& display) const;
|
||||
#if UI_POCKET_GUI
|
||||
mesh::ui::pocket::Settings& pocketSettings() { return _pocket_settings; }
|
||||
void renderPocketBoard(mesh::ui::pocket::PocketGui& gui) const;
|
||||
void renderPocketInbox(mesh::ui::pocket::PocketGui& gui) const;
|
||||
unsigned pocketBoardCount() const;
|
||||
void cleanPocketDisplay() { if (_display) _display->forceFullRefresh(); }
|
||||
void channelMessageSent(int channel_idx, const char* channel_name,
|
||||
const char* sender, const char* text, size_t length) override;
|
||||
#endif
|
||||
bool hasDisplay() const { return _display != NULL; }
|
||||
#ifdef HAS_TOUCH
|
||||
bool supportsTouchDebug() const override { return _display != nullptr; }
|
||||
|
||||
Reference in new issue
Block a user