diff --git a/esphome/components/ads1115/ads1115.cpp b/esphome/components/ads1115/ads1115.cpp index dc74fe6392..c05064383c 100644 --- a/esphome/components/ads1115/ads1115.cpp +++ b/esphome/components/ads1115/ads1115.cpp @@ -86,7 +86,7 @@ float ADS1115Component::request_measurement(ADS1115Multiplexer multiplexer, ADS1 // 0bxxxxBBBxxxxxxxxx config &= 0b1111000111111111; config |= (gain & 0b111) << 9; - + // Sample rate // 0bxxxxxxxxBBBxxxxx config &= 0b1111111100011111; @@ -103,52 +103,52 @@ float ADS1115Component::request_measurement(ADS1115Multiplexer multiplexer, ADS1 return NAN; } this->prev_config_ = config; - + + // Delay calculated as: ceil((1000/SPS)+.5) if (resolution == ADS1015_12_BITS) { switch (samplerate) { case ADS1115_8SPS: - delay(9); // ceil((1000/128)+.5) + delay(9); break; case ADS1115_16SPS: - delay(5); // ceil((1000/250)+.5) + delay(5); break; case ADS1115_32SPS: - delay(3); // ceil((1000/475)+.5) + delay(3); break; case ADS1115_64SPS: case ADS1115_128SPS: - delay(2); // ceil((1000/1600)+.5) + delay(2); break; default: - delay(1); // ceil((2400/1600)+.5) + delay(1); break; } - } - else { + } else { switch (samplerate) { case ADS1115_8SPS: - delay(126); // ceil((1000/8)+.5) + delay(126); // NOLINT break; case ADS1115_16SPS: - delay(63); // ceil((1000/16)+.5) + delay(63); // NOLINT break; case ADS1115_32SPS: - delay(32); // ceil((1000/32)+.5) + delay(32); break; case ADS1115_64SPS: - delay(17); // ceil((1000/64)+.5) + delay(17); break; case ADS1115_128SPS: - delay(9); // ceil((1000/128)+.5) + delay(9); break; case ADS1115_250SPS: - delay(5); // ceil((1000/250)+.5) + delay(5); break; case ADS1115_475SPS: - delay(3); // ceil((1000/475)+.5) + delay(3); break; case ADS1115_860SPS: - delay(2); // ceil((1000/860)+.5) + delay(2); break; } } diff --git a/esphome/components/ads1115/ads1115.h b/esphome/components/ads1115/ads1115.h index ffdd9579a7..e65835a386 100644 --- a/esphome/components/ads1115/ads1115.h +++ b/esphome/components/ads1115/ads1115.h @@ -53,7 +53,8 @@ class ADS1115Component : public Component, public i2c::I2CDevice { void set_continuous_mode(bool continuous_mode) { continuous_mode_ = continuous_mode; } /// Helper method to request a measurement from a sensor. - float request_measurement(ADS1115Multiplexer multiplexer, ADS1115Gain gain, ADS1115Resolution resolution, ADS1115Samplerate samplerate); + float request_measurement(ADS1115Multiplexer multiplexer, ADS1115Gain gain, ADS1115Resolution resolution, + ADS1115Samplerate samplerate); protected: uint16_t prev_config_{0}; diff --git a/esphome/components/ads1115/sensor/__init__.py b/esphome/components/ads1115/sensor/__init__.py index c57652d8d8..f346a71198 100644 --- a/esphome/components/ads1115/sensor/__init__.py +++ b/esphome/components/ads1115/sensor/__init__.py @@ -53,7 +53,7 @@ SAMPLERATE = { "128": ADS1115Samplerate.ADS1115_128SPS, "250": ADS1115Samplerate.ADS1115_250SPS, "475": ADS1115Samplerate.ADS1115_475SPS, - "860": ADS1115Samplerate.ADS1115_860SPS + "860": ADS1115Samplerate.ADS1115_860SPS, } ADS1115Sensor = ads1115_ns.class_( @@ -76,7 +76,9 @@ CONFIG_SCHEMA = ( cv.Optional(CONF_RESOLUTION, default="16_BITS"): cv.enum( RESOLUTION, upper=True, space="_" ), - cv.Optional(CONF_SAMPLE_RATE, default="860"): cv.enum(SAMPLERATE, string=True), + cv.Optional(CONF_SAMPLE_RATE, default="860"): cv.enum( + SAMPLERATE, string=True + ), } ) .extend(cv.polling_component_schema("60s"))