From 4d3ff959e0e5ab94aede5b94c4019e207089a72b Mon Sep 17 00:00:00 2001 From: brianhealey Date: Mon, 31 Aug 2026 18:48:48 +0200 Subject: [PATCH] Implement LinuxBoard::sleep() to stop the main loop busy-spinning `mesh::MainBoard::sleep()` is a no-op by default and `LinuxBoard` never overrode it, so `board.sleep(0)`/`sleep(30)` returned immediately and the repeater loop spun a core at 100%. Only `NRF52Board` and `ESP32Board` implement it. Implement it with `sleep()`/`usleep()`, and add a `delay(1)` in the main loop's non-powersaving branch so platforms without power management do not spin either. Reported and fixed by brianhealey, measured at 99% -> 0-9% CPU on a Pi Compute Module 5 with an SX1262. Cherry-picked from l5yth/meshcore-linux#21, which could not be merged. (cherry picked from commit 11d6ddfc) --- examples/simple_repeater/main.cpp | 3 +++ variants/linux/LinuxBoard.h | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 2484ca9ba5..a556062881 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -209,5 +209,8 @@ void loop() { board.sleep(30); // Sleep. Wake up after a while or when receiving a LoRa packet } #endif + } else { + // Small delay to prevent busy loop on platforms without power saving + delay(1); } } diff --git a/variants/linux/LinuxBoard.h b/variants/linux/LinuxBoard.h index 81b481400c..9aabb09156 100644 --- a/variants/linux/LinuxBoard.h +++ b/variants/linux/LinuxBoard.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -79,6 +80,14 @@ class LinuxBoard : public mesh::MainBoard { // is a no-op, matching ESP32Board/NRF52Board/STM32Board. void attachDynamicPrefs(KeyValueStore* prefs) { } + void sleep(uint32_t secs) override { + if (secs > 0) { + ::sleep(secs); + } else { + usleep(10000); // 10ms delay to prevent busy loop + } + } + LinuxConfig config; };