]> git.earman.xyz Git - sensor-watch.git/commitdiff
jump counter forward when tab resumes from background
authorredraw <redraw@sdf.org>
Thu, 22 Jan 2026 20:31:01 +0000 (17:31 -0300)
committerredraw <redraw@sdf.org>
Thu, 22 Jan 2026 20:39:33 +0000 (17:39 -0300)
watch-library/simulator/watch/watch_rtc.c

index cbda46b0e996b46d0c1cd8c0f61a94b2cc693903..3492032f5a9d0831dfcfec801b3b5aa142528aae 100644 (file)
@@ -180,9 +180,12 @@ static void _watch_schedule_next_tick(void) {
     next_tick_time += ms;
     double delay = next_tick_time - now;
 
-    // If we're behind, schedule immediately
+    // If we're behind, jump counter forward and reset timing
     if (delay < 0) {
-        delay = 0;
+        uint32_t missed_ticks = (uint32_t)((-delay) / ms);
+        counter += missed_ticks;
+        next_tick_time = now + ms;
+        delay = ms;
     }
 
     emscripten_async_call(_watch_increase_counter, NULL, delay);