diff --git a/esphome/components/cst816/binary_sensor/__init__.py b/esphome/components/cst816/binary_sensor/__init__.py index b3fd5bb852..7907cc93ef 100644 --- a/esphome/components/cst816/binary_sensor/__init__.py +++ b/esphome/components/cst816/binary_sensor/__init__.py @@ -1,28 +1,5 @@ -import esphome.codegen as cg import esphome.config_validation as cv -from esphome.components import binary_sensor -from .. import cst816_ns -from ..touchscreen import CST816Touchscreen, CST816ButtonListener - -CONF_CST816_ID = "cst816_id" - -CST816Button = cst816_ns.class_( - "CST816Button", - binary_sensor.BinarySensor, - cg.Component, - CST816ButtonListener, - cg.Parented.template(CST816Touchscreen), +CONFIG_SCHEMA = cv.invalid( + "The CST816 binary sensor has been removed. Instead use the touchscreen binary sensor with the 'use_raw' flag set." ) - -CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(CST816Button).extend( - { - cv.GenerateID(CONF_CST816_ID): cv.use_id(CST816Touchscreen), - } -) - - -async def to_code(config): - var = await binary_sensor.new_binary_sensor(config) - await cg.register_component(var, config) - await cg.register_parented(var, config[CONF_CST816_ID]) diff --git a/esphome/components/cst816/binary_sensor/cst816_button.h b/esphome/components/cst816/binary_sensor/cst816_button.h deleted file mode 100644 index 4ae856d506..0000000000 --- a/esphome/components/cst816/binary_sensor/cst816_button.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "esphome/components/binary_sensor/binary_sensor.h" -#include "esphome/components/cst816/touchscreen/cst816_touchscreen.h" -#include "esphome/core/component.h" -#include "esphome/core/helpers.h" - -namespace esphome { -namespace cst816 { - -class CST816Button : public binary_sensor::BinarySensor, - public Component, - public CST816ButtonListener, - public Parented { - public: - void setup() override { - this->parent_->register_button_listener(this); - this->publish_initial_state(false); - } - - void dump_config() override { LOG_BINARY_SENSOR("", "CST816 Button", this); } - - void update_button(bool state) override { this->publish_state(state); } -}; - -} // namespace cst816 -} // namespace esphome diff --git a/esphome/components/cst816/touchscreen/cst816_touchscreen.cpp b/esphome/components/cst816/touchscreen/cst816_touchscreen.cpp index 7dcb130e20..607f209c4a 100644 --- a/esphome/components/cst816/touchscreen/cst816_touchscreen.cpp +++ b/esphome/components/cst816/touchscreen/cst816_touchscreen.cpp @@ -37,14 +37,6 @@ void CST816Touchscreen::continue_setup_() { ESP_LOGCONFIG(TAG, "CST816 Touchscreen setup complete"); } -void CST816Touchscreen::update_button_state_(bool state) { - if (this->button_touched_ == state) - return; - this->button_touched_ = state; - for (auto *listener : this->button_listeners_) - listener->update_button(state); -} - void CST816Touchscreen::setup() { ESP_LOGCONFIG(TAG, "Setting up CST816 Touchscreen..."); if (this->reset_pin_ != nullptr) { @@ -68,18 +60,13 @@ void CST816Touchscreen::update_touches() { } uint8_t num_of_touches = data[REG_TOUCH_NUM] & 3; if (num_of_touches == 0) { - this->update_button_state_(false); return; } uint16_t x = encode_uint16(data[REG_XPOS_HIGH] & 0xF, data[REG_XPOS_LOW]); uint16_t y = encode_uint16(data[REG_YPOS_HIGH] & 0xF, data[REG_YPOS_LOW]); ESP_LOGV(TAG, "Read touch %d/%d", x, y); - if (x >= this->x_raw_max_) { - this->update_button_state_(true); - } else { - this->add_raw_touch_position_(0, x, y); - } + this->add_raw_touch_position_(0, x, y); } void CST816Touchscreen::dump_config() { @@ -87,6 +74,8 @@ void CST816Touchscreen::dump_config() { LOG_I2C_DEVICE(this); LOG_PIN(" Interrupt Pin: ", this->interrupt_pin_); LOG_PIN(" Reset Pin: ", this->reset_pin_); + ESP_LOGCONFIG(TAG, " X Raw Min: %d, X Raw Max: %d", this->x_raw_min_, this->x_raw_max_); + ESP_LOGCONFIG(TAG, " Y Raw Min: %d, Y Raw Max: %d", this->y_raw_min_, this->y_raw_max_); const char *name; switch (this->chip_id_) { case CST820_CHIP_ID: diff --git a/esphome/components/cst816/touchscreen/cst816_touchscreen.h b/esphome/components/cst816/touchscreen/cst816_touchscreen.h index dc00e675ba..99ea085e37 100644 --- a/esphome/components/cst816/touchscreen/cst816_touchscreen.h +++ b/esphome/components/cst816/touchscreen/cst816_touchscreen.h @@ -40,7 +40,6 @@ class CST816Touchscreen : public touchscreen::Touchscreen, public i2c::I2CDevice public: void setup() override; void update_touches() override; - void register_button_listener(CST816ButtonListener *listener) { this->button_listeners_.push_back(listener); } void dump_config() override; void set_interrupt_pin(InternalGPIOPin *pin) { this->interrupt_pin_ = pin; } @@ -49,14 +48,11 @@ class CST816Touchscreen : public touchscreen::Touchscreen, public i2c::I2CDevice protected: void continue_setup_(); - void update_button_state_(bool state); InternalGPIOPin *interrupt_pin_{}; GPIOPin *reset_pin_{}; uint8_t chip_id_{}; bool skip_probe_{}; // if set, do not expect to be able to probe the controller on the i2c bus. - std::vector button_listeners_; - bool button_touched_{}; }; } // namespace cst816 diff --git a/tests/components/cst816/common.yaml b/tests/components/cst816/common.yaml index a4ac4aafec..9750de15db 100644 --- a/tests/components/cst816/common.yaml +++ b/tests/components/cst816/common.yaml @@ -35,5 +35,11 @@ touchscreen: swap_xy: false binary_sensor: - - platform: cst816 + - platform: touchscreen name: Home Button + use_raw: true + x_min: 0 + x_max: 480 + y_min: 320 + y_max: 360 +