ESPHome  2025.3.2
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
chsc6x_touchscreen.cpp
Go to the documentation of this file.
1 #include "chsc6x_touchscreen.h"
2 
3 namespace esphome {
4 namespace chsc6x {
5 
7  ESP_LOGCONFIG(TAG, "Setting up CHSC6X Touchscreen...");
8  if (this->interrupt_pin_ != nullptr) {
9  this->interrupt_pin_->setup();
11  }
12  if (this->x_raw_max_ == this->x_raw_min_) {
13  this->x_raw_max_ = this->display_->get_native_width();
14  }
15  if (this->y_raw_max_ == this->y_raw_min_) {
16  this->y_raw_max_ = this->display_->get_native_height();
17  }
18 
19  ESP_LOGCONFIG(TAG, "CHSC6X Touchscreen setup complete");
20 }
21 
23  uint8_t data[CHSC6X_REG_STATUS_LEN];
24  if (!this->read_bytes(CHSC6X_REG_STATUS, data, sizeof(data))) {
25  return;
26  }
27 
28  uint8_t num_of_touches = data[CHSC6X_REG_STATUS_TOUCH];
29 
30  if (num_of_touches == 1) {
31  uint16_t x = data[CHSC6X_REG_STATUS_X_COR];
32  uint16_t y = data[CHSC6X_REG_STATUS_Y_COR];
33  this->add_raw_touch_position_(0, x, y);
34  }
35 }
36 
38  ESP_LOGCONFIG(TAG, "CHSC6X Touchscreen:");
39  LOG_I2C_DEVICE(this);
40  LOG_PIN(" Interrupt Pin: ", this->interrupt_pin_);
41  ESP_LOGCONFIG(TAG, " Touch timeout: %d", this->touch_timeout_);
42  ESP_LOGCONFIG(TAG, " x_raw_max_: %d", this->x_raw_max_);
43  ESP_LOGCONFIG(TAG, " y_raw_max_: %d", this->y_raw_max_);
44 }
45 
46 } // namespace chsc6x
47 } // namespace esphome
uint16_t x
Definition: tt21100.cpp:17
int get_native_height()
Get the native (original) height of the display in pixels.
Definition: display.h:223
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
Definition: i2c.h:212
virtual void setup()=0
uint16_t y
Definition: tt21100.cpp:18
int get_native_width()
Get the native (original) width of the display in pixels.
Definition: display.h:221
void attach_interrupt_(InternalGPIOPin *irq_pin, esphome::gpio::InterruptType type)
Call this function to send touch points to the on_touch listener and the binary_sensors.
Definition: touchscreen.cpp:12
void add_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_raw, int16_t z_raw=0)
Definition: touchscreen.cpp:74
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7