mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-08-06 13:34:06 -06:00
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>
This commit is contained in:
parent
c24b7a7ef9
commit
20d0936fa2
10 changed files with 58 additions and 45 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue