diff --git a/LSM9DS1.cpp b/LSM9DS1.cpp index e39e323..eab8b80 100644 --- a/LSM9DS1.cpp +++ b/LSM9DS1.cpp @@ -111,11 +111,18 @@ void LSM9DS1::dataReady() { } void LSM9DS1::end() { - if (!running) return; running = false; - thr.join(); - gpiod_line_release(pinDRDY); - gpiod_chip_close(chipDRDY); + if (thr.joinable()) { + thr.join(); + } + if (NULL != pinDRDY) { + gpiod_line_release(pinDRDY); + } + if (NULL != chipDRDY) { + gpiod_chip_close(chipDRDY); + } + pinDRDY = NULL; + chipDRDY = NULL; } void LSM9DS1::initGyro() diff --git a/LSM9DS1.h b/LSM9DS1.h index 67bf81c..14b8d3a 100644 --- a/LSM9DS1.h +++ b/LSM9DS1.h @@ -672,10 +672,14 @@ class LSM9DS1 running = true; while (running) { const struct timespec ts = { 1, 0 }; - gpiod_line_event_wait(pinDRDY, &ts); - struct gpiod_line_event event; - gpiod_line_event_read(pinDRDY, &event); - dataReady(); + int r = gpiod_line_event_wait(pinDRDY, &ts); + if (1 == r) { + struct gpiod_line_event event; + gpiod_line_event_read(pinDRDY, &event); + dataReady(); + } else { + running = false; + } } }