mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	| @@ -209,6 +209,9 @@ void BluetoothProxy::bluetooth_device_request(const api::BluetoothDeviceRequest | |||||||
|   switch (msg.request_type) { |   switch (msg.request_type) { | ||||||
|     case api::enums::BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT: { |     case api::enums::BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT: { | ||||||
|       this->address_ = msg.address; |       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; |       break; | ||||||
|     } |     } | ||||||
|     case api::enums::BLUETOOTH_DEVICE_REQUEST_TYPE_DISCONNECT: { |     case api::enums::BLUETOOTH_DEVICE_REQUEST_TYPE_DISCONNECT: { | ||||||
|   | |||||||
| @@ -145,6 +145,8 @@ class ESPBTDeviceListener { | |||||||
| enum class ClientState { | enum class ClientState { | ||||||
|   // Connection is idle, no device detected. |   // Connection is idle, no device detected. | ||||||
|   IDLE, |   IDLE, | ||||||
|  |   // Searching for device. | ||||||
|  |   SEARCHING, | ||||||
|   // Device advertisement found. |   // Device advertisement found. | ||||||
|   DISCOVERED, |   DISCOVERED, | ||||||
|   // Connection in progress. |   // Connection in progress. | ||||||
|   | |||||||
| @@ -55,6 +55,7 @@ from esphome.const import ( | |||||||
|     DEVICE_CLASS_PM25, |     DEVICE_CLASS_PM25, | ||||||
|     DEVICE_CLASS_POWER, |     DEVICE_CLASS_POWER, | ||||||
|     DEVICE_CLASS_POWER_FACTOR, |     DEVICE_CLASS_POWER_FACTOR, | ||||||
|  |     DEVICE_CLASS_PRECIPITATION_INTENSITY, | ||||||
|     DEVICE_CLASS_PRESSURE, |     DEVICE_CLASS_PRESSURE, | ||||||
|     DEVICE_CLASS_REACTIVE_POWER, |     DEVICE_CLASS_REACTIVE_POWER, | ||||||
|     DEVICE_CLASS_SIGNAL_STRENGTH, |     DEVICE_CLASS_SIGNAL_STRENGTH, | ||||||
| @@ -65,6 +66,8 @@ from esphome.const import ( | |||||||
|     DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS, |     DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS, | ||||||
|     DEVICE_CLASS_VOLTAGE, |     DEVICE_CLASS_VOLTAGE, | ||||||
|     DEVICE_CLASS_VOLUME, |     DEVICE_CLASS_VOLUME, | ||||||
|  |     DEVICE_CLASS_WATER, | ||||||
|  |     DEVICE_CLASS_WIND_SPEED, | ||||||
|     DEVICE_CLASS_WEIGHT, |     DEVICE_CLASS_WEIGHT, | ||||||
| ) | ) | ||||||
| from esphome.core import CORE, coroutine_with_priority | from esphome.core import CORE, coroutine_with_priority | ||||||
| @@ -100,6 +103,7 @@ DEVICE_CLASSES = [ | |||||||
|     DEVICE_CLASS_PM25, |     DEVICE_CLASS_PM25, | ||||||
|     DEVICE_CLASS_POWER, |     DEVICE_CLASS_POWER, | ||||||
|     DEVICE_CLASS_POWER_FACTOR, |     DEVICE_CLASS_POWER_FACTOR, | ||||||
|  |     DEVICE_CLASS_PRECIPITATION_INTENSITY, | ||||||
|     DEVICE_CLASS_PRESSURE, |     DEVICE_CLASS_PRESSURE, | ||||||
|     DEVICE_CLASS_REACTIVE_POWER, |     DEVICE_CLASS_REACTIVE_POWER, | ||||||
|     DEVICE_CLASS_SIGNAL_STRENGTH, |     DEVICE_CLASS_SIGNAL_STRENGTH, | ||||||
| @@ -110,6 +114,8 @@ DEVICE_CLASSES = [ | |||||||
|     DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS, |     DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS, | ||||||
|     DEVICE_CLASS_VOLTAGE, |     DEVICE_CLASS_VOLTAGE, | ||||||
|     DEVICE_CLASS_VOLUME, |     DEVICE_CLASS_VOLUME, | ||||||
|  |     DEVICE_CLASS_WATER, | ||||||
|  |     DEVICE_CLASS_WIND_SPEED, | ||||||
|     DEVICE_CLASS_WEIGHT, |     DEVICE_CLASS_WEIGHT, | ||||||
| ] | ] | ||||||
|  |  | ||||||
|   | |||||||
| @@ -20,8 +20,6 @@ void XPT2046Component::setup() { | |||||||
|     this->irq_pin_->setup();  // INPUT |     this->irq_pin_->setup();  // INPUT | ||||||
|     this->irq_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP); |     this->irq_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP); | ||||||
|     this->irq_pin_->setup(); |     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); |     this->irq_pin_->attach_interrupt(XPT2046TouchscreenStore::gpio_intr, &this->store_, gpio::INTERRUPT_FALLING_EDGE); | ||||||
|   } |   } | ||||||
|   spi_setup(); |   spi_setup(); | ||||||
| @@ -29,10 +27,10 @@ void XPT2046Component::setup() { | |||||||
| } | } | ||||||
|  |  | ||||||
| void XPT2046Component::loop() { | void XPT2046Component::loop() { | ||||||
|   if ((this->irq_pin_ == nullptr) || (!this->store_.touch)) |   if ((this->irq_pin_ != nullptr) && (this->store_.touch || this->touched)) { | ||||||
|     return; |  | ||||||
|     this->store_.touch = false; |     this->store_.touch = false; | ||||||
|     check_touch_(); |     check_touch_(); | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| void XPT2046Component::update() { | void XPT2046Component::update() { | ||||||
| @@ -45,35 +43,30 @@ void XPT2046Component::check_touch_() { | |||||||
|   bool touch = false; |   bool touch = false; | ||||||
|   uint32_t now = millis(); |   uint32_t now = millis(); | ||||||
|  |  | ||||||
|   this->z_raw = 0; |  | ||||||
|  |  | ||||||
|   // 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(); |   enable(); | ||||||
|  |  | ||||||
|   int16_t touch_pressure_1 = read_adc_(0xB1 /* touch_pressure_1 */); |   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_2 = read_adc_(0xC1 /* touch_pressure_2 */); | ||||||
|  |  | ||||||
|     this->z_raw = touch_pressure_1 + 4095 - touch_pressure_2; |   this->z_raw = touch_pressure_1 + 0Xfff - touch_pressure_2; | ||||||
|  |  | ||||||
|   touch = (this->z_raw >= this->threshold_); |   touch = (this->z_raw >= this->threshold_); | ||||||
|   if (touch) { |   if (touch) { | ||||||
|       read_adc_(0x91 /* Y */);  // dummy Y measure, 1st is always noisy |     read_adc_(0xD1 /* X */);  // dummy Y measure, 1st is always noisy | ||||||
|       data[0] = read_adc_(0xD1 /* X */); |     data[0] = read_adc_(0x91 /* Y */); | ||||||
|       data[1] = read_adc_(0x91 /* Y */);  // make 3 x-y measurements |     data[1] = read_adc_(0xD1 /* X */);  // make 3 x-y measurements | ||||||
|       data[2] = read_adc_(0xD1 /* X */); |     data[2] = read_adc_(0x91 /* Y */); | ||||||
|       data[3] = read_adc_(0x91 /* Y */); |     data[3] = read_adc_(0xD1 /* X */); | ||||||
|       data[4] = read_adc_(0xD1 /* X */); |     data[4] = read_adc_(0x91 /* Y */); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|     data[5] = read_adc_(0x90 /* Y */);  // Last Y touch power down |   data[5] = read_adc_(0xD0 /* X */);  // Last X touch power down | ||||||
|  |  | ||||||
|   disable(); |   disable(); | ||||||
|  |  | ||||||
|   if (touch) { |   if (touch) { | ||||||
|       this->x_raw = best_two_avg(data[0], data[2], data[4]); |     this->x_raw = best_two_avg(data[1], data[3], data[5]); | ||||||
|       this->y_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); |     ESP_LOGVV(TAG, "Update [x, y] = [%d, %d], z = %d", this->x_raw, this->y_raw, this->z_raw); | ||||||
|  |  | ||||||
| @@ -124,16 +117,15 @@ void XPT2046Component::check_touch_() { | |||||||
|       this->touched = true; |       this->touched = true; | ||||||
|       this->last_pos_ms_ = now; |       this->last_pos_ms_ = now; | ||||||
|     } |     } | ||||||
|     } else { |   } | ||||||
|       this->x_raw = this->y_raw = 0; |  | ||||||
|       if (this->touched) { |   if (!touch && this->touched) { | ||||||
|  |     this->x_raw = this->y_raw = this->z_raw = 0; | ||||||
|     ESP_LOGV(TAG, "Released [%d, %d]", this->x, this->y); |     ESP_LOGV(TAG, "Released [%d, %d]", this->x, this->y); | ||||||
|     this->touched = false; |     this->touched = false; | ||||||
|     for (auto *listener : this->touch_listeners_) |     for (auto *listener : this->touch_listeners_) | ||||||
|       listener->release(); |       listener->release(); | ||||||
|   } |   } | ||||||
|     } |  | ||||||
|   } |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void XPT2046Component::set_calibration(int16_t x_min, int16_t x_max, int16_t y_min, int16_t y_max) {  // NOLINT | void XPT2046Component::set_calibration(int16_t x_min, int16_t x_max, int16_t y_min, int16_t y_max) {  // NOLINT | ||||||
| @@ -203,6 +195,7 @@ int16_t XPT2046Component::read_adc_(uint8_t ctrl) {  // NOLINT | |||||||
|   uint8_t data[2]; |   uint8_t data[2]; | ||||||
|  |  | ||||||
|   write_byte(ctrl); |   write_byte(ctrl); | ||||||
|  |   delay(1); | ||||||
|   data[0] = read_byte(); |   data[0] = read_byte(); | ||||||
|   data[1] = read_byte(); |   data[1] = read_byte(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -14,8 +14,6 @@ using namespace touchscreen; | |||||||
|  |  | ||||||
| struct XPT2046TouchscreenStore { | struct XPT2046TouchscreenStore { | ||||||
|   volatile bool touch; |   volatile bool touch; | ||||||
|   ISRInternalGPIOPin pin; |  | ||||||
|  |  | ||||||
|   static void gpio_intr(XPT2046TouchscreenStore *store); |   static void gpio_intr(XPT2046TouchscreenStore *store); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| """Constants used by esphome.""" | """Constants used by esphome.""" | ||||||
|  |  | ||||||
| __version__ = "2022.10.0" | __version__ = "2022.10.1" | ||||||
|  |  | ||||||
| ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_" | ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_" | ||||||
|  |  | ||||||
| @@ -947,6 +947,7 @@ DEVICE_CLASS_PM1 = "pm1" | |||||||
| DEVICE_CLASS_PM10 = "pm10" | DEVICE_CLASS_PM10 = "pm10" | ||||||
| DEVICE_CLASS_PM25 = "pm25" | DEVICE_CLASS_PM25 = "pm25" | ||||||
| DEVICE_CLASS_POWER_FACTOR = "power_factor" | DEVICE_CLASS_POWER_FACTOR = "power_factor" | ||||||
|  | DEVICE_CLASS_PRECIPITATION_INTENSITY = "precipitation_intensity" | ||||||
| DEVICE_CLASS_PRESSURE = "pressure" | DEVICE_CLASS_PRESSURE = "pressure" | ||||||
| DEVICE_CLASS_REACTIVE_POWER = "reactive_power" | DEVICE_CLASS_REACTIVE_POWER = "reactive_power" | ||||||
| DEVICE_CLASS_SIGNAL_STRENGTH = "signal_strength" | DEVICE_CLASS_SIGNAL_STRENGTH = "signal_strength" | ||||||
| @@ -957,6 +958,8 @@ DEVICE_CLASS_TIMESTAMP = "timestamp" | |||||||
| DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS = "volatile_organic_compounds" | DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS = "volatile_organic_compounds" | ||||||
| DEVICE_CLASS_VOLTAGE = "voltage" | DEVICE_CLASS_VOLTAGE = "voltage" | ||||||
| DEVICE_CLASS_VOLUME = "volume" | DEVICE_CLASS_VOLUME = "volume" | ||||||
|  | DEVICE_CLASS_WATER = "water" | ||||||
|  | DEVICE_CLASS_WIND_SPEED = "wind_speed" | ||||||
| DEVICE_CLASS_WEIGHT = "weight" | DEVICE_CLASS_WEIGHT = "weight" | ||||||
| # device classes of both binary_sensor and button component | # device classes of both binary_sensor and button component | ||||||
| DEVICE_CLASS_UPDATE = "update" | DEVICE_CLASS_UPDATE = "update" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user