36 lines
1.1 KiB
C++
36 lines
1.1 KiB
C++
#include "ads1115_int_sensor.h"
|
|
|
|
#include "esphome/core/log.h"
|
|
|
|
namespace esphome {
|
|
namespace ads1115_int {
|
|
|
|
static const char *const TAG = "ads1115_int.sensor";
|
|
|
|
void ADS1115Sensor::loop() {
|
|
if (parent_->is_data_ready(this->multiplexer_)) {
|
|
this->parent_->clear_data_ready(this->multiplexer_);
|
|
int16_t raw_value = -1000;
|
|
double v = this->parent_->read_data(raw_value, this->multiplexer_, this->gain_, this->resolution_, this->samplerate_);
|
|
if (!std::isnan(v)) {
|
|
if(this->count_ % 10 == 0) {
|
|
ESP_LOGI(TAG, "'% -18s': Raw=% 6d %fV", this->get_name().c_str(), raw_value, v);
|
|
}
|
|
this->count_++;
|
|
ESP_LOGD(TAG, "'%s': Got Voltage=%fV", this->get_name().c_str(), v);
|
|
this->publish_state(v);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ADS1115Sensor::dump_config() {
|
|
LOG_SENSOR(" ", "ADS1115 Int Sensor", this);
|
|
ESP_LOGCONFIG(TAG, " Multiplexer: %u", this->multiplexer_);
|
|
ESP_LOGCONFIG(TAG, " Gain: %u", this->gain_);
|
|
ESP_LOGCONFIG(TAG, " Resolution: %u", this->resolution_);
|
|
ESP_LOGCONFIG(TAG, " Sample rate: %u", this->samplerate_);
|
|
}
|
|
|
|
} // namespace ads1115
|
|
} // namespace esphome
|