ESPHome 2025.5.0
Loading...
Searching...
No Matches
veml3235.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
7
8namespace esphome {
9namespace veml3235 {
10
11// Register IDs/locations
12//
13static const uint8_t CONFIG_REG = 0x00;
14static const uint8_t W_REG = 0x04;
15static const uint8_t ALS_REG = 0x05;
16static const uint8_t ID_REG = 0x09;
17
18// Bit offsets within CONFIG_REG
19//
20static const uint8_t CONFIG_REG_IT_BIT = 12;
21static const uint8_t CONFIG_REG_DG_BIT = 5;
22static const uint8_t CONFIG_REG_G_BIT = 3;
23
24// Other important constants
25//
26static const uint8_t DEVICE_ID = 0x35;
27static const uint16_t SHUTDOWN_BITS = 0x0018;
28
29// Base multiplier value for lux computation
30//
31static 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//
45
46// Enum for digital gain settings for the VEML3235.
47// Higher values are better for low light situations, but can increase noise.
48//
53
54// Enum for gain settings for the VEML3235.
55// Higher values are better for low light situations, but can increase noise.
56//
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.
78 void set_power_on(bool power_on) { this->power_on_ = power_on; }
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
This class simplifies creating components that periodically check a state.
Definition component.h:301
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:133
Base-class for all sensors.
Definition sensor.h:57
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:39
VEML3235ComponentIntegrationTime integration_time_
Definition veml3235.h:105
void set_digital_gain(VEML3235ComponentDigitalGain digital_gain)
Definition veml3235.h:79
VEML3235ComponentGain gain()
Definition veml3235.h:89
void set_power_on(bool power_on)
Definition veml3235.h:78
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(bool auto_gain)
Definition veml3235.h:71
void set_auto_gain_threshold_high(float auto_gain_threshold_high)
Definition veml3235.h:72
float get_setup_priority() const override
Definition veml3235.h:68
VEML3235ComponentIntegrationTime integration_time()
Definition veml3235.h:90
void set_gain(VEML3235ComponentGain gain)
Definition veml3235.h:80
VEML3235ComponentGain gain_
Definition veml3235.h:104
void set_auto_gain_threshold_low(float auto_gain_threshold_low)
Definition veml3235.h:75
VEML3235ComponentDigitalGain digital_gain()
Definition veml3235.h:88
VEML3235ComponentDigitalGain digital_gain_
Definition veml3235.h:103
bool refresh_config_reg(bool force_on=false)
Definition veml3235.cpp:31
const uint8_t CONFIG_REG
Definition pca9554.cpp:11
const float DATA
For components that import data from directly connected sensors like DHT.
Definition component.cpp:19
VEML3235ComponentIntegrationTime
Definition veml3235.h:38
@ VEML3235_INTEGRATION_TIME_100MS
Definition veml3235.h:40
@ VEML3235_INTEGRATION_TIME_200MS
Definition veml3235.h:41
@ VEML3235_INTEGRATION_TIME_50MS
Definition veml3235.h:39
@ VEML3235_INTEGRATION_TIME_800MS
Definition veml3235.h:43
@ VEML3235_INTEGRATION_TIME_400MS
Definition veml3235.h:42
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7