From e96d7483b3acec403cb1cec25ae0ff8b8656d282 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Tue, 25 Oct 2022 12:54:10 +1300 Subject: [PATCH 1/5] Update bluetooth proxy limit as soon as connection requested (#3935) --- esphome/components/bluetooth_proxy/bluetooth_proxy.cpp | 3 +++ esphome/components/esp32_ble_tracker/esp32_ble_tracker.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp b/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp index cc1c178b08..5dfdc06070 100644 --- a/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp +++ b/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp @@ -209,6 +209,9 @@ void BluetoothProxy::bluetooth_device_request(const api::BluetoothDeviceRequest switch (msg.request_type) { case api::enums::BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT: { this->address_ = msg.address; + this->set_state(espbt::ClientState::SEARCHING); + api::global_api_server->send_bluetooth_connections_free(this->get_bluetooth_connections_free(), + this->get_bluetooth_connections_limit()); break; } case api::enums::BLUETOOTH_DEVICE_REQUEST_TYPE_DISCONNECT: { diff --git a/esphome/components/esp32_ble_tracker/esp32_ble_tracker.h b/esphome/components/esp32_ble_tracker/esp32_ble_tracker.h index 45abcd63fa..dd08f07fd7 100644 --- a/esphome/components/esp32_ble_tracker/esp32_ble_tracker.h +++ b/esphome/components/esp32_ble_tracker/esp32_ble_tracker.h @@ -145,6 +145,8 @@ class ESPBTDeviceListener { enum class ClientState { // Connection is idle, no device detected. IDLE, + // Searching for device. + SEARCHING, // Device advertisement found. DISCOVERED, // Connection in progress. From ca09693efa97458cdb735dfe312487172f21e55a Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 25 Oct 2022 09:37:19 +0200 Subject: [PATCH 2/5] Add water & precipitation_intensity sensor device classes (#3940) --- esphome/components/sensor/__init__.py | 4 ++++ esphome/const.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/esphome/components/sensor/__init__.py b/esphome/components/sensor/__init__.py index 12daf34d6e..3ed27390bd 100644 --- a/esphome/components/sensor/__init__.py +++ b/esphome/components/sensor/__init__.py @@ -55,6 +55,7 @@ from esphome.const import ( DEVICE_CLASS_PM25, DEVICE_CLASS_POWER, DEVICE_CLASS_POWER_FACTOR, + DEVICE_CLASS_PRECIPITATION_INTENSITY, DEVICE_CLASS_PRESSURE, DEVICE_CLASS_REACTIVE_POWER, DEVICE_CLASS_SIGNAL_STRENGTH, @@ -65,6 +66,7 @@ from esphome.const import ( DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS, DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLUME, + DEVICE_CLASS_WATER, DEVICE_CLASS_WEIGHT, ) from esphome.core import CORE, coroutine_with_priority @@ -100,6 +102,7 @@ DEVICE_CLASSES = [ DEVICE_CLASS_PM25, DEVICE_CLASS_POWER, DEVICE_CLASS_POWER_FACTOR, + DEVICE_CLASS_PRECIPITATION_INTENSITY, DEVICE_CLASS_PRESSURE, DEVICE_CLASS_REACTIVE_POWER, DEVICE_CLASS_SIGNAL_STRENGTH, @@ -110,6 +113,7 @@ DEVICE_CLASSES = [ DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS, DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLUME, + DEVICE_CLASS_WATER, DEVICE_CLASS_WEIGHT, ] diff --git a/esphome/const.py b/esphome/const.py index d2bac8f9df..96dfc47dbc 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -947,6 +947,7 @@ DEVICE_CLASS_PM1 = "pm1" DEVICE_CLASS_PM10 = "pm10" DEVICE_CLASS_PM25 = "pm25" DEVICE_CLASS_POWER_FACTOR = "power_factor" +DEVICE_CLASS_PRECIPITATION_INTENSITY = "precipitation_intensity" DEVICE_CLASS_PRESSURE = "pressure" DEVICE_CLASS_REACTIVE_POWER = "reactive_power" DEVICE_CLASS_SIGNAL_STRENGTH = "signal_strength" @@ -957,6 +958,7 @@ DEVICE_CLASS_TIMESTAMP = "timestamp" DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS = "volatile_organic_compounds" DEVICE_CLASS_VOLTAGE = "voltage" DEVICE_CLASS_VOLUME = "volume" +DEVICE_CLASS_WATER = "water" DEVICE_CLASS_WEIGHT = "weight" # device classes of both binary_sensor and button component DEVICE_CLASS_UPDATE = "update" From 0220934e4cef6677d585a4992cd17cd4bf80f5fd Mon Sep 17 00:00:00 2001 From: NP v/d Spek Date: Tue, 25 Oct 2022 20:33:18 +0200 Subject: [PATCH 3/5] Fixed touch release issue using the interrupt pin (#3925) Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> --- esphome/components/xpt2046/xpt2046.cpp | 159 ++++++++++++------------- esphome/components/xpt2046/xpt2046.h | 2 - 2 files changed, 76 insertions(+), 85 deletions(-) diff --git a/esphome/components/xpt2046/xpt2046.cpp b/esphome/components/xpt2046/xpt2046.cpp index d6cbe39aa0..e3317e0fd5 100644 --- a/esphome/components/xpt2046/xpt2046.cpp +++ b/esphome/components/xpt2046/xpt2046.cpp @@ -20,8 +20,6 @@ void XPT2046Component::setup() { this->irq_pin_->setup(); // INPUT this->irq_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP); this->irq_pin_->setup(); - - this->store_.pin = this->irq_pin_->to_isr(); this->irq_pin_->attach_interrupt(XPT2046TouchscreenStore::gpio_intr, &this->store_, gpio::INTERRUPT_FALLING_EDGE); } spi_setup(); @@ -29,10 +27,10 @@ void XPT2046Component::setup() { } void XPT2046Component::loop() { - if ((this->irq_pin_ == nullptr) || (!this->store_.touch)) - return; - this->store_.touch = false; - check_touch_(); + if ((this->irq_pin_ != nullptr) && (this->store_.touch || this->touched)) { + this->store_.touch = false; + check_touch_(); + } } void XPT2046Component::update() { @@ -45,94 +43,88 @@ void XPT2046Component::check_touch_() { bool touch = false; uint32_t now = millis(); - this->z_raw = 0; + enable(); - // In case the penirq pin is present only do the SPI transaction if it reports a touch (is low). - // The touch has to be also confirmed with checking the pressure over threshold - if ((this->irq_pin_ == nullptr) || !this->irq_pin_->digital_read()) { - enable(); + int16_t touch_pressure_1 = read_adc_(0xB1 /* touch_pressure_1 */); + int16_t touch_pressure_2 = read_adc_(0xC1 /* touch_pressure_2 */); - int16_t touch_pressure_1 = read_adc_(0xB1 /* touch_pressure_1 */); - int16_t touch_pressure_2 = read_adc_(0xC1 /* touch_pressure_2 */); + this->z_raw = touch_pressure_1 + 0Xfff - touch_pressure_2; - this->z_raw = touch_pressure_1 + 4095 - touch_pressure_2; + touch = (this->z_raw >= this->threshold_); + if (touch) { + read_adc_(0xD1 /* X */); // dummy Y measure, 1st is always noisy + data[0] = read_adc_(0x91 /* Y */); + data[1] = read_adc_(0xD1 /* X */); // make 3 x-y measurements + data[2] = read_adc_(0x91 /* Y */); + data[3] = read_adc_(0xD1 /* X */); + data[4] = read_adc_(0x91 /* Y */); + } - touch = (this->z_raw >= this->threshold_); - if (touch) { - read_adc_(0x91 /* Y */); // dummy Y measure, 1st is always noisy - data[0] = read_adc_(0xD1 /* X */); - data[1] = read_adc_(0x91 /* Y */); // make 3 x-y measurements - data[2] = read_adc_(0xD1 /* X */); - data[3] = read_adc_(0x91 /* Y */); - data[4] = read_adc_(0xD1 /* X */); + data[5] = read_adc_(0xD0 /* X */); // Last X touch power down + + disable(); + + if (touch) { + this->x_raw = best_two_avg(data[1], data[3], data[5]); + this->y_raw = best_two_avg(data[0], data[2], data[4]); + + ESP_LOGVV(TAG, "Update [x, y] = [%d, %d], z = %d", this->x_raw, this->y_raw, this->z_raw); + + TouchPoint touchpoint; + + touchpoint.x = normalize(this->x_raw, this->x_raw_min_, this->x_raw_max_); + touchpoint.y = normalize(this->y_raw, this->y_raw_min_, this->y_raw_max_); + + if (this->swap_x_y_) { + std::swap(touchpoint.x, touchpoint.y); } - data[5] = read_adc_(0x90 /* Y */); // Last Y touch power down + if (this->invert_x_) { + touchpoint.x = 0xfff - touchpoint.x; + } - disable(); + if (this->invert_y_) { + touchpoint.y = 0xfff - touchpoint.y; + } - if (touch) { - this->x_raw = best_two_avg(data[0], data[2], data[4]); - this->y_raw = best_two_avg(data[1], data[3], data[5]); - - ESP_LOGVV(TAG, "Update [x, y] = [%d, %d], z = %d", this->x_raw, this->y_raw, this->z_raw); - - TouchPoint touchpoint; - - touchpoint.x = normalize(this->x_raw, this->x_raw_min_, this->x_raw_max_); - touchpoint.y = normalize(this->y_raw, this->y_raw_min_, this->y_raw_max_); - - if (this->swap_x_y_) { + switch (static_cast(this->display_->get_rotation())) { + case ROTATE_0_DEGREES: + break; + case ROTATE_90_DEGREES: std::swap(touchpoint.x, touchpoint.y); - } - - if (this->invert_x_) { - touchpoint.x = 0xfff - touchpoint.x; - } - - if (this->invert_y_) { touchpoint.y = 0xfff - touchpoint.y; - } - - switch (static_cast(this->display_->get_rotation())) { - case ROTATE_0_DEGREES: - break; - case ROTATE_90_DEGREES: - std::swap(touchpoint.x, touchpoint.y); - touchpoint.y = 0xfff - touchpoint.y; - break; - case ROTATE_180_DEGREES: - touchpoint.x = 0xfff - touchpoint.x; - touchpoint.y = 0xfff - touchpoint.y; - break; - case ROTATE_270_DEGREES: - std::swap(touchpoint.x, touchpoint.y); - touchpoint.x = 0xfff - touchpoint.x; - break; - } - - touchpoint.x = (int16_t)((int) touchpoint.x * this->display_->get_width() / 0xfff); - touchpoint.y = (int16_t)((int) touchpoint.y * this->display_->get_height() / 0xfff); - - if (!this->touched || (now - this->last_pos_ms_) >= this->report_millis_) { - ESP_LOGV(TAG, "Touching at [%03X, %03X] => [%3d, %3d]", this->x_raw, this->y_raw, touchpoint.x, touchpoint.y); - - this->defer([this, touchpoint]() { this->send_touch_(touchpoint); }); - - this->x = touchpoint.x; - this->y = touchpoint.y; - this->touched = true; - this->last_pos_ms_ = now; - } - } else { - this->x_raw = this->y_raw = 0; - if (this->touched) { - ESP_LOGV(TAG, "Released [%d, %d]", this->x, this->y); - this->touched = false; - for (auto *listener : this->touch_listeners_) - listener->release(); - } + break; + case ROTATE_180_DEGREES: + touchpoint.x = 0xfff - touchpoint.x; + touchpoint.y = 0xfff - touchpoint.y; + break; + case ROTATE_270_DEGREES: + std::swap(touchpoint.x, touchpoint.y); + touchpoint.x = 0xfff - touchpoint.x; + break; } + + touchpoint.x = (int16_t)((int) touchpoint.x * this->display_->get_width() / 0xfff); + touchpoint.y = (int16_t)((int) touchpoint.y * this->display_->get_height() / 0xfff); + + if (!this->touched || (now - this->last_pos_ms_) >= this->report_millis_) { + ESP_LOGV(TAG, "Touching at [%03X, %03X] => [%3d, %3d]", this->x_raw, this->y_raw, touchpoint.x, touchpoint.y); + + this->defer([this, touchpoint]() { this->send_touch_(touchpoint); }); + + this->x = touchpoint.x; + this->y = touchpoint.y; + this->touched = true; + this->last_pos_ms_ = now; + } + } + + if (!touch && this->touched) { + this->x_raw = this->y_raw = this->z_raw = 0; + ESP_LOGV(TAG, "Released [%d, %d]", this->x, this->y); + this->touched = false; + for (auto *listener : this->touch_listeners_) + listener->release(); } } @@ -203,6 +195,7 @@ int16_t XPT2046Component::read_adc_(uint8_t ctrl) { // NOLINT uint8_t data[2]; write_byte(ctrl); + delay(1); data[0] = read_byte(); data[1] = read_byte(); diff --git a/esphome/components/xpt2046/xpt2046.h b/esphome/components/xpt2046/xpt2046.h index c3d0462c6a..e7d9caba21 100644 --- a/esphome/components/xpt2046/xpt2046.h +++ b/esphome/components/xpt2046/xpt2046.h @@ -14,8 +14,6 @@ using namespace touchscreen; struct XPT2046TouchscreenStore { volatile bool touch; - ISRInternalGPIOPin pin; - static void gpio_intr(XPT2046TouchscreenStore *store); }; From 01adece6736cad79be1dcdba492d1510fdae994e Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 25 Oct 2022 20:35:12 +0200 Subject: [PATCH 4/5] Add wind_speed sensor device class (#3941) --- esphome/components/sensor/__init__.py | 2 ++ esphome/const.py | 1 + 2 files changed, 3 insertions(+) diff --git a/esphome/components/sensor/__init__.py b/esphome/components/sensor/__init__.py index 3ed27390bd..2859dc6e5a 100644 --- a/esphome/components/sensor/__init__.py +++ b/esphome/components/sensor/__init__.py @@ -67,6 +67,7 @@ from esphome.const import ( DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLUME, DEVICE_CLASS_WATER, + DEVICE_CLASS_WIND_SPEED, DEVICE_CLASS_WEIGHT, ) from esphome.core import CORE, coroutine_with_priority @@ -114,6 +115,7 @@ DEVICE_CLASSES = [ DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLUME, DEVICE_CLASS_WATER, + DEVICE_CLASS_WIND_SPEED, DEVICE_CLASS_WEIGHT, ] diff --git a/esphome/const.py b/esphome/const.py index 96dfc47dbc..8f1dd48539 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -959,6 +959,7 @@ DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS = "volatile_organic_compounds" DEVICE_CLASS_VOLTAGE = "voltage" DEVICE_CLASS_VOLUME = "volume" DEVICE_CLASS_WATER = "water" +DEVICE_CLASS_WIND_SPEED = "wind_speed" DEVICE_CLASS_WEIGHT = "weight" # device classes of both binary_sensor and button component DEVICE_CLASS_UPDATE = "update" From b8549d323c5062e3c2e2b7136684d1c5ef3b0ba9 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Wed, 26 Oct 2022 12:08:19 +1300 Subject: [PATCH 5/5] Bump version to 2022.10.1 --- esphome/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/const.py b/esphome/const.py index 8f1dd48539..2fb03722a0 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -1,6 +1,6 @@ """Constants used by esphome.""" -__version__ = "2022.10.0" +__version__ = "2022.10.1" ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"