ESPHome  2022.6.2
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::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...
 
void set_threshold (int16_t threshold)
 Set the threshold for the touch detection. More...
 
void set_irq_pin (GPIOPin *pin)
 Set the pin used to detect the touch. More...
 
XPT2046OnStateTriggerget_on_state_trigger () const
 Get an access to the on_state automation trigger. More...
 
void register_button (XPT2046Button *button)
 Register a virtual button to the component. 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::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 ()
 
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)
 
- 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()> &&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()> &&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_
 
int16_t x_dim_
 
int16_t y_dim_
 
bool invert_x_
 
bool invert_y_
 
bool swap_x_y_
 
uint32_t report_millis_
 
uint32_t last_pos_ms_ {0}
 
GPIOPinirq_pin_ {nullptr}
 
bool last_irq_ {true}
 
XPT2046OnStateTriggeron_state_trigger_ {new XPT2046OnStateTrigger()}
 
std::vector< XPT2046Button * > buttons_ {}
 
- 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 34 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 153 of file xpt2046.cpp.

◆ dump_config()

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

Reimplemented from esphome::Component.

Definition at line 132 of file xpt2046.cpp.

◆ get_on_state_trigger()

XPT2046OnStateTrigger* esphome::xpt2046::XPT2046Component::get_on_state_trigger ( ) const
inline

Get an access to the on_state automation trigger.

Definition at line 55 of file xpt2046.h.

◆ get_setup_priority()

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

Reimplemented from esphome::Component.

Definition at line 151 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 23 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 172 of file xpt2046.cpp.

◆ read_adc_()

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

Definition at line 186 of file xpt2046.cpp.

◆ register_button()

void esphome::xpt2046::XPT2046Component::register_button ( XPT2046Button button)
inline

Register a virtual button to the component.

Definition at line 57 of file xpt2046.h.

◆ 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 123 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 39 of file xpt2046.h.

◆ set_irq_pin()

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

Set the pin used to detect the touch.

Definition at line 53 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 49 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 46 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 51 of file xpt2046.h.

◆ setup()

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

Reimplemented from esphome::Component.

Definition at line 12 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

◆ buttons_

std::vector<XPT2046Button *> esphome::xpt2046::XPT2046Component::buttons_ {}
protected

Definition at line 120 of file xpt2046.h.

◆ invert_x_

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

Definition at line 110 of file xpt2046.h.

◆ invert_y_

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

Definition at line 110 of file xpt2046.h.

◆ irq_pin_

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

Definition at line 116 of file xpt2046.h.

◆ last_irq_

bool esphome::xpt2046::XPT2046Component::last_irq_ {true}
protected

Definition at line 117 of file xpt2046.h.

◆ last_pos_ms_

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

Definition at line 114 of file xpt2046.h.

◆ on_state_trigger_

XPT2046OnStateTrigger* esphome::xpt2046::XPT2046Component::on_state_trigger_ {new XPT2046OnStateTrigger()}
protected

Definition at line 119 of file xpt2046.h.

◆ report_millis_

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

Definition at line 113 of file xpt2046.h.

◆ swap_x_y_

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

Definition at line 111 of file xpt2046.h.

◆ threshold_

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

Definition at line 107 of file xpt2046.h.

◆ touched

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

True if the component currently detects the touch.

Definition at line 91 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 87 of file xpt2046.h.

◆ x_dim_

int16_t esphome::xpt2046::XPT2046Component::x_dim_
protected

Definition at line 109 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 98 of file xpt2046.h.

◆ x_raw_max_

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

Definition at line 108 of file xpt2046.h.

◆ x_raw_min_

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

Definition at line 108 of file xpt2046.h.

◆ y

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

Definition at line 87 of file xpt2046.h.

◆ y_dim_

int16_t esphome::xpt2046::XPT2046Component::y_dim_
protected

Definition at line 109 of file xpt2046.h.

◆ y_raw

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

Definition at line 98 of file xpt2046.h.

◆ y_raw_max_

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

Definition at line 108 of file xpt2046.h.

◆ y_raw_min_

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

Definition at line 108 of file xpt2046.h.

◆ z_raw

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

Definition at line 98 of file xpt2046.h.


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