ESPHome 2025.7.1
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
69 // Used by ESPHome framework. Does NOT actually set the value on the device.
77 void set_power_on(bool power_on) { this->power_on_ = power_on; }
83
84 bool auto_gain() { return this->auto_gain_; }
88 VEML3235ComponentGain gain() { return this->gain_; }
90
91 // Updates the configuration register on the device
92 bool refresh_config_reg(bool force_on = false);
93
94 protected:
95 float read_lx_();
96 void adjust_gain_(uint16_t als_raw_value);
97
98 bool auto_gain_{true};
99 bool power_on_{true};
105};
106
107} // namespace veml3235
108} // namespace esphome
This class simplifies creating components that periodically check a state.
Definition component.h:422
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:62
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:45
VEML3235ComponentIntegrationTime integration_time_
Definition veml3235.h:104
void set_digital_gain(VEML3235ComponentDigitalGain digital_gain)
Definition veml3235.h:78
VEML3235ComponentGain gain()
Definition veml3235.h:88
void set_power_on(bool power_on)
Definition veml3235.h:77
void adjust_gain_(uint16_t als_raw_value)
Definition veml3235.cpp:114
void set_integration_time(VEML3235ComponentIntegrationTime integration_time)
Definition veml3235.h:80
void set_auto_gain(bool auto_gain)
Definition veml3235.h:70
void set_auto_gain_threshold_high(float auto_gain_threshold_high)
Definition veml3235.h:71
VEML3235ComponentIntegrationTime integration_time()
Definition veml3235.h:89
void set_gain(VEML3235ComponentGain gain)
Definition veml3235.h:79
VEML3235ComponentGain gain_
Definition veml3235.h:103
void set_auto_gain_threshold_low(float auto_gain_threshold_low)
Definition veml3235.h:74
VEML3235ComponentDigitalGain digital_gain()
Definition veml3235.h:87
VEML3235ComponentDigitalGain digital_gain_
Definition veml3235.h:102
bool refresh_config_reg(bool force_on=false)
Definition veml3235.cpp:31
const uint8_t CONFIG_REG
Definition pca9554.cpp:11
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