Merge origin/keymindCascade with companion button hints
This commit is contained in:
commit
d89d28f7ed
78 files changed
+6858
-601
No files matched your search
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <helpers/CompanionJohnConfig.h>
|
||||
#include <helpers/ota/OtaMemoryPolicy.h>
|
||||
|
||||
// Features are selected independently so adding a transport or changing an
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#if MESH_CONTACT_CACHE && defined(ESP32_PLATFORM)
|
||||
#include <helpers/ContactFileTransaction.h>
|
||||
#endif
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
#include <helpers/bible/JohnBookmarkFiles.h>
|
||||
#endif
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
#include <helpers/AtomicFileWriter.h>
|
||||
@@ -389,6 +392,74 @@ File DataStore::openRead(const char* filename) {
|
||||
return openRead(_fs, filename);
|
||||
}
|
||||
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
namespace {
|
||||
class JohnBookmarkFiles {
|
||||
FILESYSTEM* _fs;
|
||||
public:
|
||||
explicit JohnBookmarkFiles(FILESYSTEM* fs) : _fs(fs) {}
|
||||
bool exists(const char* path) {
|
||||
#if defined(NRF52_PLATFORM)
|
||||
bool present = false;
|
||||
// Unknown presence must take the read/abort path, never the new-file path.
|
||||
return !contactPathPresence(_fs, path, present) || present;
|
||||
#else
|
||||
return _fs->exists(path);
|
||||
#endif
|
||||
}
|
||||
bool remove(const char* path) {
|
||||
#if defined(NRF52_PLATFORM)
|
||||
bool present = false;
|
||||
if (!contactPathPresence(_fs, path, present)) return false;
|
||||
return !present || _fs->remove(path);
|
||||
#else
|
||||
return !exists(path) || _fs->remove(path);
|
||||
#endif
|
||||
}
|
||||
bool rename(const char* from, const char* to) { return _fs->rename(from, to); }
|
||||
bool read(const char* path, uint8_t (&data)[mesh::bible::kBookmarkBytes]) {
|
||||
File file = mesh::openFileRead(_fs, path);
|
||||
if (!file) return false;
|
||||
if (file.size() != sizeof(data)) {
|
||||
// Known malformed record, not an I/O failure. Let the codec reject it
|
||||
// and permit a later verified replacement instead of trapping resume.
|
||||
memset(data, 0, sizeof(data));
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
const bool ok = file.read(data, sizeof(data)) == sizeof(data);
|
||||
file.close();
|
||||
return ok;
|
||||
}
|
||||
bool write(const char* path, const uint8_t (&data)[mesh::bible::kBookmarkBytes]) {
|
||||
File file = openWrite(_fs, path);
|
||||
if (!file) return false;
|
||||
const bool ok = file.write(data, sizeof(data)) == sizeof(data);
|
||||
file.flush();
|
||||
file.close();
|
||||
return ok;
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
bool DataStore::loadJohnBookmark(mesh::bible::Position& pos) {
|
||||
pos = mesh::bible::Position{};
|
||||
#if defined(NRF52_PLATFORM)
|
||||
if (_primary_storage_unavailable) return false;
|
||||
#endif
|
||||
JohnBookmarkFiles files(_fs);
|
||||
return mesh::bible::loadReaderBookmark(files, pos);
|
||||
}
|
||||
|
||||
bool DataStore::saveJohnBookmark(mesh::bible::Position pos) {
|
||||
#if defined(NRF52_PLATFORM)
|
||||
if (_primary_storage_unavailable) return false;
|
||||
#endif
|
||||
JohnBookmarkFiles files(_fs);
|
||||
return mesh::bible::saveReaderBookmark(files, pos);
|
||||
}
|
||||
#endif
|
||||
|
||||
File DataStore::openRead(FILESYSTEM* fs, const char* filename) {
|
||||
return mesh::openFileRead(fs, filename);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
#if MESH_CONTACT_CACHE
|
||||
#include <helpers/ContactSecretCache.h>
|
||||
#endif
|
||||
#include <helpers/CompanionJohnConfig.h>
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
#include <helpers/bible/JohnReader.h>
|
||||
#endif
|
||||
|
||||
class DataStoreHost {
|
||||
public:
|
||||
@@ -102,6 +106,10 @@ public:
|
||||
bool loadPrefs(CompanionNodePrefs& prefs, double& node_lat,
|
||||
double& node_lon);
|
||||
bool savePrefs(const CompanionNodePrefs& prefs, double node_lat, double node_lon);
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
bool loadJohnBookmark(mesh::bible::Position& pos);
|
||||
bool saveJohnBookmark(mesh::bible::Position pos);
|
||||
#endif
|
||||
void loadContacts(DataStoreHost* host);
|
||||
bool saveContacts(DataStoreHost* host, bool (*filter)(const ContactInfo& c) = NULL);
|
||||
bool markContactDirty(const ContactInfo& contact);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <Mesh.h>
|
||||
#include <helpers/CompanionHardwareCommandCompat.h>
|
||||
#include <helpers/CompanionStatusResponse.h>
|
||||
#include <helpers/CompanionJohn.h>
|
||||
#include <helpers/IdentityGeneration.h>
|
||||
#include <helpers/LazyPersistence.h>
|
||||
#include <helpers/StorageLayout.h>
|
||||
@@ -7141,6 +7142,10 @@ void MyMesh::handleTerminalCommand(char* command) {
|
||||
if (*command == 0) return;
|
||||
mesh::cli::normalizeCommandVerb(command);
|
||||
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
if (mesh::handleJohnCommand(command, terminalOutput())) return;
|
||||
#endif
|
||||
|
||||
char local_reply[160];
|
||||
#if COMPANION_FEATURE_USB_MOTA_SOURCE
|
||||
const bool usb_mota_owner_transition =
|
||||
@@ -7677,6 +7682,9 @@ void MyMesh::handleTerminalCommand(char* command) {
|
||||
terminalOutput().print(" board\r\n");
|
||||
terminalOutput().print(" version\r\n");
|
||||
terminalOutput().print(" get storage.layout\r\n");
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
terminalOutput().print(" get John <chapter>:<verse> (World English Bible, offline)\r\n");
|
||||
#endif
|
||||
terminalOutput().print(" get pwrmgt.bootreason\r\n");
|
||||
#if COMPANION_FEATURE_MEMORY_DIAGNOSTICS
|
||||
terminalOutput().print(" memory\r\n");
|
||||
|
||||
@@ -319,6 +319,10 @@ public:
|
||||
if (saved) _prefs.clearDirty();
|
||||
return saved;
|
||||
}
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
bool loadJohnBookmark(mesh::bible::Position& pos) { return _store->loadJohnBookmark(pos); }
|
||||
bool saveJohnBookmark(mesh::bible::Position pos) { return _store->saveJohnBookmark(pos); }
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
void applyGpsPrefs() {
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
#pragma once
|
||||
#include <helpers/CompanionJohn.h>
|
||||
#include <helpers/bible/JohnReader.h>
|
||||
#if UI_SMALL_MESSAGE_FONT
|
||||
#include <helpers/ui/SmallMessageText.h>
|
||||
#endif
|
||||
|
||||
// Included by UITask.cpp after the task and MyMesh declarations. Only a small
|
||||
// cursor/checkpoint object persists; the 2 KiB decode buffer is on demand.
|
||||
class JohnReaderScreen : public UIScreen {
|
||||
UITask* _task;
|
||||
DisplayDriver* _display;
|
||||
mesh::bible::ReaderBookmark _bookmark;
|
||||
uint32_t _retry_at = 0;
|
||||
bool _loaded = false;
|
||||
|
||||
__attribute__((noinline)) void process(int direction, bool draw) {
|
||||
using namespace mesh::bible;
|
||||
char scratch[kBlockSize];
|
||||
const char* text = nullptr;
|
||||
Position pos = _bookmark.position();
|
||||
_display->setCompactText(false);
|
||||
_display->setTextSize(1);
|
||||
const int width = _display->width();
|
||||
const int header_height = _display->textLineHeight();
|
||||
// Narrow/rotated panels need separate reference and progress lines.
|
||||
const bool stacked_header = width < _display->getTextWidth("88:88")
|
||||
+ _display->getTextWidth("88/88") + 4;
|
||||
const int top = header_height * (stacked_header ? 2 : 1) + 2;
|
||||
#if UI_SMALL_MESSAGE_FONT
|
||||
// Share message font selection and metrics, including rotated/tiny panels.
|
||||
mesh::ui::SmallMessageText compact(*_display);
|
||||
const bool small = _display->useSmallMessageFont();
|
||||
DisplayDriver& body = small ? static_cast<DisplayDriver&>(compact) : *_display;
|
||||
const int line_height = small ? compact.lineHeight() : header_height;
|
||||
int rows = small ? compact.lineCount(top) : (_display->height() - top) / line_height;
|
||||
#else
|
||||
DisplayDriver& body = *_display;
|
||||
const int line_height = header_height;
|
||||
int rows = (_display->height() - top) / line_height;
|
||||
#endif
|
||||
if (rows < 1) rows = 1;
|
||||
auto measure = [&body](const char* line) {
|
||||
char filtered[kReaderLineBytes];
|
||||
body.translateUTF8ToBlocks(filtered, line, sizeof(filtered));
|
||||
return body.getTextWidth(filtered);
|
||||
};
|
||||
|
||||
// At most two lookups: the current verse, then its adjacent verse when
|
||||
// navigation crosses a boundary. No recursive decode or second buffer.
|
||||
for (int pass = 0; pass < 2; ++pass) {
|
||||
const LookupResult result = mesh::readJohnVerse(
|
||||
referenceAt(pos.verse), scratch, sizeof(scratch), text);
|
||||
if (result != LookupResult::Found) {
|
||||
if (draw) {
|
||||
_display->setColor(UIColor::warning_txt);
|
||||
_display->setCursor(0, top);
|
||||
_display->print("John unavailable");
|
||||
} else _task->showAlert("John data error", 1500);
|
||||
return;
|
||||
}
|
||||
memmove(scratch, text, strlen(text) + 1);
|
||||
const ReaderPage page = readerPage(scratch, pos.offset, width, rows, measure);
|
||||
pos.offset = page.start; // clamp stale bookmarks after a layout change
|
||||
if (direction > 0) {
|
||||
if (scratch[page.next]) pos.offset = page.next;
|
||||
else if (pos.verse + 1 < kVerseCount) { ++pos.verse; pos.offset = 0; }
|
||||
direction = 0;
|
||||
continue;
|
||||
}
|
||||
if (direction < 0) {
|
||||
if (page.start) pos.offset = page.previous;
|
||||
else if (pos.verse) { --pos.verse; pos.offset = kBlockSize - 1; }
|
||||
direction = 0;
|
||||
continue;
|
||||
}
|
||||
_bookmark.move(pos, millis());
|
||||
if (!draw) return;
|
||||
char label[32], progress[16];
|
||||
const Reference ref = referenceAt(pos.verse);
|
||||
snprintf(label, sizeof(label), "John %u:%u WEB", ref.chapter, ref.verse);
|
||||
snprintf(progress, sizeof(progress), "%u/%u", page.part, page.parts);
|
||||
const int progress_width = _display->getTextWidth(progress);
|
||||
if (stacked_header || _display->getTextWidth(label) > width - progress_width - 4)
|
||||
snprintf(label, sizeof(label), "%u:%u", ref.chapter, ref.verse);
|
||||
_display->setColor(UIColor::title_txt);
|
||||
_display->drawTextEllipsized(0, 0, stacked_header ? width : width - progress_width - 4, label);
|
||||
_display->drawTextRightAlign(width, stacked_header ? header_height : 0, progress);
|
||||
_display->drawRect(0, top - 2, width, 1);
|
||||
body.setColor(UIColor::primary_txt);
|
||||
uint16_t offset = page.start;
|
||||
for (int row = 0; row < rows && scratch[offset]; ++row) {
|
||||
char line[kReaderLineBytes], filtered[kReaderLineBytes];
|
||||
offset = readerLine(scratch, offset, width, measure, line);
|
||||
body.translateUTF8ToBlocks(filtered, line, sizeof(filtered));
|
||||
body.setCursor(0, top + row * line_height);
|
||||
body.print(filtered);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
JohnReaderScreen(UITask* task, DisplayDriver* display) : _task(task), _display(display) {}
|
||||
void open() {
|
||||
if (!_loaded) {
|
||||
mesh::bible::Position pos;
|
||||
the_mesh.loadJohnBookmark(pos);
|
||||
_bookmark.restore(pos);
|
||||
_loaded = true;
|
||||
}
|
||||
}
|
||||
bool flush() {
|
||||
if (!_bookmark.dirty()) return true;
|
||||
if (!the_mesh.saveJohnBookmark(_bookmark.position())) {
|
||||
_retry_at = millis() + 30000;
|
||||
return false;
|
||||
}
|
||||
_bookmark.saved();
|
||||
_retry_at = 0;
|
||||
return true;
|
||||
}
|
||||
void poll() override {
|
||||
const uint32_t now = millis();
|
||||
if (_bookmark.due(now) && (!_retry_at || int32_t(now - _retry_at) >= 0)) flush();
|
||||
}
|
||||
int render(DisplayDriver&) override { process(0, true); return 5000; }
|
||||
bool handleInput(char c) override {
|
||||
const uint8_t key = static_cast<uint8_t>(c);
|
||||
if (key == KEY_NEXT || key == KEY_RIGHT) { process(1, false); return true; }
|
||||
if (key == KEY_PREV || key == KEY_LEFT) { process(-1, false); return true; }
|
||||
if (key == KEY_ENTER || key == KEY_CANCEL) { _task->closeJohnReader(); return true; }
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -12,6 +12,10 @@
|
||||
#include "../MyMesh.h"
|
||||
#include "../CompanionWiFi.h"
|
||||
#include "target.h"
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
#include "JohnReaderScreen.h"
|
||||
#include <new>
|
||||
#endif
|
||||
#include <time.h>
|
||||
#ifdef WIFI_SSID
|
||||
#include <WiFi.h>
|
||||
@@ -550,6 +554,9 @@ public:
|
||||
}
|
||||
|
||||
void showFirstPage() { _page = HomePage::FIRST; }
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
bool isRadioPage() const { return _page == HomePage::RADIO; }
|
||||
#endif
|
||||
|
||||
bool isTransportSelectorPage() const {
|
||||
#ifdef COMPANION_EXCLUSIVE_WIFI_BLE
|
||||
@@ -589,8 +596,14 @@ public:
|
||||
}
|
||||
|
||||
int render(DisplayDriver& display) override {
|
||||
display.setTextSize(1);
|
||||
const int normal_line = !display.useSmallMessageFont()
|
||||
&& display.renderWidth() == display.width() ? display.textLineHeight() : 11;
|
||||
const int row_height = normal_line > 11 ? normal_line : 11;
|
||||
const int header_height = row_height + 1;
|
||||
const int body_top = header_height + 8;
|
||||
display.setColor(UIColor::title_bkg);
|
||||
display.fillRect(0, 0, display.width(), 12);
|
||||
display.fillRect(0, 0, display.width(), header_height);
|
||||
char tmp[80];
|
||||
// status indicators
|
||||
display.setTextSize(1);
|
||||
@@ -614,7 +627,7 @@ public:
|
||||
// equal-background branch above and retain their light text colour.
|
||||
display.setColor(UIColor::corp_blue);
|
||||
}
|
||||
int y = 14;
|
||||
int y = header_height + 2;
|
||||
int x = display.width() / 2 - 5 * (HomePage::Count-1);
|
||||
for (uint8_t i = 0; i < HomePage::Count; i++, x += 10) {
|
||||
if (i == _page) {
|
||||
@@ -637,12 +650,12 @@ public:
|
||||
} else {
|
||||
sprintf(tmp, "INBOX: %d", _task->getPreviewCount());
|
||||
display.setTextSize(2);
|
||||
display.drawTextCentered(display.width() / 2, 22, tmp);
|
||||
display.drawTextCentered(display.width() / 2, body_top + 2, tmp);
|
||||
}
|
||||
#else
|
||||
display.setTextSize(2);
|
||||
sprintf(tmp, "INBOX: %d", _task->getPreviewCount());
|
||||
display.drawTextCentered(display.width() / 2, 22, tmp);
|
||||
display.drawTextCentered(display.width() / 2, body_top + 2, tmp);
|
||||
#endif
|
||||
#ifdef UI_DEDICATED_PAIRING_BLOCK
|
||||
const mesh::ui::CompanionHomeLayout layout =
|
||||
@@ -852,8 +865,8 @@ public:
|
||||
} else if (_page == HomePage::RECENT) {
|
||||
the_mesh.getRecentlyHeard(recent, UI_RECENT_LIST_SIZE);
|
||||
display.setColor(UIColor::primary_txt);
|
||||
int y = 20;
|
||||
for (int i = 0; i < UI_RECENT_LIST_SIZE; i++, y += 11) {
|
||||
int y = body_top;
|
||||
for (int i = 0; i < UI_RECENT_LIST_SIZE && y + row_height <= display.height(); i++, y += row_height) {
|
||||
auto a = &recent[i];
|
||||
if (a->name[0] == 0) continue; // empty slot
|
||||
int secs = _rtc->getCurrentTime() - a->recv_timestamp;
|
||||
@@ -878,19 +891,19 @@ public:
|
||||
display.setColor(UIColor::primary_txt);
|
||||
display.setTextSize(1);
|
||||
// freq / sf
|
||||
display.setCursor(0, 20);
|
||||
display.setCursor(0, body_top);
|
||||
sprintf(tmp, "FQ: %06.3f SF: %d", _node_prefs->freq, _node_prefs->sf);
|
||||
display.print(tmp);
|
||||
|
||||
display.setCursor(0, 31);
|
||||
display.setCursor(0, body_top + row_height);
|
||||
sprintf(tmp, "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr);
|
||||
display.print(tmp);
|
||||
|
||||
// tx power, noise floor
|
||||
display.setCursor(0, 42);
|
||||
display.setCursor(0, body_top + 2 * row_height);
|
||||
sprintf(tmp, "TX: %ddBm", _node_prefs->tx_power_dbm);
|
||||
display.print(tmp);
|
||||
display.setCursor(0, 53);
|
||||
display.setCursor(0, body_top + 3 * row_height);
|
||||
float noise_floor = radio_driver.getNoiseFloorDbm();
|
||||
if (noise_floor == 0.0f) {
|
||||
strcpy(tmp, "Noise floor: measuring");
|
||||
@@ -940,23 +953,23 @@ public:
|
||||
#else
|
||||
} else if (_page == HomePage::BLUETOOTH) {
|
||||
display.setColor(UIColor::corp_blue);
|
||||
display.drawXbm((display.width() - 32) / 2, 18,
|
||||
display.drawXbm((display.width() - 32) / 2, body_top - 2,
|
||||
_task->isBluetoothEnabled() ? bluetooth_on : bluetooth_off,
|
||||
32, 32);
|
||||
display.setColor(UIColor::secondary_txt);
|
||||
display.setTextSize(1);
|
||||
display.drawTextCentered(display.width() / 2, 64 - 11, "toggle: " PRESS_LABEL);
|
||||
display.drawTextCentered(display.width() / 2, body_top + 33, "toggle: " PRESS_LABEL);
|
||||
#endif
|
||||
} else if (_page == HomePage::ADVERT) {
|
||||
display.setColor(UIColor::corp_blue);
|
||||
display.drawXbm((display.width() - 32) / 2, 18, advert_icon, 32, 32);
|
||||
display.drawXbm((display.width() - 32) / 2, body_top - 2, advert_icon, 32, 32);
|
||||
display.setColor(UIColor::secondary_txt);
|
||||
display.drawTextCentered(display.width() / 2, 64 - 11, "advert: " PRESS_LABEL);
|
||||
display.drawTextCentered(display.width() / 2, body_top + 33, "advert: " PRESS_LABEL);
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
} else if (_page == HomePage::GPS) {
|
||||
LocationProvider* nmea = sensors.getLocationProvider();
|
||||
char buf[50];
|
||||
int y = 18;
|
||||
int y = body_top - 2;
|
||||
bool gps_state = _task->getGPSState();
|
||||
#ifdef PIN_GPS_SWITCH
|
||||
bool hw_gps_state = digitalRead(PIN_GPS_SWITCH);
|
||||
@@ -971,38 +984,38 @@ public:
|
||||
display.setColor(UIColor::primary_txt);
|
||||
display.drawTextLeftAlign(0, y, buf);
|
||||
if (nmea == NULL) {
|
||||
y = y + 12;
|
||||
y += row_height > 12 ? row_height : 12;
|
||||
display.setColor(UIColor::secondary_txt);
|
||||
display.drawTextLeftAlign(0, y, "Can't access GPS");
|
||||
} else {
|
||||
display.setColor(UIColor::primary_txt);
|
||||
strcpy(buf, nmea->isValid()?"fix":"no fix");
|
||||
display.drawTextRightAlign(display.width()-1, y, buf);
|
||||
y = y + 12;
|
||||
y += row_height > 12 ? row_height : 12;
|
||||
display.setColor(UIColor::secondary_txt);
|
||||
display.drawTextLeftAlign(0, y, "sat");
|
||||
display.setColor(UIColor::primary_txt);
|
||||
sprintf(buf, "%d", nmea->satellitesCount());
|
||||
display.drawTextRightAlign(display.width()-1, y, buf);
|
||||
y = y + 12;
|
||||
y += row_height > 12 ? row_height : 12;
|
||||
display.setColor(UIColor::secondary_txt);
|
||||
display.drawTextLeftAlign(0, y, "pos");
|
||||
display.setColor(UIColor::primary_txt);
|
||||
sprintf(buf, "%.4f %.4f",
|
||||
nmea->getLatitude()/1000000., nmea->getLongitude()/1000000.);
|
||||
display.drawTextRightAlign(display.width()-1, y, buf);
|
||||
y = y + 12;
|
||||
y += row_height > 12 ? row_height : 12;
|
||||
display.setColor(UIColor::secondary_txt);
|
||||
display.drawTextLeftAlign(0, y, "alt");
|
||||
display.setColor(UIColor::primary_txt);
|
||||
sprintf(buf, "%.2f", nmea->getAltitude()/1000.);
|
||||
display.drawTextRightAlign(display.width()-1, y, buf);
|
||||
y = y + 12;
|
||||
y += row_height > 12 ? row_height : 12;
|
||||
}
|
||||
#endif
|
||||
#if UI_SENSORS_PAGE == 1
|
||||
} else if (_page == HomePage::SENSORS) {
|
||||
int y = 18;
|
||||
int y = body_top - 2;
|
||||
refresh_sensors();
|
||||
if (sensors_lpp.getBuffer() == nullptr) {
|
||||
display.setColor(UIColor::warning_txt);
|
||||
@@ -1075,7 +1088,7 @@ public:
|
||||
display.width()-display.getTextWidth(buf)-1, y
|
||||
);
|
||||
display.print(buf);
|
||||
y = y + 12;
|
||||
y += row_height > 12 ? row_height : 12;
|
||||
}
|
||||
if (sensors_scroll) sensors_scroll_offset = (sensors_scroll_offset+1)%sensors_nb;
|
||||
else sensors_scroll_offset = 0;
|
||||
@@ -1113,6 +1126,12 @@ public:
|
||||
_page = (_page + HomePage::Count - 1) % HomePage::Count;
|
||||
return true;
|
||||
}
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
if (c == KEY_ENTER && _page == HomePage::RADIO) {
|
||||
_task->showJohnReader();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
if (c == KEY_NEXT || c == KEY_RIGHT) {
|
||||
_page = (_page + 1) % HomePage::Count;
|
||||
if (_page == HomePage::RECENT) {
|
||||
@@ -1330,9 +1349,12 @@ class MsgPreviewScreen : public UIScreen {
|
||||
|
||||
void renderChannelFilter(DisplayDriver& display) const {
|
||||
#if UI_MESSAGE_CHANNEL_FOOTER == 1
|
||||
display.setTextSize(1);
|
||||
const mesh::ui::CompanionMessageChromeLayout layout =
|
||||
mesh::ui::makeCompanionMessageChromeLayout(
|
||||
UI_COMPACT_MESSAGE_STATUS == 1);
|
||||
UI_COMPACT_MESSAGE_STATUS == 1,
|
||||
!display.useSmallMessageFont() && display.renderWidth() == display.width()
|
||||
? display.textLineHeight() : 0);
|
||||
const int bar_height = layout.filter_height;
|
||||
const int bar_y = display.height() - bar_height;
|
||||
display.setColor(UIColor::window_bkg);
|
||||
@@ -1386,8 +1408,11 @@ public:
|
||||
}
|
||||
|
||||
void renderSummary(DisplayDriver& display) const {
|
||||
display.setTextSize(1);
|
||||
const mesh::ui::CompanionMessageListLayout layout =
|
||||
mesh::ui::makeCompanionMessageListLayout(display.height());
|
||||
mesh::ui::makeCompanionMessageListLayout(display.height(),
|
||||
!display.useSmallMessageFont() && display.renderWidth() == display.width()
|
||||
? display.textLineHeight() : 10);
|
||||
int rendered = 0;
|
||||
|
||||
display.setTextSize(1);
|
||||
@@ -1443,25 +1468,34 @@ public:
|
||||
}
|
||||
|
||||
int render(DisplayDriver& display) override {
|
||||
// Native larger panels retain their normal font and line metrics.
|
||||
// Leave the Indicator's scaled chrome unchanged.
|
||||
display.setTextSize(1);
|
||||
const bool native_large = !display.useSmallMessageFont()
|
||||
&& display.renderWidth() == display.width();
|
||||
mesh::ui::CompanionMessageChromeLayout layout =
|
||||
mesh::ui::makeCompanionMessageChromeLayout(
|
||||
UI_COMPACT_MESSAGE_STATUS == 1);
|
||||
mesh::ui::makeCompanionMessageChromeLayout(UI_COMPACT_MESSAGE_STATUS == 1,
|
||||
native_large ? display.textLineHeight() : 0);
|
||||
int body_bottom = UI_MESSAGE_CHANNEL_FOOTER == 1
|
||||
? display.height() - layout.filter_height : display.height();
|
||||
display.setCompactText(layout.compact_text);
|
||||
display.setTextSize(1);
|
||||
#if UI_BUTTON_READER_HINT == 1
|
||||
#if UI_SMALL_MESSAGE_FONT == 1
|
||||
mesh::ui::SmallMessageText reader_text(display);
|
||||
mesh::ui::SmallMessageText compact(display);
|
||||
const bool small = display.useSmallMessageFont();
|
||||
DisplayDriver& reader_text = small
|
||||
? static_cast<DisplayDriver&>(compact) : display;
|
||||
// Eight-pixel rows for the header and origin leave five message rows and
|
||||
// a navigation row on a 128x64 V4. Keep the 5px font on tiny panels.
|
||||
const int hint_line_height = reader_text.lineHeight();
|
||||
layout.header_divider_y = hint_line_height - 1;
|
||||
layout.origin_y = hint_line_height;
|
||||
layout.message_y = 2 * hint_line_height;
|
||||
const int hint_line_height = small ? compact.lineHeight() : display.textLineHeight();
|
||||
if (small) {
|
||||
layout.header_divider_y = hint_line_height - 1;
|
||||
layout.origin_y = hint_line_height;
|
||||
layout.message_y = 2 * hint_line_height;
|
||||
}
|
||||
#else
|
||||
DisplayDriver& reader_text = display;
|
||||
const int hint_line_height = layout.message_y - layout.origin_y;
|
||||
const int hint_line_height = display.textLineHeight();
|
||||
#endif
|
||||
const mesh::ui::ButtonReaderHintLayout hint =
|
||||
mesh::ui::makeButtonReaderHintLayout(
|
||||
@@ -1526,14 +1560,13 @@ public:
|
||||
display.setColor(UIColor::primary_txt);
|
||||
char filtered_msg[sizeof(p->message)];
|
||||
display.translateUTF8ToBlocks(filtered_msg, p->message, sizeof(filtered_msg));
|
||||
#if UI_BUTTON_READER_HINT == 1
|
||||
const int line_height = layout.message_y - layout.origin_y;
|
||||
const int message_rows = (body_bottom - layout.message_y) / line_height;
|
||||
mesh::ui::drawTextWrapped(display, 0, layout.message_y, display.width(),
|
||||
line_height, message_rows, filtered_msg);
|
||||
#else
|
||||
display.printWordWrap(filtered_msg, display.width());
|
||||
#endif
|
||||
if (native_large || UI_BUTTON_READER_HINT == 1) {
|
||||
mesh::ui::drawTextWrapped(display, 0, layout.message_y, display.width(),
|
||||
display.textLineHeight(), (body_bottom - layout.message_y) / display.textLineHeight(),
|
||||
filtered_msg);
|
||||
} else {
|
||||
display.printWordWrap(filtered_msg, display.width());
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UI_BUTTON_READER_HINT == 1
|
||||
@@ -1644,6 +1677,24 @@ void UITask::showMessages() {
|
||||
setCurrScreen(msg_preview);
|
||||
}
|
||||
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
void UITask::showJohnReader() {
|
||||
if (!_display || isPairingScreenActive()) return;
|
||||
if (!_display->isOn()) _display->turnOn();
|
||||
if (!john_reader) john_reader = new (std::nothrow) JohnReaderScreen(this, _display);
|
||||
if (!john_reader) { showAlert("Reader: no memory", 1500); return; }
|
||||
static_cast<JohnReaderScreen*>(john_reader)->open();
|
||||
setCurrScreen(john_reader);
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
}
|
||||
|
||||
void UITask::closeJohnReader() {
|
||||
// Home retains the selected radio page while the reader is open.
|
||||
setCurrScreen(home);
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
}
|
||||
#endif
|
||||
|
||||
int UITask::getPreviewCount() const {
|
||||
return static_cast<const MsgPreviewScreen*>(msg_preview)->messageCount();
|
||||
}
|
||||
@@ -1688,7 +1739,11 @@ void UITask::msgRead(int msgcount) {
|
||||
_deferred_msg_preview = false;
|
||||
const bool holding_usb_preview = curr == msg_preview && _msg_preview_until != 0
|
||||
&& static_cast<int32_t>(millis() - _msg_preview_until) < 0;
|
||||
if (!holding_usb_preview) {
|
||||
if (!holding_usb_preview
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
&& !isJohnReaderActive()
|
||||
#endif
|
||||
) {
|
||||
gotoHomeScreen();
|
||||
}
|
||||
}
|
||||
@@ -1705,7 +1760,14 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text,
|
||||
// Keep the PIN visible, but retain the preview so it can be shown after
|
||||
// pairing completes or the pairing display window expires.
|
||||
_deferred_msg_preview = true;
|
||||
} else {
|
||||
}
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
else if (isJohnReaderActive()) {
|
||||
// Queue incoming messages without stealing the reader's page.
|
||||
_deferred_msg_preview = true;
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
setCurrScreen(msg_preview);
|
||||
}
|
||||
|
||||
@@ -1750,6 +1812,12 @@ void UITask::userLedHandler() {
|
||||
}
|
||||
|
||||
void UITask::setCurrScreen(UIScreen* c) {
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
if (isJohnReaderActive() && c != john_reader
|
||||
&& !static_cast<JohnReaderScreen*>(john_reader)->flush()) {
|
||||
showAlert("Bookmark save failed", 1500);
|
||||
}
|
||||
#endif
|
||||
curr = c;
|
||||
_next_refresh = 100;
|
||||
}
|
||||
@@ -1832,6 +1900,9 @@ void UITask::servicePairingState() {
|
||||
*/
|
||||
void UITask::shutdown(bool restart){
|
||||
if (!prepareForShutdown()) return;
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
if (john_reader) static_cast<JohnReaderScreen*>(john_reader)->flush();
|
||||
#endif
|
||||
|
||||
#ifdef PIN_BUZZER
|
||||
/* note: we have a choice here -
|
||||
@@ -1899,6 +1970,11 @@ void UITask::loop() {
|
||||
if (ev == BUTTON_EVENT_CLICK) {
|
||||
c = checkDisplayOn(KEY_ENTER);
|
||||
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
if (isJohnReaderActive() || (curr == home && static_cast<HomeScreen*>(home)->isRadioPage()))
|
||||
c = handleLongPress(KEY_ENTER);
|
||||
else
|
||||
#endif
|
||||
display.turnOff();
|
||||
} else if (ev == BUTTON_EVENT_DOUBLE_CLICK) {
|
||||
c = handleDoubleClick(KEY_SELECT);
|
||||
@@ -2039,6 +2115,9 @@ void UITask::loop() {
|
||||
#endif
|
||||
|
||||
if (curr) curr->poll();
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
if (john_reader && curr != john_reader) john_reader->poll();
|
||||
#endif
|
||||
|
||||
if (_msgcount == 0 && _msg_preview_until != 0
|
||||
&& static_cast<int32_t>(millis() - _msg_preview_until) >= 0) {
|
||||
@@ -2080,6 +2159,9 @@ void UITask::loop() {
|
||||
if (user_btn.isWakeHoldActive()) _auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
#endif
|
||||
if (!isPairingScreenActive() && isDisplayAutoOffDue(_auto_off, AUTO_OFF_MILLIS)) {
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
if (isJohnReaderActive()) static_cast<JohnReaderScreen*>(john_reader)->flush();
|
||||
#endif
|
||||
_display->turnOff();
|
||||
}
|
||||
#endif
|
||||
@@ -2127,6 +2209,15 @@ char UITask::handleLongPress(char c) {
|
||||
// Exit an incoming message preview even during the startup rescue window.
|
||||
// The on-screen reader hint must not unexpectedly enter CLI rescue.
|
||||
if (curr == msg_preview) return c;
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
// The radio page's reader gesture, including exit, takes precedence over
|
||||
// the global early-boot rescue gesture just like the WiFi setup page.
|
||||
if (isJohnReaderActive()) { closeJohnReader(); return 0; }
|
||||
if (curr == home && static_cast<HomeScreen*>(home)->isRadioPage()) {
|
||||
showJohnReader();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#if UI_WIFI_SETUP_HOME_PAGE == 1
|
||||
// A setup AP may focus this page immediately at boot. Its documented HOLD
|
||||
// action must win over the otherwise-global early-boot CLI rescue gesture.
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "../AbstractUITask.h"
|
||||
#include "../NodePrefs.h"
|
||||
#include <helpers/CompanionJohnConfig.h>
|
||||
|
||||
class UITask : public AbstractUITask {
|
||||
DisplayDriver* _display;
|
||||
@@ -84,6 +85,9 @@ class UITask : public AbstractUITask {
|
||||
UIScreen* home;
|
||||
UIScreen* msg_preview;
|
||||
UIScreen* curr;
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
UIScreen* john_reader = nullptr;
|
||||
#endif
|
||||
|
||||
void userLedHandler();
|
||||
|
||||
@@ -119,6 +123,11 @@ public:
|
||||
|
||||
void gotoHomeScreen() { setCurrScreen(home); }
|
||||
void showMessages();
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
bool isJohnReaderActive() const { return john_reader && curr == john_reader; }
|
||||
void showJohnReader();
|
||||
void closeJohnReader();
|
||||
#endif
|
||||
void showAlert(const char* text, int duration_millis);
|
||||
int getMsgCount() const { return _msgcount; }
|
||||
int getPreviewCount() const;
|
||||
|
||||
Reference in new issue
Block a user