diff --git a/src/main.ino b/src/main.ino index 7d9eba315..0550fc234 100644 --- a/src/main.ino +++ b/src/main.ino @@ -371,8 +371,10 @@ void setup() void loop() { + uint32_t msecstosleep = 1000 * 30; // How long can we sleep before we again need to service the main loop? + gps.loop(); - screen_loop(); + msecstosleep = min(screen_loop(), msecstosleep); service.loop(); loopBLE(); @@ -428,5 +430,6 @@ void loop() // No GPS lock yet, let the OS put the main CPU in low power mode for 100ms (or until another interrupt comes in) // i.e. don't just keep spinning in loop as fast as we can. - //delay(100); + DEBUG_MSG("msecs %d\n", msecstosleep); + delay(msecstosleep); } \ No newline at end of file diff --git a/src/screen.cpp b/src/screen.cpp index e55a6e2d1..589b060b7 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -259,10 +259,10 @@ void screen_setup() #endif } -void screen_loop() +uint32_t screen_loop() { if (!disp) - return; + return 30 * 1000; #ifdef T_BEAM_V10 if (axp192_found && pmu_irq) @@ -295,11 +295,17 @@ void screen_loop() #endif static bool showingBootScreen = true; - ui.update(); + + + + uint32_t msecstosleep = ui.update(); // Once we finish showing the bootscreen, remove it from the loop if (showingBootScreen && ui.getUiState()->currentFrame == 1) { ui.setFrames(nonBootFrames, frameCount - 1); } + + // If we are scrolling do 30fps, otherwise just 1 fps (to save CPU) + return (ui.getUiState()->frameState == IN_TRANSITION ? 10 : 500); } diff --git a/src/screen.h b/src/screen.h index 2f85d4726..747ffbedf 100644 --- a/src/screen.h +++ b/src/screen.h @@ -1,4 +1,8 @@ #pragma once void screen_print(const char * text); -void screen_loop(), screen_setup(), screen_on(), screen_off(), screen_show_logo(); \ No newline at end of file + +/// @return how many msecs can we sleep before we want service again +uint32_t screen_loop(); + +void screen_setup(), screen_on(), screen_off(), screen_show_logo(); \ No newline at end of file