8static const char *
const TAG =
"max44009.sensor";
11static const uint8_t MAX44009_REGISTER_CONFIGURATION = 0x02;
12static const uint8_t MAX44009_LUX_READING_HIGH = 0x03;
13static const uint8_t MAX44009_LUX_READING_LOW = 0x04;
15static const uint8_t MAX44009_CFG_CONTINUOUS = 0x80;
17static const uint8_t MAX44009_OK = 0;
18static const uint8_t MAX44009_ERROR_WIRE_REQUEST = -10;
19static const uint8_t MAX44009_ERROR_OVERFLOW = -20;
20static const uint8_t MAX44009_ERROR_HIGH_BYTE = -30;
21static const uint8_t MAX44009_ERROR_LOW_BYTE = -31;
24 bool state_ok =
false;
47 ESP_LOGCONFIG(TAG,
"MAX44009:");
50 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
59 if (this->
error_ != MAX44009_OK) {
69 uint8_t datahigh = this->
read_(MAX44009_LUX_READING_HIGH);
70 if (
error_ != MAX44009_OK) {
71 this->
error_ = MAX44009_ERROR_HIGH_BYTE;
74 uint8_t datalow = this->
read_(MAX44009_LUX_READING_LOW);
75 if (
error_ != MAX44009_OK) {
76 this->
error_ = MAX44009_ERROR_LOW_BYTE;
79 uint8_t exponent = datahigh >> 4;
80 if (exponent == 0x0F) {
81 this->
error_ = MAX44009_ERROR_OVERFLOW;
89 uint8_t exponent = data_high >> 4;
90 uint32_t mantissa = ((data_high & 0x0F) << 4) + (data_low & 0x0F);
91 return ((0x0001 << exponent) * 0.045) * mantissa;
95 uint8_t config = this->
read_(MAX44009_REGISTER_CONFIGURATION);
96 if (this->
error_ == MAX44009_OK) {
97 config |= MAX44009_CFG_CONTINUOUS;
98 this->
write_(MAX44009_REGISTER_CONFIGURATION, config);
100 ESP_LOGV(TAG,
"set to continuous mode");
109 uint8_t config = this->
read_(MAX44009_REGISTER_CONFIGURATION);
110 if (this->
error_ == MAX44009_OK) {
111 config &= ~MAX44009_CFG_CONTINUOUS;
112 this->
write_(MAX44009_REGISTER_CONFIGURATION, config);
114 ESP_LOGV(TAG,
"set to low power mode");
125 this->
error_ = MAX44009_ERROR_WIRE_REQUEST;
127 this->
error_ = MAX44009_OK;
134 this->
error_ = MAX44009_ERROR_WIRE_REQUEST;
136 this->
error_ = MAX44009_OK;
BedjetMode mode
BedJet operating mode.
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message=nullptr)
void status_clear_warning()
virtual uint32_t get_update_interval() const
Get the update interval in ms of this sensor.
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
bool read_byte(uint8_t a_register, uint8_t *data, bool stop=true)
float get_setup_priority() const override
float read_illuminance_()
Read the illuminance value.
void write_(uint8_t reg, uint8_t value)
void set_mode(MAX44009Mode mode)
void dump_config() override
bool set_continuous_mode()
bool set_low_power_mode()
float convert_to_lux_(uint8_t data_high, uint8_t data_low)
uint8_t read_(uint8_t reg)
void publish_state(float state)
Publish a new state to the front-end.
@ MAX44009_MODE_LOW_POWER
@ MAX44009_MODE_CONTINUOUS
const float DATA
For components that import data from directly connected sensors like DHT.
Providing packet encoding functions for exchanging data with a remote host.