* Correctly track and display simulation paused status in telelogger.
authorUrban Wallasch <urban.wallasch@freenet.de>
Thu, 25 Jul 2019 22:14:56 +0000 (00:14 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Thu, 25 Jul 2019 22:14:56 +0000 (00:14 +0200)
telelogger.c

index 9544418879a804252d2e4be4c0ba3c07608a01f6..dbe489f34e87950049dfbad9a21f896875d3c1b1 100644 (file)
@@ -1,3 +1,5 @@
+#define _XOPEN_SOURCE 500  // for usleep()
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -19,6 +21,7 @@ static const char *s2hms( int s ) {
 }
 
 static int log_console(void) {
+    bool last_paused = telemetry->paused;
     uint64_t last_timestamp = telemetry->timestamp;
 
     printf( "game id: %s version %u.%u (%s)\n" , telemetry->game_id,
@@ -61,9 +64,18 @@ static int log_console(void) {
         printf( "nav limit: %.1f km/h\n", telemetry->nav_slimit * 3.6 );
 
         puts("");
-        sleep( 1 );
-        while ( telemetry->paused || last_timestamp == telemetry->timestamp )
+
+        if ( last_paused ) {
+            while ( telemetry->paused )
+                usleep( 100000 );
+        }
+        else if ( last_timestamp == telemetry->timestamp ) {
+            while ( last_timestamp == telemetry->timestamp )
+                sleep( 1 );
+        }
+        else
             sleep( 1 );
+        last_paused = telemetry->paused;
         last_timestamp = telemetry->timestamp;
     }
     return 0;