]> git.earman.xyz Git - sensor-watch.git/commitdiff
movement: fix unintended timeout short circuiting
authorMatheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
Wed, 6 Mar 2024 00:49:32 +0000 (21:49 -0300)
committerMatheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
Wed, 6 Mar 2024 00:49:32 +0000 (21:49 -0300)
Currently, movement drops time out events in case the previous loop
indicates that sleep is not possible due to short circuiting behavior
of logical and in C: if the left-hand side is false, the right hand
side is not evaluated at all, which means the loop is not called.
This was not intended to happen.

Fix it by storing the result in a second boolean variable
and working out the logic after the fact.

movement/movement.c

index c64df0c0731939ba8096c36727080e73270029a5..191429efa23813f435af4c0b6f3550212254ba36 100644 (file)
@@ -533,7 +533,8 @@ bool app_loop(void) {
         // first trip  | can sleep | cannot sleep | can sleep    | cannot sleep
         // second trip | can sleep | cannot sleep | cannot sleep | can sleep
         //          && | can sleep | cannot sleep | cannot sleep | cannot sleep
-        can_sleep = can_sleep && wf->loop(event, &movement_state.settings, watch_face_contexts[movement_state.current_face_idx]);
+        bool can_sleep2 = wf->loop(event, &movement_state.settings, watch_face_contexts[movement_state.current_face_idx]);
+        can_sleep = can_sleep && can_sleep2;
         event.event_type = EVENT_NONE;
         if (movement_state.settings.bit.to_always && movement_state.current_face_idx != 0) {
             // ...but if the user has "timeout always" set, give it the boot.