7static const uint8_t PMWCS3_I2C_ADDRESS = 0x63;
8static const uint8_t PMWCS3_REG_READ_START = 0x01;
9static const uint8_t PMWCS3_REG_READ_E25 = 0x02;
10static const uint8_t PMWCS3_REG_READ_EC = 0x03;
11static const uint8_t PMWCS3_REG_READ_TEMP = 0x04;
12static const uint8_t PMWCS3_REG_READ_VWC = 0x05;
13static const uint8_t PMWCS3_REG_CALIBRATE_AIR = 0x06;
14static const uint8_t PMWCS3_REG_CALIBRATE_WATER = 0x07;
15static const uint8_t PMWCS3_SET_I2C_ADDRESS = 0x08;
16static const uint8_t PMWCS3_REG_GET_DATA = 0x09;
17static const uint8_t PMWCS3_REG_CALIBRATE_EC = 0x10;
18static const uint8_t PMWCS3_REG_CAP = 0x0A;
19static const uint8_t PMWCS3_REG_RES = 0x0B;
20static const uint8_t PMWCS3_REG_RC = 0x0C;
21static const uint8_t PMWCS3_REG_RT = 0x0D;
25void PMWCS3Component::new_i2c_address(uint8_t
address) {
28 ESP_LOGW(TAG,
"Setting I2C address failed (%d)",
address);
32 ESP_LOGVV(TAG,
"Set I2C address to %d",
address);
36void PMWCS3Component::air_calibration() {
37 if (!this->
write_bytes(PMWCS3_REG_CALIBRATE_AIR,
nullptr, 0)) {
39 ESP_LOGW(TAG,
"Starting air calibration failed");
42 ESP_LOGW(TAG,
"Running air calibration for 300s");
44void PMWCS3Component::water_calibration() {
45 if (!this->
write_bytes(PMWCS3_REG_CALIBRATE_WATER,
nullptr, 0)) {
47 ESP_LOGW(TAG,
"Starting water calibration failed");
50 ESP_LOGW(TAG,
"Running water calibration for 300s");
55void PMWCS3Component::dump_config() {
56 ESP_LOGCONFIG(TAG,
"PMWCS3");
58 LOG_UPDATE_INTERVAL(
this);
59 LOG_SENSOR(
" ",
"e25", this->e25_sensor_);
60 LOG_SENSOR(
" ",
"ec", this->ec_sensor_);
61 LOG_SENSOR(
" ",
"temperature", this->temperature_sensor_);
62 LOG_SENSOR(
" ",
"vwc", this->vwc_sensor_);
66 if (!this->
write_bytes(PMWCS3_REG_READ_START,
nullptr, 0)) {
68 ESP_LOGVV(TAG,
"Writing REG_READ_START failed");
78 ESP_LOGVV(TAG,
"Reading PMWCS3_REG_GET_DATA failed");
82 if (this->e25_sensor_ !=
nullptr) {
83 e25 = data[0] / 100.0;
84 this->e25_sensor_->publish_state(e25);
85 ESP_LOGVV(TAG,
"e25: raw=%u, result=%f", data[0], e25);
87 if (this->ec_sensor_ !=
nullptr) {
89 this->ec_sensor_->publish_state(ec);
90 ESP_LOGVV(TAG,
"ec: raw=%u, result=%f", data[1], ec);
92 if (this->temperature_sensor_ !=
nullptr) {
94 this->temperature_sensor_->publish_state(
temperature);
95 ESP_LOGVV(TAG,
"temp: raw=%u, result=%f", data[2],
temperature);
97 if (this->vwc_sensor_ !=
nullptr) {
99 this->vwc_sensor_->publish_state(vwc);
100 ESP_LOGVV(TAG,
"vwc: raw=%u, result=%f", data[3], vwc);
bool read_bytes_16_le(uint8_t a_register, uint16_t *data, uint8_t len)
Read len 16-bit values stored least significant byte first; no conversion is compiled on little-endia...