ESPHome
2026.11.0-dev
Loading...
Searching...
No Matches
esphome
components
bh1745
bh1745.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
esphome/components/i2c/i2c.h
"
4
#include "
esphome/components/sensor/sensor.h
"
5
#include "
esphome/core/component.h
"
6
7
namespace
esphome::bh1745
{
8
9
enum class
MeasurementTime
: uint8_t {
10
MEASUREMENT_TIME_160MS
= 0b000,
11
MEASUREMENT_TIME_320MS
= 0b001,
12
MEASUREMENT_TIME_640MS
= 0b010,
13
MEASUREMENT_TIME_1280MS
= 0b011,
14
MEASUREMENT_TIME_2560MS
= 0b100,
15
MEASUREMENT_TIME_5120MS
= 0b101,
16
};
17
18
enum class
AdcGain
: uint8_t {
19
ADC_GAIN_1X
= 0,
20
ADC_GAIN_2X
= 1,
21
ADC_GAIN_16X
= 2,
22
};
23
24
class
BH1745Component
:
public
PollingComponent
,
public
i2c::I2CDevice
{
25
SUB_SENSOR(red_counts)
26
SUB_SENSOR(green_counts)
27
SUB_SENSOR(blue_counts)
28
SUB_SENSOR(clear_counts)
29
SUB_SENSOR(illuminance)
30
SUB_SENSOR(color_temperature)
31
32
public
:
33
void
setup
()
override
;
34
void
dump_config()
override
;
35
void
update()
override
;
36
37
void
set_measurement_time(
MeasurementTime
measurement_time) { this->
measurement_time_
= measurement_time; }
38
void
set_adc_gain(
AdcGain
adc_gain) { this->
adc_gain_
= adc_gain; }
39
void
set_glass_attenuation_factor(
float
factor) { this->
glass_attenuation_factor_
= factor; }
40
42
void
enable_interrupt_output() { this->
interrupt_output_
=
true
; }
43
void
set_interrupt_state(
bool
on);
44
45
protected
:
46
float
glass_attenuation_factor_
{1.0f};
47
float
lux_scale_
{1.0f};
// 160 / (gain * integration time * glass attenuation), set in setup()
48
MeasurementTime
measurement_time_
{
MeasurementTime::MEASUREMENT_TIME_160MS
};
49
AdcGain
adc_gain_
{
AdcGain::ADC_GAIN_1X
};
50
bool
busy_
{
true
};
// cleared once the chip is configured after the reset
51
bool
interrupt_output_
{
false
};
52
};
53
54
}
// namespace esphome::bh1745
esphome::Component::setup
virtual void setup()
Where the component's initialization should happen.
Definition
component.cpp:84
esphome::PollingComponent
This class simplifies creating components that periodically check a state.
Definition
component.h:514
esphome::bh1745::BH1745Component
Definition
bh1745.h:24
esphome::bh1745::BH1745Component::busy_
bool busy_
Definition
bh1745.h:50
esphome::bh1745::BH1745Component::adc_gain_
AdcGain adc_gain_
Definition
bh1745.h:49
esphome::bh1745::BH1745Component::interrupt_output_
bool interrupt_output_
Definition
bh1745.h:51
esphome::bh1745::BH1745Component::glass_attenuation_factor_
float glass_attenuation_factor_
Definition
bh1745.h:46
esphome::bh1745::BH1745Component::lux_scale_
float lux_scale_
Definition
bh1745.h:47
esphome::bh1745::BH1745Component::measurement_time_
MeasurementTime measurement_time_
Definition
bh1745.h:48
esphome::i2c::I2CDevice
This Class provides the methods to read/write bytes from/to an i2c device.
Definition
i2c.h:132
component.h
i2c.h
esphome::bh1745
Definition
bh1745.cpp:7
esphome::bh1745::MeasurementTime
MeasurementTime
Definition
bh1745.h:9
esphome::bh1745::MeasurementTime::MEASUREMENT_TIME_5120MS
@ MEASUREMENT_TIME_5120MS
esphome::bh1745::MeasurementTime::MEASUREMENT_TIME_1280MS
@ MEASUREMENT_TIME_1280MS
esphome::bh1745::MeasurementTime::MEASUREMENT_TIME_320MS
@ MEASUREMENT_TIME_320MS
esphome::bh1745::MeasurementTime::MEASUREMENT_TIME_2560MS
@ MEASUREMENT_TIME_2560MS
esphome::bh1745::MeasurementTime::MEASUREMENT_TIME_640MS
@ MEASUREMENT_TIME_640MS
esphome::bh1745::MeasurementTime::MEASUREMENT_TIME_160MS
@ MEASUREMENT_TIME_160MS
esphome::bh1745::AdcGain
AdcGain
Definition
bh1745.h:18
esphome::bh1745::AdcGain::ADC_GAIN_1X
@ ADC_GAIN_1X
esphome::bh1745::AdcGain::ADC_GAIN_16X
@ ADC_GAIN_16X
esphome::bh1745::AdcGain::ADC_GAIN_2X
@ ADC_GAIN_2X
sensor.h
Generated by
1.12.0