adafruit / Adafruit_BMP280_Library

Arduino Library for BMP280 sensors
255 stars 186 forks source link

Fix for issue #60 (uninitialized configuration structs) #61

Closed Telemattic closed 3 years ago

Telemattic commented 3 years ago

Initialize Adafruit_BMP280::_config and _ctrlMeas members to power-on-reset state in their constructors. Note that Adafruit_BMP280::begin() calls Adafruit_BMP280::setSampling() which will mostly initialize these structs as well. The defect in issue #60 is that _config.spi3w_en is never initialized and consequently the sensor can end up configured for spi 3-wire mode, which is not supported by the code. Fix is to initialize all members of these configuration structs to the power-on-reset values defined in the datasheet.

Testing: ran my local code that demonstrated the defect

Risk: minimal -- setSampling() already initializes all of the struct members save spi3w_en, and if that member is ever non-zero the sensor is put into a mode not supported by this library!

caternuson commented 3 years ago

@Telemattic Thanks for the PR. Looks like the CI checks are failing on formatting (cosmetic). Here's how to run clang-format to fix: https://learn.adafruit.com/the-well-automated-arduino-library/formatting-with-clang-format

caternuson commented 3 years ago

Thanks! That fixed it.