Skip to content

Commit d724ba9

Browse files
authored
Fix: Add debouncing to GUI navigation to prevent rapid scene changes. Reduces stress on LVGL memory allocator during fast button mashing. (#115)
1 parent e58c671 commit d724ba9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/applicationInternal/scenes/sceneHandler.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ void setLabelActiveScene() {
1717

1818
void showSpecificGUI(GUIlists GUIlist, std::string GUIname);
1919

20+
static unsigned long last_gui_navigation_time = 0;
21+
const unsigned long GUI_NAVIGATION_DEBOUNCE_MS = 100;
22+
23+
bool isGuiNavigationDebounced() {
24+
unsigned long current_time = millis();
25+
if (current_time - last_gui_navigation_time < GUI_NAVIGATION_DEBOUNCE_MS) {
26+
omote_log_d("scene: GUI navigation debounced, too soon since last navigation\r\n");
27+
return true;
28+
}
29+
last_gui_navigation_time = current_time;
30+
return false;
31+
}
32+
2033
void handleScene(uint16_t command, commandData commandData, std::string additionalPayload = "") {
2134

2235
auto current = commandData.commandPayloads.begin();
@@ -31,6 +44,10 @@ void handleScene(uint16_t command, commandData commandData, std::string addition
3144

3245
// --- do not switch scene, but navigate to the prev or next gui in the currently active list of guis ---------------
3346
if ((scene_name == scene_gui_next) || (scene_name == scene_gui_prev)) {
47+
if (isGuiNavigationDebounced()) {
48+
return;
49+
}
50+
3451
if (scene_name == scene_gui_prev) {
3552
if (gui_memoryOptimizer_getActiveTabID() == 0) {
3653
omote_log_d("scene: cannot navigate to prev gui, because there is none\r\n");

0 commit comments

Comments
 (0)