ESPHome  2024.11.1
veml3235.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
7 
8 namespace esphome {
9 namespace veml3235 {
10 
11 // Register IDs/locations
12 //
13 static const uint8_t CONFIG_REG = 0x00;
14 static const uint8_t W_REG = 0x04;
15 static const uint8_t ALS_REG = 0x05;
16 static const uint8_t ID_REG = 0x09;
17 
18 // Bit offsets within CONFIG_REG
19 //
20 static const uint8_t CONFIG_REG_IT_BIT = 12;
21 static const uint8_t CONFIG_REG_DG_BIT = 5;
22 static const uint8_t CONFIG_REG_G_BIT = 3;
23 
24 // Other important constants
25 //
26 static const uint8_t DEVICE_ID = 0x35;
27 static const uint16_t SHUTDOWN_BITS = 0x0018;
28 
29 // Base multiplier value for lux computation
30 //
31 static const float LUX_MULTIPLIER_BASE = 0.00213;
32 
33 // Enum for conversion/integration time settings for the VEML3235.
34 //
35 // Specific values of the enum constants are register values taken from the VEML3235 datasheet.
36 // Longer times mean more accurate results, but will take more energy/more time.
37 //
44 };
45 
46 // Enum for digital gain settings for the VEML3235.
47 // Higher values are better for low light situations, but can increase noise.
48 //
52 };
53 
54 // Enum for gain settings for the VEML3235.
55 // Higher values are better for low light situations, but can increase noise.
56 //
61 };
62 
64  public:
65  void setup() override;
66  void dump_config() override;
67  void update() override { this->publish_state(this->read_lx_()); }
68  float get_setup_priority() const override { return setup_priority::DATA; }
69 
70  // Used by ESPHome framework. Does NOT actually set the value on the device.
71  void set_auto_gain(bool auto_gain) { this->auto_gain_ = auto_gain; }
74  }
77  }
78  void set_power_on(bool power_on) { this->power_on_ = power_on; }
83  }
84 
85  bool auto_gain() { return this->auto_gain_; }
89  VEML3235ComponentGain gain() { return this->gain_; }
91 
92  // Updates the configuration register on the device
93  bool refresh_config_reg(bool force_on = false);
94 
95  protected:
96  float read_lx_();
97  void adjust_gain_(uint16_t als_raw_value);
98 
99  bool auto_gain_{true};
100  bool power_on_{true};
106 };
107 
108 } // namespace veml3235
109 } // namespace esphome
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
void adjust_gain_(uint16_t als_raw_value)
Definition: veml3235.cpp:114
void set_integration_time(VEML3235ComponentIntegrationTime integration_time)
Definition: veml3235.h:81
void set_auto_gain_threshold_low(float auto_gain_threshold_low)
Definition: veml3235.h:75
VEML3235ComponentGain gain()
Definition: veml3235.h:89
VEML3235ComponentIntegrationTime integration_time_
Definition: veml3235.h:105
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_power_on(bool power_on)
Definition: veml3235.h:78
void set_auto_gain_threshold_high(float auto_gain_threshold_high)
Definition: veml3235.h:72
VEML3235ComponentDigitalGain digital_gain_
Definition: veml3235.h:103
bool refresh_config_reg(bool force_on=false)
Definition: veml3235.cpp:31
void set_gain(VEML3235ComponentGain gain)
Definition: veml3235.h:80
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:39
VEML3235ComponentDigitalGain digital_gain()
Definition: veml3235.h:88
VEML3235ComponentIntegrationTime
Definition: veml3235.h:38
VEML3235ComponentIntegrationTime integration_time()
Definition: veml3235.h:90
VEML3235ComponentDigitalGain
Definition: veml3235.h:49
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
VEML3235ComponentGain gain_
Definition: veml3235.h:104
const uint8_t CONFIG_REG
Definition: pca9554.cpp:11
Base-class for all sensors.
Definition: sensor.h:57
void set_auto_gain(bool auto_gain)
Definition: veml3235.h:71
void set_digital_gain(VEML3235ComponentDigitalGain digital_gain)
Definition: veml3235.h:79
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133
float get_setup_priority() const override
Definition: veml3235.h:68