mirror of
https://github.com/esphome/esphome.git
synced 2025-04-13 14:20:29 +01:00
[ltr390] Move calculation to allow dynamic setting of gain and resolution (#8343)
This commit is contained in:
parent
903d033e0f
commit
db666e44a7
@ -1,7 +1,7 @@
|
|||||||
#include "ltr390.h"
|
#include "ltr390.h"
|
||||||
|
#include <bitset>
|
||||||
#include "esphome/core/hal.h"
|
#include "esphome/core/hal.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
#include <bitset>
|
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace ltr390 {
|
namespace ltr390 {
|
||||||
@ -91,7 +91,12 @@ void LTR390Component::read_uvs_() {
|
|||||||
uint32_t uv = *val;
|
uint32_t uv = *val;
|
||||||
|
|
||||||
if (this->uvi_sensor_ != nullptr) {
|
if (this->uvi_sensor_ != nullptr) {
|
||||||
this->uvi_sensor_->publish_state((uv / this->sensitivity_uv_) * this->wfac_);
|
// Set sensitivity by linearly scaling against known value in the datasheet
|
||||||
|
float gain_scale_uv = GAINVALUES[this->gain_uv_] / GAIN_MAX;
|
||||||
|
float intg_scale_uv = (RESOLUTIONVALUE[this->res_uv_] * 100) / INTG_MAX;
|
||||||
|
float sensitivity_uv = SENSITIVITY_MAX * gain_scale_uv * intg_scale_uv;
|
||||||
|
|
||||||
|
this->uvi_sensor_->publish_state((uv / sensitivity_uv) * this->wfac_);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->uv_sensor_ != nullptr) {
|
if (this->uv_sensor_ != nullptr) {
|
||||||
@ -166,11 +171,6 @@ void LTR390Component::setup() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set sensitivity by linearly scaling against known value in the datasheet
|
|
||||||
float gain_scale_uv = GAINVALUES[this->gain_uv_] / GAIN_MAX;
|
|
||||||
float intg_scale_uv = (RESOLUTIONVALUE[this->res_uv_] * 100) / INTG_MAX;
|
|
||||||
this->sensitivity_uv_ = SENSITIVITY_MAX * gain_scale_uv * intg_scale_uv;
|
|
||||||
|
|
||||||
// Set sensor read state
|
// Set sensor read state
|
||||||
this->reading_ = false;
|
this->reading_ = false;
|
||||||
|
|
||||||
|
@ -77,7 +77,6 @@ class LTR390Component : public PollingComponent, public i2c::I2CDevice {
|
|||||||
LTR390GAIN gain_uv_;
|
LTR390GAIN gain_uv_;
|
||||||
LTR390RESOLUTION res_als_;
|
LTR390RESOLUTION res_als_;
|
||||||
LTR390RESOLUTION res_uv_;
|
LTR390RESOLUTION res_uv_;
|
||||||
float sensitivity_uv_;
|
|
||||||
float wfac_;
|
float wfac_;
|
||||||
|
|
||||||
sensor::Sensor *light_sensor_{nullptr};
|
sensor::Sensor *light_sensor_{nullptr};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user