8 static const char *
const TAG =
"max44009.sensor";
11 static const uint8_t MAX44009_REGISTER_CONFIGURATION = 0x02;
12 static const uint8_t MAX44009_LUX_READING_HIGH = 0x03;
13 static const uint8_t MAX44009_LUX_READING_LOW = 0x04;
15 static const uint8_t MAX44009_CFG_CONTINUOUS = 0x80;
17 static const uint8_t MAX44009_OK = 0;
18 static const uint8_t MAX44009_ERROR_WIRE_REQUEST = -10;
19 static const uint8_t MAX44009_ERROR_OVERFLOW = -20;
20 static const uint8_t MAX44009_ERROR_HIGH_BYTE = -30;
21 static const uint8_t MAX44009_ERROR_LOW_BYTE = -31;
24 ESP_LOGCONFIG(TAG,
"Setting up MAX44009...");
25 bool state_ok =
false;
48 ESP_LOGCONFIG(TAG,
"MAX44009:");
51 ESP_LOGE(TAG,
"Communication with MAX44009 failed!");
60 if (this->
error_ != MAX44009_OK) {
70 uint8_t datahigh = this->
read_(MAX44009_LUX_READING_HIGH);
71 if (
error_ != MAX44009_OK) {
72 this->
error_ = MAX44009_ERROR_HIGH_BYTE;
75 uint8_t datalow = this->
read_(MAX44009_LUX_READING_LOW);
76 if (
error_ != MAX44009_OK) {
77 this->
error_ = MAX44009_ERROR_LOW_BYTE;
80 uint8_t exponent = datahigh >> 4;
81 if (exponent == 0x0F) {
82 this->
error_ = MAX44009_ERROR_OVERFLOW;
90 uint8_t exponent = data_high >> 4;
91 uint32_t mantissa = ((data_high & 0x0F) << 4) + (data_low & 0x0F);
92 return ((0x0001 << exponent) * 0.045) * mantissa;
96 uint8_t config = this->
read_(MAX44009_REGISTER_CONFIGURATION);
97 if (this->
error_ == MAX44009_OK) {
98 config |= MAX44009_CFG_CONTINUOUS;
99 this->
write_(MAX44009_REGISTER_CONFIGURATION, config);
101 ESP_LOGV(TAG,
"set to continuous mode");
110 uint8_t config = this->
read_(MAX44009_REGISTER_CONFIGURATION);
111 if (this->
error_ == MAX44009_OK) {
112 config &= ~MAX44009_CFG_CONTINUOUS;
113 this->
write_(MAX44009_REGISTER_CONFIGURATION, config);
115 ESP_LOGV(TAG,
"set to low power mode");
126 this->
error_ = MAX44009_ERROR_WIRE_REQUEST;
128 this->
error_ = MAX44009_OK;
135 this->
error_ = MAX44009_ERROR_WIRE_REQUEST;
137 this->
error_ = MAX44009_OK;
void dump_config() override
bool read_byte(uint8_t a_register, uint8_t *data, bool stop=true)
const float DATA
For components that import data from directly connected sensors like DHT.
void status_set_warning(const char *message="unspecified")
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
void set_mode(MAX44009Mode mode)
float read_illuminance_()
Read the illuminance value.
float convert_to_lux_(uint8_t data_high, uint8_t data_low)
void status_clear_warning()
BedjetMode mode
BedJet operating mode.
void publish_state(float state)
Publish a new state to the front-end.
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)
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
uint8_t read_(uint8_t reg)
float get_setup_priority() const override
bool set_low_power_mode()
bool set_continuous_mode()
void write_(uint8_t reg, uint8_t value)