8 static const uint8_t PMWCS3_I2C_ADDRESS = 0x63;
9 static const uint8_t PMWCS3_REG_READ_START = 0x01;
10 static const uint8_t PMWCS3_REG_READ_E25 = 0x02;
11 static const uint8_t PMWCS3_REG_READ_EC = 0x03;
12 static const uint8_t PMWCS3_REG_READ_TEMP = 0x04;
13 static const uint8_t PMWCS3_REG_READ_VWC = 0x05;
14 static const uint8_t PMWCS3_REG_CALIBRATE_AIR = 0x06;
15 static const uint8_t PMWCS3_REG_CALIBRATE_WATER = 0x07;
16 static const uint8_t PMWCS3_SET_I2C_ADDRESS = 0x08;
17 static const uint8_t PMWCS3_REG_GET_DATA = 0x09;
18 static const uint8_t PMWCS3_REG_CALIBRATE_EC = 0x10;
19 static const uint8_t PMWCS3_REG_CAP = 0x0A;
20 static const uint8_t PMWCS3_REG_RES = 0x0B;
21 static const uint8_t PMWCS3_REG_RC = 0x0C;
22 static const uint8_t PMWCS3_REG_RT = 0x0D;
24 static const char *
const TAG =
"pmwcs3";
27 if (!this->
write_byte(PMWCS3_SET_I2C_ADDRESS, address)) {
29 ESP_LOGW(TAG,
"couldn't write the new I2C address %d", address);
33 ESP_LOGVV(TAG,
"changed I2C address to %d", address);
38 if (!this->
write_bytes(PMWCS3_REG_CALIBRATE_AIR,
nullptr, 0)) {
40 ESP_LOGW(TAG,
"couldn't start air calibration");
43 ESP_LOGW(TAG,
"Start air calibration during the next 300s");
46 if (!this->
write_bytes(PMWCS3_REG_CALIBRATE_WATER,
nullptr, 0)) {
48 ESP_LOGW(TAG,
"couldn't start water calibration");
51 ESP_LOGW(TAG,
"Start water calibration during the next 300s");
61 ESP_LOGCONFIG(TAG,
"PMWCS3");
64 ESP_LOGE(TAG,
"Communication with PMWCS3 failed!");
66 ESP_LOGI(TAG,
"%s", this->
is_failed() ?
"FAILED" :
"OK");
68 LOG_UPDATE_INTERVAL(
this);
76 if (!this->
write_bytes(PMWCS3_REG_READ_START,
nullptr, 0)) {
78 ESP_LOGVV(TAG,
"Failed to write into REG_READ_START register !!!");
87 if (!this->
read_bytes(PMWCS3_REG_GET_DATA, (uint8_t *) &data, 8)) {
88 ESP_LOGVV(TAG,
"Error reading PMWCS3_REG_GET_DATA registers");
93 e25 = ((data[1] << 8) | data[0]) / 100.0;
95 ESP_LOGVV(TAG,
"e25: data[0]=%d, data[1]=%d, result=%f", data[0], data[1], e25);
98 ec = ((data[3] << 8) | data[2]) / 10.0;
100 ESP_LOGVV(TAG,
"ec: data[2]=%d, data[3]=%d, result=%f", data[2], data[3], ec);
103 temperature = ((data[5] << 8) | data[4]) / 100.0;
105 ESP_LOGVV(TAG,
"temp: data[4]=%d, data[5]=%d, result=%f", data[4], data[5], temperature);
108 vwc = ((data[7] << 8) | data[6]) / 10.0;
110 ESP_LOGVV(TAG,
"vwc: data[6]=%d, data[7]=%d, result=%f", data[6], data[7], vwc);
sensor::Sensor * temperature_sensor_
const float DATA
For components that import data from directly connected sensors like DHT.
float get_setup_priority() const override
void status_set_warning(const char *message="unspecified")
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
void dump_config() override
void new_i2c_address(uint8_t newaddress)
sensor::Sensor * vwc_sensor_
sensor::Sensor * e25_sensor_
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
sensor::Sensor * ec_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.
void set_i2c_address(uint8_t address)
We store the address of the device on the bus.
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len, bool stop=true)