diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2017-02-06 13:31:34 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2017-02-06 13:31:34 -0500 |
commit | 20d0936fa256e0caa41a18a79556c8ade3f8347f (patch) | |
tree | 230424417d2f1b0c148d677ecf3d1003dfd943ac /klippy/pyhelper.c | |
parent | c24b7a7ef96b6c9770fdf4c821f5719892732033 (diff) | |
download | kutter-20d0936fa256e0caa41a18a79556c8ade3f8347f.tar.gz kutter-20d0936fa256e0caa41a18a79556c8ade3f8347f.tar.xz kutter-20d0936fa256e0caa41a18a79556c8ade3f8347f.zip |
reactor: Use the system monotonic clock instead of the normal system clock
The normal system clock can have sudden jumps if the system clock is
changed. Use the system monotonic clock to avoid these sudden changes
in time.
It appears the Raspbian OS (which is used by OctoPi) is setup to
update the system clock upon network connectivity. This could cause
sudden system clock changes which could lead to Klippy processing
errors. Using the monotonic clock eliminates these issues.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/pyhelper.c')
-rw-r--r-- | klippy/pyhelper.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/klippy/pyhelper.c b/klippy/pyhelper.c index 2716b9b7..410fd764 100644 --- a/klippy/pyhelper.c +++ b/klippy/pyhelper.c @@ -9,17 +9,20 @@ #include <stdint.h> // uint8_t #include <stdio.h> // fprintf #include <string.h> // strerror -#include <sys/time.h> // gettimeofday #include <time.h> // struct timespec -#include "pyhelper.h" // get_time +#include "pyhelper.h" // get_monotonic -// Return the current system time as a double +// Return the monotonic system time as a double double -get_time(void) +get_monotonic(void) { - struct timeval tv; - gettimeofday(&tv, NULL); - return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.; + struct timespec ts; + int ret = clock_gettime(CLOCK_MONOTONIC, &ts); + if (ret) { + report_errno("clock_gettime", ret); + return 0.; + } + return (double)ts.tv_sec + (double)ts.tv_nsec * .000000001; } // Fill a 'struct timespec' with a system time stored in a double |