From 01d24594245df280b5373955b67e47281fdcf8e6 Mon Sep 17 00:00:00 2001 From: ladyada Date: Sat, 23 Aug 2025 15:23:11 -0400 Subject: [PATCH] Add reset() function for complete sensor reset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add reset() function that combines OTP memory reboot and algorithm reset - Integrate reset() call into begin() initialization sequence after isConnected() - Ensures clean sensor state before applying configuration settings - 5ms delay for proper sensor reset timing 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- Adafruit_STHS34PF80.cpp | 25 +++++++++++++++++++++++++ Adafruit_STHS34PF80.h | 1 + 2 files changed, 26 insertions(+) diff --git a/Adafruit_STHS34PF80.cpp b/Adafruit_STHS34PF80.cpp index 77c356f..f9d8337 100644 --- a/Adafruit_STHS34PF80.cpp +++ b/Adafruit_STHS34PF80.cpp @@ -63,6 +63,10 @@ bool Adafruit_STHS34PF80::begin(uint8_t i2c_addr, TwoWire *wire) { return false; } + if (!reset()) { + return false; + } + // Apply recommended default settings if (!setObjAveraging(STHS34PF80_AVG_TMOS_32)) { return false; @@ -98,6 +102,27 @@ bool Adafruit_STHS34PF80::isConnected() { return chip_id.read() == 0xD3; } +/*! + * @brief Reset the sensor completely + * @return True if successful, false otherwise + */ +bool Adafruit_STHS34PF80::reset() { + // Reboot OTP memory + if (!rebootOTPmemory()) { + return false; + } + + // Wait for sensor reset to complete + delay(5); + + // Reset the internal algorithm + if (!algorithmReset()) { + return false; + } + + return true; +} + /*! * @brief Set the motion detection low-pass filter configuration * @param config The LPF configuration value diff --git a/Adafruit_STHS34PF80.h b/Adafruit_STHS34PF80.h index 9f13f41..1fcce4d 100644 --- a/Adafruit_STHS34PF80.h +++ b/Adafruit_STHS34PF80.h @@ -133,6 +133,7 @@ public: bool begin(uint8_t i2c_addr = STHS34PF80_DEFAULT_ADDR, TwoWire *wire = &Wire); bool isConnected(); + bool reset(); bool setMotionLowPassFilter(sths34pf80_lpf_config_t config); sths34pf80_lpf_config_t getMotionLowPassFilter();