1
0
mirror of https://github.com/esphome/esphome.git synced 2025-01-31 10:10:56 +00:00

[ads1115] Lint fix

This commit is contained in:
brambo123 2025-01-17 14:53:44 +01:00
parent 9bba989223
commit dc4978d12c
3 changed files with 23 additions and 20 deletions

View File

@ -104,51 +104,51 @@ float ADS1115Component::request_measurement(ADS1115Multiplexer multiplexer, ADS1
} }
this->prev_config_ = config; this->prev_config_ = config;
// Delay calculated as: ceil((1000/SPS)+.5)
if (resolution == ADS1015_12_BITS) { if (resolution == ADS1015_12_BITS) {
switch (samplerate) { switch (samplerate) {
case ADS1115_8SPS: case ADS1115_8SPS:
delay(9); // ceil((1000/128)+.5) delay(9);
break; break;
case ADS1115_16SPS: case ADS1115_16SPS:
delay(5); // ceil((1000/250)+.5) delay(5);
break; break;
case ADS1115_32SPS: case ADS1115_32SPS:
delay(3); // ceil((1000/475)+.5) delay(3);
break; break;
case ADS1115_64SPS: case ADS1115_64SPS:
case ADS1115_128SPS: case ADS1115_128SPS:
delay(2); // ceil((1000/1600)+.5) delay(2);
break; break;
default: default:
delay(1); // ceil((2400/1600)+.5) delay(1);
break; break;
} }
} } else {
else {
switch (samplerate) { switch (samplerate) {
case ADS1115_8SPS: case ADS1115_8SPS:
delay(126); // ceil((1000/8)+.5) delay(126); // NOLINT
break; break;
case ADS1115_16SPS: case ADS1115_16SPS:
delay(63); // ceil((1000/16)+.5) delay(63); // NOLINT
break; break;
case ADS1115_32SPS: case ADS1115_32SPS:
delay(32); // ceil((1000/32)+.5) delay(32);
break; break;
case ADS1115_64SPS: case ADS1115_64SPS:
delay(17); // ceil((1000/64)+.5) delay(17);
break; break;
case ADS1115_128SPS: case ADS1115_128SPS:
delay(9); // ceil((1000/128)+.5) delay(9);
break; break;
case ADS1115_250SPS: case ADS1115_250SPS:
delay(5); // ceil((1000/250)+.5) delay(5);
break; break;
case ADS1115_475SPS: case ADS1115_475SPS:
delay(3); // ceil((1000/475)+.5) delay(3);
break; break;
case ADS1115_860SPS: case ADS1115_860SPS:
delay(2); // ceil((1000/860)+.5) delay(2);
break; break;
} }
} }

View File

@ -53,7 +53,8 @@ class ADS1115Component : public Component, public i2c::I2CDevice {
void set_continuous_mode(bool continuous_mode) { continuous_mode_ = continuous_mode; } void set_continuous_mode(bool continuous_mode) { continuous_mode_ = continuous_mode; }
/// Helper method to request a measurement from a sensor. /// 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: protected:
uint16_t prev_config_{0}; uint16_t prev_config_{0};

View File

@ -53,7 +53,7 @@ SAMPLERATE = {
"128": ADS1115Samplerate.ADS1115_128SPS, "128": ADS1115Samplerate.ADS1115_128SPS,
"250": ADS1115Samplerate.ADS1115_250SPS, "250": ADS1115Samplerate.ADS1115_250SPS,
"475": ADS1115Samplerate.ADS1115_475SPS, "475": ADS1115Samplerate.ADS1115_475SPS,
"860": ADS1115Samplerate.ADS1115_860SPS "860": ADS1115Samplerate.ADS1115_860SPS,
} }
ADS1115Sensor = ads1115_ns.class_( ADS1115Sensor = ads1115_ns.class_(
@ -76,7 +76,9 @@ CONFIG_SCHEMA = (
cv.Optional(CONF_RESOLUTION, default="16_BITS"): cv.enum( cv.Optional(CONF_RESOLUTION, default="16_BITS"): cv.enum(
RESOLUTION, upper=True, space="_" 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")) .extend(cv.polling_component_schema("60s"))