-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6518 from esphome/bump-2024.4.0b2
2024.4.0b2
- Loading branch information
Showing
9 changed files
with
92 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "ads1115_sensor.h" | ||
|
||
#include "esphome/core/log.h" | ||
|
||
namespace esphome { | ||
namespace ads1115 { | ||
|
||
static const char *const TAG = "ads1115.sensor"; | ||
|
||
float ADS1115Sensor::sample() { | ||
return this->parent_->request_measurement(this->multiplexer_, this->gain_, this->resolution_); | ||
} | ||
|
||
void ADS1115Sensor::update() { | ||
float v = this->sample(); | ||
if (!std::isnan(v)) { | ||
ESP_LOGD(TAG, "'%s': Got Voltage=%fV", this->get_name().c_str(), v); | ||
this->publish_state(v); | ||
} | ||
} | ||
|
||
void ADS1115Sensor::dump_config() { | ||
LOG_SENSOR(" ", "ADS1115 Sensor", this); | ||
ESP_LOGCONFIG(TAG, " Multiplexer: %u", this->multiplexer_); | ||
ESP_LOGCONFIG(TAG, " Gain: %u", this->gain_); | ||
ESP_LOGCONFIG(TAG, " Resolution: %u", this->resolution_); | ||
} | ||
|
||
} // namespace ads1115 | ||
} // namespace esphome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include "esphome/core/component.h" | ||
#include "esphome/core/helpers.h" | ||
|
||
#include "esphome/components/sensor/sensor.h" | ||
#include "esphome/components/voltage_sampler/voltage_sampler.h" | ||
|
||
#include "../ads1115.h" | ||
|
||
namespace esphome { | ||
namespace ads1115 { | ||
|
||
/// Internal holder class that is in instance of Sensor so that the hub can create individual sensors. | ||
class ADS1115Sensor : public sensor::Sensor, | ||
public PollingComponent, | ||
public voltage_sampler::VoltageSampler, | ||
public Parented<ADS1115Component> { | ||
public: | ||
void update() override; | ||
void set_multiplexer(ADS1115Multiplexer multiplexer) { this->multiplexer_ = multiplexer; } | ||
void set_gain(ADS1115Gain gain) { this->gain_ = gain; } | ||
void set_resolution(ADS1115Resolution resolution) { this->resolution_ = resolution; } | ||
float sample() override; | ||
|
||
void dump_config() override; | ||
|
||
protected: | ||
ADS1115Multiplexer multiplexer_; | ||
ADS1115Gain gain_; | ||
ADS1115Resolution resolution_; | ||
}; | ||
|
||
} // namespace ads1115 | ||
} // namespace esphome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters