ESPHome  2023.5.4
Public Member Functions | Data Fields | Protected Member Functions | Static Protected Member Functions | Protected Attributes
esphome::xpt2046::XPT2046Component Class Reference

#include <xpt2046.h>

Inheritance diagram for esphome::xpt2046::XPT2046Component:
esphome::touchscreen::Touchscreen esphome::PollingComponent esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_2MHZ > esphome::Component

Public Member Functions

void set_dimensions (int16_t x, int16_t y)
 Set the logical touch screen dimensions. More...
 
void set_calibration (int16_t x_min, int16_t x_max, int16_t y_min, int16_t y_max)
 Set the coordinates for the touch screen edges. More...
 
void set_swap_x_y (bool val)
 If true the x and y axes will be swapped. More...
 
void set_report_interval (uint32_t interval)
 Set the interval to report the touch point perodically. More...
 
uint32_t get_report_interval ()
 
void set_threshold (int16_t threshold)
 Set the threshold for the touch detection. More...
 
void set_irq_pin (InternalGPIOPin *pin)
 Set the pin used to detect the touch. More...
 
void setup () override
 
void dump_config () override
 
float get_setup_priority () const override
 
void loop () override
 Detect the touch if the irq pin is specified. More...
 
void update () override
 Read and process the values from the hardware. More...
 
- Public Member Functions inherited from esphome::touchscreen::Touchscreen
void set_display (display::DisplayBuffer *display)
 
display::DisplayBufferget_display () const
 
Trigger< TouchPoint > * get_touch_trigger ()
 
void register_listener (TouchListener *listener)
 
- Public Member Functions inherited from esphome::PollingComponent
 PollingComponent ()
 
 PollingComponent (uint32_t update_interval)
 Initialize this polling component with the given update interval in ms. More...
 
virtual void set_update_interval (uint32_t update_interval)
 Manually set the update interval in ms for this polling object. More...
 
void call_setup () override
 
virtual uint32_t get_update_interval () const
 Get the update interval in ms of this sensor. More...
 
- Public Member Functions inherited from esphome::Component
float get_actual_setup_priority () const
 
void set_setup_priority (float priority)
 
virtual float get_loop_priority () const
 priority of loop(). More...
 
void call ()
 
virtual void on_shutdown ()
 
virtual void on_safe_shutdown ()
 
uint32_t get_component_state () const
 
virtual void mark_failed ()
 Mark this component as failed. More...
 
bool is_failed ()
 
bool is_ready ()
 
virtual bool can_proceed ()
 
bool status_has_warning ()
 
bool status_has_error ()
 
void status_set_warning ()
 
void status_set_error ()
 
void status_clear_warning ()
 
void status_clear_error ()
 
void status_momentary_warning (const std::string &name, uint32_t length=5000)
 
void status_momentary_error (const std::string &name, uint32_t length=5000)
 
bool has_overridden_loop () const
 
void set_component_source (const char *source)
 Set where this component was loaded from for some debug messages. More...
 
const char * get_component_source () const
 Get the integration where this component was declared as a string. More...
 
- Public Member Functions inherited from esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_2MHZ >
 SPIDevice ()=default
 
 SPIDevice (SPIComponent *parent, GPIOPin *cs)
 
void set_spi_parent (SPIComponent *parent)
 
void set_cs_pin (GPIOPin *cs)
 
void spi_setup ()
 
void enable ()
 
void disable ()
 
uint8_t read_byte ()
 
void read_array (uint8_t *data, size_t length)
 
std::array< uint8_t, N > read_array ()
 
void write_byte (uint8_t data)
 
void write_byte16 (uint16_t data)
 
void write_array16 (const uint16_t *data, size_t length)
 
void write_array (const uint8_t *data, size_t length)
 
void write_array (const std::array< uint8_t, N > &data)
 
void write_array (const std::vector< uint8_t > &data)
 
uint8_t transfer_byte (uint8_t data)
 
void transfer_array (uint8_t *data, size_t length)
 
void transfer_array (std::array< uint8_t, N > &data)
 

Data Fields

bool touched {false}
 True if the component currently detects the touch. More...
 
int16_t x {0}
 Coordinates of the touch position. More...
 
int16_t y {0}
 
int16_t x_raw {0}
 Raw sensor values of the coordinates and the pressure. More...
 
int16_t y_raw {0}
 
int16_t z_raw {0}
 

Protected Member Functions

int16_t read_adc_ (uint8_t ctrl)
 
void check_touch_ ()
 
- Protected Member Functions inherited from esphome::touchscreen::Touchscreen
void send_touch_ (TouchPoint tp)
 Call this function to send touch points to the on_touch listener and the binary_sensors. More...
 
- Protected Member Functions inherited from esphome::Component
virtual void call_loop ()
 
virtual void call_dump_config ()
 
void set_interval (const std::string &name, uint32_t interval, std::function< void()> &&f)
 Set an interval function with a unique name. More...
 
void set_interval (uint32_t interval, std::function< void()> &&f)
 
bool cancel_interval (const std::string &name)
 Cancel an interval function. More...
 
void set_retry (const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> &&f, float backoff_increase_factor=1.0f)
 Set an retry function with a unique name. More...
 
void set_retry (uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> &&f, float backoff_increase_factor=1.0f)
 
bool cancel_retry (const std::string &name)
 Cancel a retry function. More...
 
void set_timeout (const std::string &name, uint32_t timeout, std::function< void()> &&f)
 Set a timeout function with a unique name. More...
 
void set_timeout (uint32_t timeout, std::function< void()> &&f)
 
bool cancel_timeout (const std::string &name)
 Cancel a timeout function. More...
 
void defer (const std::string &name, std::function< void()> &&f)
 Defer a callback to the next loop() call. More...
 
void defer (std::function< void()> &&f)
 Defer a callback to the next loop() call. More...
 
bool cancel_defer (const std::string &name)
 Cancel a defer callback using the specified name, name must not be empty. More...
 

Static Protected Member Functions

static int16_t best_two_avg (int16_t x, int16_t y, int16_t z)
 
static int16_t normalize (int16_t val, int16_t min_val, int16_t max_val)
 

Protected Attributes

int16_t threshold_
 
int16_t x_raw_min_
 
int16_t x_raw_max_
 
int16_t y_raw_min_
 
int16_t y_raw_max_
 
bool invert_x_
 
bool invert_y_
 
bool swap_x_y_
 
uint32_t report_millis_
 
uint32_t last_pos_ms_ {0}
 
InternalGPIOPinirq_pin_ {nullptr}
 
XPT2046TouchscreenStore store_
 
- Protected Attributes inherited from esphome::touchscreen::Touchscreen
uint16_t display_width_
 
uint16_t display_height_
 
display::DisplayBufferdisplay_
 
TouchRotation rotation_
 
Trigger< TouchPointtouch_trigger_
 
std::vector< TouchListener * > touch_listeners_
 
- Protected Attributes inherited from esphome::PollingComponent
uint32_t update_interval_
 
- Protected Attributes inherited from esphome::Component
uint32_t component_state_ {0x0000}
 State of this component. More...
 
float setup_priority_override_ {NAN}
 
const char * component_source_ {nullptr}
 
- Protected Attributes inherited from esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_2MHZ >
SPIComponentparent_
 
GPIOPincs_
 

Detailed Description

Definition at line 20 of file xpt2046.h.

Member Function Documentation

◆ best_two_avg()

int16_t esphome::xpt2046::XPT2046Component::best_two_avg ( int16_t  x,
int16_t  y,
int16_t  z 
)
staticprotected

Definition at line 161 of file xpt2046.cpp.

◆ check_touch_()

void esphome::xpt2046::XPT2046Component::check_touch_ ( )
protected

Definition at line 41 of file xpt2046.cpp.

◆ dump_config()

void esphome::xpt2046::XPT2046Component::dump_config ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 140 of file xpt2046.cpp.

◆ get_report_interval()

uint32_t esphome::xpt2046::XPT2046Component::get_report_interval ( )
inline

Definition at line 37 of file xpt2046.h.

◆ get_setup_priority()

float esphome::xpt2046::XPT2046Component::get_setup_priority ( ) const
overridevirtual

Reimplemented from esphome::Component.

Definition at line 159 of file xpt2046.cpp.

◆ loop()

void esphome::xpt2046::XPT2046Component::loop ( )
overridevirtual

Detect the touch if the irq pin is specified.

If the touch is detected and the component does not already know about it the update() is called immediately. If the irq pin is not specified the loop() is a no-op.

Reimplemented from esphome::Component.

Definition at line 29 of file xpt2046.cpp.

◆ normalize()

int16_t esphome::xpt2046::XPT2046Component::normalize ( int16_t  val,
int16_t  min_val,
int16_t  max_val 
)
staticprotected

Definition at line 180 of file xpt2046.cpp.

◆ read_adc_()

int16_t esphome::xpt2046::XPT2046Component::read_adc_ ( uint8_t  ctrl)
protected

Definition at line 194 of file xpt2046.cpp.

◆ set_calibration()

void esphome::xpt2046::XPT2046Component::set_calibration ( int16_t  x_min,
int16_t  x_max,
int16_t  y_min,
int16_t  y_max 
)

Set the coordinates for the touch screen edges.

Definition at line 131 of file xpt2046.cpp.

◆ set_dimensions()

void esphome::xpt2046::XPT2046Component::set_dimensions ( int16_t  x,
int16_t  y 
)
inline

Set the logical touch screen dimensions.

Definition at line 26 of file xpt2046.h.

◆ set_irq_pin()

void esphome::xpt2046::XPT2046Component::set_irq_pin ( InternalGPIOPin pin)
inline

Set the pin used to detect the touch.

Definition at line 42 of file xpt2046.h.

◆ set_report_interval()

void esphome::xpt2046::XPT2046Component::set_report_interval ( uint32_t  interval)
inline

Set the interval to report the touch point perodically.

Definition at line 36 of file xpt2046.h.

◆ set_swap_x_y()

void esphome::xpt2046::XPT2046Component::set_swap_x_y ( bool  val)
inline

If true the x and y axes will be swapped.

Definition at line 33 of file xpt2046.h.

◆ set_threshold()

void esphome::xpt2046::XPT2046Component::set_threshold ( int16_t  threshold)
inline

Set the threshold for the touch detection.

Definition at line 40 of file xpt2046.h.

◆ setup()

void esphome::xpt2046::XPT2046Component::setup ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 14 of file xpt2046.cpp.

◆ update()

void esphome::xpt2046::XPT2046Component::update ( )
overridevirtual

Read and process the values from the hardware.

Read the raw x, y and touch pressure values from the chip, detect the touch, and if touched, transform to the user x and y coordinates. If the state has changed or if the value should be reported again due to the report interval, run the action and inform the virtual buttons.

Implements esphome::PollingComponent.

Definition at line 36 of file xpt2046.cpp.

Field Documentation

◆ invert_x_

bool esphome::xpt2046::XPT2046Component::invert_x_
protected

Definition at line 96 of file xpt2046.h.

◆ invert_y_

bool esphome::xpt2046::XPT2046Component::invert_y_
protected

Definition at line 96 of file xpt2046.h.

◆ irq_pin_

InternalGPIOPin* esphome::xpt2046::XPT2046Component::irq_pin_ {nullptr}
protected

Definition at line 102 of file xpt2046.h.

◆ last_pos_ms_

uint32_t esphome::xpt2046::XPT2046Component::last_pos_ms_ {0}
protected

Definition at line 100 of file xpt2046.h.

◆ report_millis_

uint32_t esphome::xpt2046::XPT2046Component::report_millis_
protected

Definition at line 99 of file xpt2046.h.

◆ store_

XPT2046TouchscreenStore esphome::xpt2046::XPT2046Component::store_
protected

Definition at line 103 of file xpt2046.h.

◆ swap_x_y_

bool esphome::xpt2046::XPT2046Component::swap_x_y_
protected

Definition at line 97 of file xpt2046.h.

◆ threshold_

int16_t esphome::xpt2046::XPT2046Component::threshold_
protected

Definition at line 93 of file xpt2046.h.

◆ touched

bool esphome::xpt2046::XPT2046Component::touched {false}

True if the component currently detects the touch.

Definition at line 76 of file xpt2046.h.

◆ x

int16_t esphome::xpt2046::XPT2046Component::x {0}

Coordinates of the touch position.

The values are set immediately before the on_state action with touched == true is triggered. The action with touched == false sends the coordinates of the last reported touch.

Definition at line 72 of file xpt2046.h.

◆ x_raw

int16_t esphome::xpt2046::XPT2046Component::x_raw {0}

Raw sensor values of the coordinates and the pressure.

The values are set each time the update() method is called.

Definition at line 83 of file xpt2046.h.

◆ x_raw_max_

int16_t esphome::xpt2046::XPT2046Component::x_raw_max_
protected

Definition at line 94 of file xpt2046.h.

◆ x_raw_min_

int16_t esphome::xpt2046::XPT2046Component::x_raw_min_
protected

Definition at line 94 of file xpt2046.h.

◆ y

int16_t esphome::xpt2046::XPT2046Component::y {0}

Definition at line 72 of file xpt2046.h.

◆ y_raw

int16_t esphome::xpt2046::XPT2046Component::y_raw {0}

Definition at line 83 of file xpt2046.h.

◆ y_raw_max_

int16_t esphome::xpt2046::XPT2046Component::y_raw_max_
protected

Definition at line 94 of file xpt2046.h.

◆ y_raw_min_

int16_t esphome::xpt2046::XPT2046Component::y_raw_min_
protected

Definition at line 94 of file xpt2046.h.

◆ z_raw

int16_t esphome::xpt2046::XPT2046Component::z_raw {0}

Definition at line 83 of file xpt2046.h.


The documentation for this class was generated from the following files: