diff --git a/esphome/components/ltr390/ltr390.cpp b/esphome/components/ltr390/ltr390.cpp index cbf1e2e3f9..48899d932c 100644 --- a/esphome/components/ltr390/ltr390.cpp +++ b/esphome/components/ltr390/ltr390.cpp @@ -38,25 +38,25 @@ bool LTR390Component::reset_(void) { return true; } -void LTR390Component::set_mode_(ltr390_mode_t mode) { +void LTR390Component::set_mode_(LTR390MODE mode) { std::bitset<8> crtl_value(this->ctrl_reg_->get()); crtl_value[LTR390_CTRL_MODE] = mode; *this->ctrl_reg_ = crtl_value.to_ulong(); } -ltr390_mode_t LTR390Component::get_mode_(void) { +LTR390MODE LTR390Component::get_mode_(void) { std::bitset<8> crtl_value(this->ctrl_reg_->get()); - return (ltr390_mode_t)(int) crtl_value[LTR390_CTRL_MODE]; + return (LTR390MODE)(int) crtl_value[LTR390_CTRL_MODE]; } -void LTR390Component::set_gain_(ltr390_gain_t gain) { *this->gain_reg_ = gain; } +void LTR390Component::set_gain_(LTR390GAIN gain) { *this->gain_reg_ = gain; } -ltr390_gain_t LTR390Component::get_gain_(void) { +LTR390GAIN LTR390Component::get_gain_(void) { std::bitset<8> gain_value(this->gain_reg_->get()); - return (ltr390_gain_t) gain_value.to_ulong(); + return (LTR390GAIN) gain_value.to_ulong(); } -void LTR390Component::set_resolution_(ltr390_resolution_t res) { +void LTR390Component::set_resolution_(LTR390RESOLUTION res) { std::bitset<8> res_value(this->res_reg_->get()); std::bitset<3> new_res_value(res); @@ -68,7 +68,7 @@ void LTR390Component::set_resolution_(ltr390_resolution_t res) { *this->res_reg_ = res_value.to_ulong(); } -ltr390_resolution_t LTR390Component::get_resolution_(void) { +LTR390RESOLUTION LTR390Component::get_resolution_(void) { std::bitset<8> res_value(this->res_reg_->get()); std::bitset<3> output_value(0); @@ -76,7 +76,7 @@ ltr390_resolution_t LTR390Component::get_resolution_(void) { output_value[i] = res_value[4 + i]; } - return (ltr390_resolution_t) output_value.to_ulong(); + return (LTR390RESOLUTION) output_value.to_ulong(); } bool LTR390Component::new_data_available_(void) { @@ -95,7 +95,7 @@ uint32_t little_endian_bytes_to_int(uint8_t *buffer, uint8_t num_bytes) { return value; } -uint32_t LTR390Component::read_sensor_data_(ltr390_mode_t mode) { +uint32_t LTR390Component::read_sensor_data_(LTR390MODE mode) { const uint8_t num_bytes = 3; uint8_t buffer[num_bytes]; @@ -180,7 +180,7 @@ void LTR390Component::setup() { this->reading = false; // Create a list of modes and corresponding read functions - this->mode_funcs_ = new std::vector > >(); + this->mode_funcs_ = new std::vector > >(); // If we need the light sensor then add to the list if (this->light_sensor_ != nullptr || this->als_sensor_ != nullptr) { diff --git a/esphome/components/ltr390/ltr390.h b/esphome/components/ltr390/ltr390.h index 3c82ace55a..7bb61503ed 100644 --- a/esphome/components/ltr390/ltr390.h +++ b/esphome/components/ltr390/ltr390.h @@ -10,7 +10,7 @@ namespace esphome { namespace ltr390 { -enum ltr390_ctrl_t { +enum LTR390CTRL { LTR390_CTRL_EN = 1, LTR390_CTRL_MODE = 3, LTR390_CTRL_RST = 4, @@ -27,13 +27,13 @@ static const uint8_t LTR390_MAIN_STATUS = 0x07; #define LTR390_SENSITIVITY 2300.0 // Sensing modes -enum ltr390_mode_t { +enum LTR390MODE { LTR390_MODE_ALS, LTR390_MODE_UVS, }; // Sensor gain levels -enum ltr390_gain_t { +enum LTR390GAIN { LTR390_GAIN_1 = 0, LTR390_GAIN_3, // Default LTR390_GAIN_6, @@ -42,7 +42,7 @@ enum ltr390_gain_t { }; // Sensor resolution -enum ltr390_resolution_t { +enum LTR390RESOLUTION { LTR390_RESOLUTION_20BIT, LTR390_RESOLUTION_19BIT, LTR390_RESOLUTION_18BIT, // Default @@ -58,8 +58,8 @@ class LTR390Component : public PollingComponent, public i2c::I2CDevice { void dump_config() override; void update() override; - void set_gain_value(ltr390_gain_t gain) { this->gain_ = gain; } - void set_res_value(ltr390_resolution_t res) { this->res_ = res; } + void set_gain_value(LTR390GAIN gain) { this->gain_ = gain; } + void set_res_value(LTR390RESOLUTION res) { this->res_ = res; } void set_wfac_value(float wfac) { this->wfac_ = wfac; } void set_light_sensor(sensor::Sensor *light_sensor) { this->light_sensor_ = light_sensor; } @@ -73,17 +73,17 @@ class LTR390Component : public PollingComponent, public i2c::I2CDevice { bool reset_(); - void set_mode_(ltr390_mode_t mode); - ltr390_mode_t get_mode_(); + void set_mode_(LTR390MODE mode); + LTR390MODE get_mode_(); - void set_gain_(ltr390_gain_t gain); - ltr390_gain_t get_gain_(); + void set_gain_(LTR390GAIN gain); + LTR390GAIN get_gain_(); - void set_resolution_(ltr390_resolution_t res); - ltr390_resolution_t get_resolution_(); + void set_resolution_(LTR390RESOLUTION res); + LTR390RESOLUTION get_resolution_(); bool new_data_available_(); - uint32_t read_sensor_data_(ltr390_mode_t mode); + uint32_t read_sensor_data_(LTR390MODE mode); void read_als_(); void read_uvs_(); @@ -92,15 +92,15 @@ class LTR390Component : public PollingComponent, public i2c::I2CDevice { std::atomic reading_; - std::vector > > *mode_funcs_; + std::vector > > *mode_funcs_; i2c::I2CRegister *ctrl_reg_; i2c::I2CRegister *status_reg_; i2c::I2CRegister *gain_reg_; i2c::I2CRegister *res_reg_; - ltr390_gain_t gain_; - ltr390_resolution_t res_; + LTR390GAIN gain_; + LTR390RESOLUTION res_; float wfac_; sensor::Sensor *light_sensor_{nullptr}; @@ -108,7 +108,6 @@ class LTR390Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *uvi_sensor_{nullptr}; sensor::Sensor *uv_sensor_{nullptr}; - }; } // namespace ltr390