Skip to content

Commit 24624c8

Browse files
committed
Keep the delay in waitForData even if imu start failed
If timer interrupt used, make waitForData wait for the timer. Rationale: make the loop relying on this delay not eat 100% cpu if imu failed. Blocking still will be disabled, if interrupt pin is used, since otherwise it would block the code endlessly.
1 parent 8f9d877 commit 24624c8

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

IMU.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class IMUInterface {
6767
class IMUBase : public IMUInterface, public Logger {
6868
private:
6969
bool usingInterrupt = false;
70+
int interruptPin = -1;
7071

7172
#ifdef ESP32
7273
SemaphoreHandle_t interruptSemaphore;
@@ -106,6 +107,7 @@ class IMUBase : public IMUInterface, public Logger {
106107
pinMode(pin, INPUT_PULLUP);
107108
attachInterruptArg(digitalPinToInterrupt(pin), IMUBase::interruptHandler, interruptSemaphore, FALLING);
108109
usingInterrupt = true;
110+
interruptPin = pin;
109111
return true;
110112
}
111113
#else
@@ -126,7 +128,7 @@ class IMUBase : public IMUInterface, public Logger {
126128

127129
public:
128130
void waitForData() override {
129-
if (this->status()) return; // don't wait if there's an error
131+
if (this->status() && interruptPin != -1) return; // don't hang if error and interrupt pin is used
130132

131133
if (usingInterrupt) {
132134
#ifdef ESP32

0 commit comments

Comments
 (0)