Skip to content

Commit

Permalink
fix delayMicroseconds() implementation
Browse files Browse the repository at this point in the history
This affects linux_kernel, mraa, and pigpio drivers (on linux)

It was a simple math operator mistake that resulted in no delay if the specified microseconds was less than 1000000.
  • Loading branch information
2bndy5 committed Mar 22, 2024
1 parent d33a90b commit 36e17e0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/utility/linux_kernel/time_keeping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#ifndef ARDUINO
#include <time.h>
#include <chrono>
#include <sys/time.h>
#include "time_keeping.h"

#ifdef __cplusplus
Expand All @@ -41,7 +40,7 @@ namespace cirque_pinnacle_arduino_wrappers {
{
struct timespec req;
req.tv_sec = (time_t)microseconds / 1000000;
req.tv_nsec = (microseconds / 1000000) * 1000;
req.tv_nsec = (microseconds % 1000000) * 1000;
//nanosleep(&req, (struct timespec *)NULL);
clock_nanosleep(CLOCK_REALTIME, 0, &req, NULL);
}
Expand Down
3 changes: 1 addition & 2 deletions src/utility/mraa/time_keeping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#ifndef ARDUINO
#include <time.h>
#include <chrono>
#include <sys/time.h>
#include "time_keeping.h"

#ifdef __cplusplus
Expand All @@ -41,7 +40,7 @@ namespace cirque_pinnacle_arduino_wrappers {
{
struct timespec req;
req.tv_sec = (time_t)microseconds / 1000000;
req.tv_nsec = (microseconds / 1000000) * 1000;
req.tv_nsec = (microseconds % 1000000) * 1000;
//nanosleep(&req, (struct timespec *)NULL);
clock_nanosleep(CLOCK_REALTIME, 0, &req, NULL);
}
Expand Down
2 changes: 1 addition & 1 deletion src/utility/pigpio/time_keeping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace cirque_pinnacle_arduino_wrappers {
{
struct timespec req;
req.tv_sec = (time_t)microseconds / 1000000;
req.tv_nsec = (microseconds / 1000000) * 1000;
req.tv_nsec = (microseconds % 1000000) * 1000;
//nanosleep(&req, (struct timespec *)NULL);
clock_nanosleep(CLOCK_REALTIME, 0, &req, NULL);
}
Expand Down

0 comments on commit 36e17e0

Please sign in to comment.