fix: review pass - Discover's late replies dropped and its way back usable, the Gallery's newest first and faster, the network clock's toast

- Discover: a reply after its try timed out, was stopped or was overtaken
  went on to the normal handling and became the contact's route (and sent
  a path back); the last tags sent are kept and a late reply is dropped.
  Leaving Route on the L2 stops a discovery as it stops a trace.
- Discover: a route whose reply came back another way offers that way too
  (L2 There / Back, L1 a Back row), turned round into a route there, so a
  trace checks it; the Discover button no longer sits on its group.
- Screenshots: numbered one past the highest (one pass over the folder,
  not a stat per number), so one taken after a delete is still the newest.
- Gallery: the newest 300 kept whatever order the folder lists them in;
  BMP rows read in the file's order and several at a time; the thumbnail
  buffer sized to the page; the folder read once per visit; a failed
  open frees or restores the picture.
- NTP: the slot the router's server goes in emptied before joining, so a
  cached address isn't taken for it; "Clock set from the network" judged
  against the clock a tick before (SNTP has set the system time already).
- Sim: sim_scroll up stops at the top.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-10-29 16:30:19 +01:00
co-authored by Claude Opus 5.5
parent e154a4e721
commit 3a26a8bee7
11 changed files with 171 additions and 65 deletions
+17 -10
View File
@@ -948,14 +948,19 @@ void UITask::takeScreenshot() {
if (!lvport::mountStorage()) { showToast("No SD card"); return; }
mkdir("/sdcard", 0777); // the sim's MEMFS may not have it yet (the card: fails, harmless)
mkdir("/sdcard/screenshots", 0777);
char path[48];
struct stat st;
int n = 1;
for (; n <= 9999; n++) {
snprintf(path, sizeof(path), "/sdcard/screenshots/scr_%04d.bmp", n);
if (stat(path, &st) != 0) break;
// One past the highest number: a deleted one's isn't reused, so the newest
// stays first in the Gallery (one pass over the folder, not a stat a file).
int n = 0;
if (DIR* d = opendir("/sdcard/screenshots")) {
while (struct dirent* de = readdir(d)) {
int k;
if (sscanf(de->d_name, "scr_%4d", &k) == 1 && k > n) n = k;
}
closedir(d);
}
if (n > 9999) { showToast("Screenshots folder full"); return; }
if (++n > 9999) { showToast("Screenshots folder full"); return; }
char path[48];
snprintf(path, sizeof(path), "/sdcard/screenshots/scr_%04d.bmp", n);
int W, H;
uint16_t* px = captureFrame(W, H);
if (!px) { showToast("Out of memory"); return; }
@@ -1249,8 +1254,9 @@ void UITask::back() {
case SCR_BOT: if (_nav_overlay) navClosePopup(); else showHome(); break;
case SCR_DIAG: if (_nav_overlay) navClosePopup(); else showHome(); break;
case SCR_ADMIN_PICK: showHome(); break;
case SCR_ROUTE: // back to the node; a trace in flight is dropped
case SCR_ROUTE: // back to the node; a trace or discovery in flight is dropped
_core->route.cancelTrace();
_core->route.stopDiscover();
_screen = SCR_NODE;
buildNode();
break;
@@ -1527,8 +1533,9 @@ extern "C" EMSCRIPTEN_KEEPALIVE int sim_scroll(int dy) {
dbgScrollable(lv_layer_top(), o, h);
if (!o) dbgScrollable(lv_screen_active(), o, h);
if (!o) return -1;
int left = lv_obj_get_scroll_bottom(o);
lv_obj_scroll_by(o, 0, -(dy < left ? dy : left), LV_ANIM_OFF);
int left = dy >= 0 ? lv_obj_get_scroll_bottom(o) : lv_obj_get_scroll_top(o); // up: no further than the top
const int step = dy >= 0 ? (dy < left ? dy : left) : (-dy < left ? dy : -left);
lv_obj_scroll_by(o, 0, -step, LV_ANIM_OFF);
return left;
}
#endif