7static const char *
const TAG =
"max44009.sensor";
10static constexpr uint8_t MAX44009_REGISTER_CONFIGURATION = 0x02;
11static constexpr uint8_t MAX44009_LUX_READING_HIGH = 0x03;
12static constexpr uint8_t MAX44009_LUX_READING_LOW = 0x04;
14static constexpr uint8_t MAX44009_CFG_CONTINUOUS = 0x80;
16static constexpr int8_t MAX44009_OK = 0;
17static constexpr int8_t MAX44009_ERROR_WIRE_REQUEST = -10;
18static constexpr int8_t MAX44009_ERROR_OVERFLOW = -20;
19static constexpr int8_t MAX44009_ERROR_HIGH_BYTE = -30;
20static constexpr int8_t MAX44009_ERROR_LOW_BYTE = -31;
23 bool state_ok =
false;
46 ESP_LOGCONFIG(TAG,
"MAX44009:");
49 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
56 if (this->
error_ != MAX44009_OK) {
66 uint8_t datahigh = this->
read_(MAX44009_LUX_READING_HIGH);
67 if (
error_ != MAX44009_OK) {
68 this->
error_ = MAX44009_ERROR_HIGH_BYTE;
71 uint8_t datalow = this->
read_(MAX44009_LUX_READING_LOW);
72 if (
error_ != MAX44009_OK) {
73 this->
error_ = MAX44009_ERROR_LOW_BYTE;
76 uint8_t exponent = datahigh >> 4;
77 if (exponent == 0x0F) {
78 this->
error_ = MAX44009_ERROR_OVERFLOW;
86 uint8_t exponent = data_high >> 4;
87 uint32_t mantissa = ((data_high & 0x0F) << 4) + (data_low & 0x0F);
88 return ((0x0001 << exponent) * 0.045) * mantissa;
92 uint8_t config = this->
read_(MAX44009_REGISTER_CONFIGURATION);
93 if (this->
error_ == MAX44009_OK) {
94 config |= MAX44009_CFG_CONTINUOUS;
95 this->
write_(MAX44009_REGISTER_CONFIGURATION, config);
97 ESP_LOGV(TAG,
"set to continuous mode");
106 uint8_t config = this->
read_(MAX44009_REGISTER_CONFIGURATION);
107 if (this->
error_ == MAX44009_OK) {
108 config &= ~MAX44009_CFG_CONTINUOUS;
109 this->
write_(MAX44009_REGISTER_CONFIGURATION, config);
111 ESP_LOGV(TAG,
"set to low power mode");
122 this->
error_ = MAX44009_ERROR_WIRE_REQUEST;
124 this->
error_ = MAX44009_OK;
131 this->
error_ = MAX44009_ERROR_WIRE_REQUEST;
133 this->
error_ = MAX44009_OK;
BedjetMode mode
BedJet operating mode.
void mark_failed()
Mark this component as failed.
void status_set_warning()
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) const
bool read_byte(uint8_t a_register, uint8_t *data)
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