Merge branch 'current' into next
This commit is contained in:
commit
cc2f6abe0c
|
@ -80,6 +80,11 @@ Release 2023.12.4 - December 25
|
|||
- dashboard: Fix file writes on Windows :esphomepr:`6013` by :ghuser:`bdraco`
|
||||
- Display: fix class inherence in Python script :esphomepr:`6009` by :ghuser:`nielsnl68`
|
||||
|
||||
Release 2023.12.5 - December 25
|
||||
-------------------------------
|
||||
|
||||
- Fix docker builds :esphomepr:`6012` by :ghuser:`bdraco`
|
||||
|
||||
Full list of changes
|
||||
--------------------
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ Configuration variables:
|
|||
|
||||
- **model** (**Required**): The model of the display. Options are:
|
||||
|
||||
- ``M5STACK``, ``TFT 2.4``, ``TFT 2.4R``, ``S3BOX``, ``S3BOX_LITE``, ``ST7789V``
|
||||
- ``M5STACK``, ``TFT 2.4``, ``TFT 2.4R``, ``S3BOX``, ``S3BOX_LITE``
|
||||
- ``ILI9341``, ``ILI9342``, ``ILI9486``, ``ILI9488``, ``ILI9488_A`` (alternative gamma configuration for ILI9488)
|
||||
- ``ILI9481``, ``ILI9481-18`` (18 bit mode)
|
||||
- ``ST7789V``, ``ST7796``
|
||||
|
@ -202,10 +202,11 @@ This config rotates the display into landscape mode using the driver chip.
|
|||
display:
|
||||
- platform: ili9xxx
|
||||
model: st7789v
|
||||
height: 170
|
||||
width: 320
|
||||
offset_height: 35
|
||||
offset_width: 0
|
||||
dimensions:
|
||||
height: 170
|
||||
width: 320
|
||||
offset_height: 35
|
||||
offset_width: 0
|
||||
transform:
|
||||
swap_xy: true
|
||||
mirror_x: false
|
||||
|
@ -216,6 +217,22 @@ This config rotates the display into landscape mode using the driver chip.
|
|||
dc_pin: GPIO13
|
||||
reset_pin: GPIO9
|
||||
|
||||
For Lilygo TTGO Boards if you move from the st7789v to this you need the following settings to make it work.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
display:
|
||||
- platform: ili9xxx
|
||||
model: st7789v
|
||||
#TTGO TDisplay 135x240
|
||||
dimensions:
|
||||
height: 240
|
||||
width: 135
|
||||
offset_height: 40
|
||||
offset_width: 52
|
||||
# Required or the colors are all inverted, and Black screen is White
|
||||
invert_colors: true
|
||||
|
||||
See Also
|
||||
--------
|
||||
|
||||
|
|
|
@ -25,6 +25,12 @@ The TTGO T-Display module shown has the display attached to the module's board a
|
|||
cannot be changed. Other display modules have pin headers or other connectors which must be connected appropriately
|
||||
to an ESP module.
|
||||
|
||||
.. warning::
|
||||
|
||||
This component has been made redundant since the ST7789V is now supported by the :ref:`ILI9XXX component <ili9xxx>`. It is recommended
|
||||
that you use the ``ili9xxx`` component as it will be maintained, whereas this component may not be, or may be removed completely
|
||||
in the future.
|
||||
|
||||
.. note::
|
||||
|
||||
Displays larger than the 135x240 pixel display on the TTGO T-Display shown require a significant amount of RAM
|
||||
|
|
|
@ -71,6 +71,11 @@ When a **display** is specified the menu will create a :ref:`page <display-pages
|
|||
of the display when invoked. This is useful when you may want to use the display for other purposes but show a menu in response to user
|
||||
interaction.
|
||||
|
||||
.. note::
|
||||
|
||||
Pop Up Mode requires that your display makes use of :ref:`pages <display-pages>`. If you are using a drawing lambda, without pages, it will not
|
||||
behave as expected. Instead you will have to use Advanced Mode
|
||||
|
||||
Advanced Drawing Mode
|
||||
*********************
|
||||
|
||||
|
@ -100,7 +105,37 @@ larger user interface (for example rendering a sensor graph and a control menu n
|
|||
// Arguments: it.menu(x, y, menu, width, height);
|
||||
it.menu(half_display_width, 0, id(my_menu), half_display_width, display_height);
|
||||
|
||||
Emulating Pop Up Mode
|
||||
*********************
|
||||
|
||||
If you wish to emulate Pop Up Mode the following sample will emulate the same behaviour. This can
|
||||
be useful if you're using a display without :ref:`pages <display-pages>` or if you have other
|
||||
requirements that requires control over how and where the menu is rendered.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
graphical_display_menu:
|
||||
id: my_menu
|
||||
items:
|
||||
# ... other items here ...
|
||||
|
||||
# An exit menu item (or some other mechanism) that calls display_menu.hide
|
||||
- type: command
|
||||
on_value:
|
||||
then:
|
||||
- display_menu.hide: my_menu
|
||||
|
||||
display:
|
||||
- platform: ..
|
||||
lambda: |-
|
||||
const auto width = it.get_width();
|
||||
const auto height = it.get_height();
|
||||
|
||||
if (id(my_menu).is_active()) {
|
||||
it.menu(0, 0, id(my_menu), width, height);
|
||||
} else {
|
||||
it.print(0, 0, id(font), "Menu is hidden, other drawing would go here here");
|
||||
}
|
||||
|
||||
Controlling Menu Item Rendering
|
||||
-------------------------------
|
||||
|
|
|
@ -13,7 +13,7 @@ NeoPixelBus Light
|
|||
|
||||
|
||||
The ``neopixelbus`` light platform allows you to create RGB lights
|
||||
in ESPHome for an individually addressable lights like NeoPixel or WS2812.
|
||||
in ESPHome for individually addressable lights like NeoPixel or WS2812.
|
||||
|
||||
It is very similar to the :doc:`fastled` platform.
|
||||
In fact, most addressable lights are supported through both light platforms. The
|
||||
|
|
|
@ -174,7 +174,7 @@ enum. These values are:
|
|||
then:
|
||||
- if:
|
||||
condition:
|
||||
lambda: return state == ota::OTA_STARTED
|
||||
lambda: return state == ota::OTA_STARTED;
|
||||
then:
|
||||
- logger.log: "OTA start"
|
||||
|
||||
|
|
|
@ -11,9 +11,6 @@ The MCP4728 output component allows to use `12bit external quad DAC
|
|||
<https://www.adafruit.com/product/4470>`__
|
||||
in order to have analog outputs on any board by using :ref:`I²C <i2c>`. Devices default address is ``0x60``.
|
||||
|
||||
If you only have one, it is not necessary to explicitly specify the ``mcp4728:`` component in the config unless you need to change the parameters.
|
||||
It will be automatically created with the default settings if you use it.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
# Example configuration entry
|
||||
|
|
|
@ -112,8 +112,8 @@ Configuration variables:
|
|||
- **temperature** (*Optional*): Temperature. All options from :ref:`Sensor <config-sensor>`.
|
||||
- **temperature_low** (*Optional*): Historic minimum temperature. All options from :ref:`Sensor <config-sensor>`.
|
||||
- **temperature_high** (*Optional*): Historic maximum temperature. All options from :ref:`Sensor <config-sensor>`.
|
||||
- **voltage_low** (*Optional*): Historic minimum voltage. All options from :ref:`Sensor <config-sensor>`.
|
||||
- **voltage_high** (*Optional*): Historic maximum voltage. All options from :ref:`Sensor <config-sensor>`.
|
||||
- **voltage_low** (*Optional*): Voltage of the lowest cell. All options from :ref:`Sensor <config-sensor>`.
|
||||
- **voltage_high** (*Optional*): Voltage of the highest cell. All options from :ref:`Sensor <config-sensor>`.
|
||||
- **mos_temperature** (*Optional*): Temperature of the mosfets. All options from :ref:`Sensor <config-sensor>`.
|
||||
|
||||
Text Sensor
|
||||
|
|
|
@ -963,6 +963,7 @@ earlier, create a new template switch that sends the RF code when triggered:
|
|||
switch:
|
||||
- platform: template
|
||||
name: RF Power Button
|
||||
optimistic: true
|
||||
turn_on_action:
|
||||
- remote_transmitter.transmit_rc_switch_raw:
|
||||
code: '100010000000000010111110'
|
||||
|
|
|
@ -4,10 +4,10 @@ AHT10 Temperature+Humidity Sensor
|
|||
.. seo::
|
||||
:description: Instructions for setting up AHT10 temperature and humidity sensors
|
||||
:image: aht10.jpg
|
||||
:keywords: aht10 aht20 dht20
|
||||
:keywords: aht10 aht20 dht20 aht30
|
||||
|
||||
The ``aht10`` Temperature+Humidity sensor allows you to use your AHT10
|
||||
(`datasheet <http://www.aosong.com/userfiles/files/media/aht10%E8%A7%84%E6%A0%BC%E4%B9%A6v1_1%EF%BC%8820191015%EF%BC%89.pdf>`__) or AHT20 (`datasheet <https://cdn-learn.adafruit.com/assets/assets/000/091/676/original/AHT20-datasheet-2020-4-16.pdf?1591047915>`__) :ref:`I²C <i2c>`-based sensor with ESPHome.
|
||||
(`datasheet <http://www.aosong.com/userfiles/files/media/aht10%E8%A7%84%E6%A0%BC%E4%B9%A6v1_1%EF%BC%8820191015%EF%BC%89.pdf>`__), AHT20 (`datasheet <https://cdn-learn.adafruit.com/assets/assets/000/091/676/original/AHT20-datasheet-2020-4-16.pdf?1591047915>`__) or AHT30 (`datasheet <https://eleparts.co.kr/data/goods_attach/202306/good-pdf-12751003-1.pdf>`__) :ref:`I²C <i2c>`-based sensor with ESPHome.
|
||||
|
||||
The DHT20 (`datasheet <https://cdn.sparkfun.com/assets/8/a/1/5/0/DHT20.pdf>`__) sensor has the packaging of the :doc:`dht` series, but has the AHT20 inside and is speaking :ref:`I²C <i2c>` as well.
|
||||
|
||||
|
@ -43,7 +43,7 @@ Configuration variables:
|
|||
- **variant** (*Optional*, enum): Set the variant of the device in use. Defaults to ``AHT10``.
|
||||
|
||||
- ``AHT10`` - For AHT10 devices.
|
||||
- ``AHT20`` - For AHT20 devices.
|
||||
- ``AHT20`` - For AHT20 and AHT30 devices.
|
||||
|
||||
- **temperature** (**Required**): The information for the temperature sensor.
|
||||
|
||||
|
|
|
@ -326,7 +326,7 @@ Configuration variables:
|
|||
Button
|
||||
------
|
||||
|
||||
The ``ld2410`` button allows you to perfrom actions on your :doc:`ld2410`.
|
||||
The ``ld2410`` button allows you to perform actions on your :doc:`ld2410`.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ trying to match.
|
|||
variables:
|
||||
new_total: int
|
||||
then:
|
||||
- pulse_counter.set_total_pulses:
|
||||
- pulse_meter.set_total_pulses:
|
||||
id: sensor_pulse_meter
|
||||
value: !lambda 'return new_total;'
|
||||
|
||||
|
|
|
@ -9,6 +9,15 @@ The ``touchscreen`` component contains the base code for most touchscreen driver
|
|||
available in ESPHome and is responsible for passing the touch events to
|
||||
``binary_sensors`` with the ``touchscreen`` platform.
|
||||
|
||||
.. warning::
|
||||
|
||||
As of version **2023.12** the way how the touchscreen component has changed a bit.
|
||||
The following variables are now obsolite:
|
||||
* **rotation** is (temporary) removed in favor the *new* **transform:**
|
||||
* **size_x_y** is moved inside the **transform:** and renamed to **size_xy**
|
||||
* **report_interval** is removed in favor of using the **update_interval**
|
||||
The display id is only just to calculate the touch position reletive to the displays *height* and *width*
|
||||
|
||||
.. _config-touchscreen:
|
||||
|
||||
Base Touchscreen Configuration
|
||||
|
@ -20,6 +29,14 @@ Base Touchscreen Configuration
|
|||
touchscreen:
|
||||
- platform: ...
|
||||
display: display1
|
||||
transform:
|
||||
mirror_x: false
|
||||
mirror_y: false
|
||||
swap_xy: false
|
||||
calibration:
|
||||
x_max: 240
|
||||
y_max: 320
|
||||
|
||||
on_touch:
|
||||
then:
|
||||
...
|
||||
|
@ -32,7 +49,26 @@ Base Touchscreen Configuration
|
|||
|
||||
Configuration variables:
|
||||
************************
|
||||
- **display** (*Required*, :ref:`config-id`): The display to use this touchscreen with. This will be provided automatically if only one display is configured on the device.
|
||||
- **display** (*Required*, :ref:`config-id`): The display to use this touchscreen with.
|
||||
- **transform** (*Optional*): Transform the touchscreen presentation using hardware. All defaults are ``false``.
|
||||
|
||||
- **swap_xy** (*Optional*, boolean): If true, exchange the x and y axes.
|
||||
- **mirror_x** (*Optional*, boolean): If true, mirror the x axis.
|
||||
- **mirror_y** (*Optional*, boolean): If true, mirror the y axis.
|
||||
|
||||
- **update_interval** (*Optional*, :ref:`config-time`): The interval to check the touchscreen. Defaults to ``never``.
|
||||
- **calibration** (*Optional*): When the touchscreen is not given the right configuration settings. You can set them here.
|
||||
|
||||
- **x_min** (*Optional*, int): The raw value corresponding to the left
|
||||
(or top if ``swap_xy`` is specified) edge of the touchscreen. See :ref:`touchscreen-calibration`
|
||||
for the process to calibrate the touchscreen. Defaults to ``0``.
|
||||
- **x_max** (*Optional*, int): The raw value corresponding to the right
|
||||
(or bottom if ``swap_xy`` is specified) edge of the touchscreen. Defaults to ``0``.
|
||||
- **y_min** (*Optional*, int): The raw value corresponding to the top
|
||||
(or left if ``swap_xy`` is specified) edge of the touchscreen. Defaults to ``0``.
|
||||
- **y_max** (*Optional*, int): The raw value corresponding to the bottom
|
||||
(or right if ``swap_xy`` is specified) edge of the touchscreen. Defaults to ``0``.
|
||||
|
||||
|
||||
- **on_touch** (*Optional*, :ref:`Automation <automation>`): An automation to perform
|
||||
when the touchscreen is touched. See :ref:`touchscreen-on_touch`.
|
||||
|
@ -52,13 +88,132 @@ list (``on_update``) or as an ``optional`` (``on_touch``).
|
|||
|
||||
The integer members for the touch positions below are in relation to the display width and height:
|
||||
|
||||
- ``id`` is a number provided by the touchscreen to uniquely identify the touch on a multi-touch screen.
|
||||
- ``state`` indicates the state of the touch. This can be **1**, indicating it is an initial touch, or **2** indicating the touch position has changed/moved.
|
||||
|
||||
- ``x`` and ``y`` are the current position.
|
||||
- ``x_last`` and ``y_last`` are the previous position.
|
||||
- ``x_first`` and ``y_first`` are the position of the touch when it was first detected.
|
||||
- ``x_raw`` and ``y_raw`` are for calibrating the touchscreen in relation of the display. This replaces the properties with the same name in the touchscreen classes.
|
||||
|
||||
- ``id`` is a number provided by the touchscreen to uniquely identify the touch on a multi-touch screen.
|
||||
- ``state`` indicates the state of the touch. This can be **1**, indicating it is an initial touch, or **2** indicating the touch position has changed/moved.
|
||||
.. _touchscreen-calibration:
|
||||
|
||||
Calibration
|
||||
-----------
|
||||
|
||||
For most of the touchscreen drivers the dimensions of the touchscreen are automatically set when the driver is setup.
|
||||
In some cases like for the **XPT2046** this can be different per used display panel.
|
||||
Then you can set the values using the **calibrate** values.
|
||||
|
||||
To match the point of the touch to the display coordinates the touch screen has to be calibrated.
|
||||
The touchscreen component returns raw values in the 0 to 4095 range. Those raw values are available
|
||||
as the ``x_raw`` and ``y_raw`` member variables and for example write them out as in the example
|
||||
:ref:`touchscreen-on_touch`. The goal of the calibration is to identify the raw values corresponding
|
||||
to the edges of the screen.
|
||||
|
||||
The calibration assumes a display oriented in a way that you will be using it, i.e. your
|
||||
:ref:`display-engine` component has to have the [0,0] logical coordinate at the top left.
|
||||
|
||||
.. note::
|
||||
|
||||
Do not set any calibration values nor ``transform`` settings.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
# Touchscreen
|
||||
touchscreen:
|
||||
platform: xpt2046
|
||||
id: my_touchscreen
|
||||
cs_pin: 17
|
||||
on_touch:
|
||||
- lambda: |-
|
||||
ESP_LOGI("cal", "x=%d, y=%d, x_raw=%d, y_raw=%0d",
|
||||
touch.x,
|
||||
touch.y,
|
||||
touch.x_raw,
|
||||
touch.y_raw
|
||||
);
|
||||
|
||||
Get a stylus or a similar object, run the project and touch the corners of the screen at
|
||||
the edge pixels. Repeat several times and note minimum and maximum x and y raw values.
|
||||
|
||||
.. warning::
|
||||
|
||||
As long the calibrate settings are not correctly set, the ``x`` and ``y`` coordinates are not calculated.
|
||||
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
... top left ...
|
||||
[21:07:48][I][cal:071]: x=217, y=34, x_raw=3718, y_raw=445
|
||||
[21:07:49][I][cal:071]: x=222, y=32, x_raw=3804, y_raw=419
|
||||
... top right ...
|
||||
[21:07:52][I][cal:071]: x=19, y=36, x_raw=334, y_raw=370
|
||||
[21:07:52][I][cal:071]: x=22, y=35, x_raw=386, y_raw=347
|
||||
... bottom left ...
|
||||
[21:08:00][I][cal:071]: x=224, y=299, x_raw=3836, y_raw=3835
|
||||
[21:08:00][I][cal:071]: x=225, y=303, x_raw=3848, y_raw=3878
|
||||
[21:08:01][I][cal:071]: x=223, y=299, x_raw=3807, y_raw=3829
|
||||
... bottom right ...
|
||||
[21:08:11][I][cal:071]: x=16, y=299, x_raw=281, y_raw=3839
|
||||
[21:08:12][I][cal:071]: x=19, y=302, x_raw=328, y_raw=3866
|
||||
[21:08:13][I][cal:071]: x=20, y=296, x_raw=358, y_raw=3799
|
||||
|
||||
That means that the minimum raw x is 281, maximum 3848, minimum y 347 and maximum 3878.
|
||||
|
||||
Identify which raw value is the display's x direction and what the y one. In our case
|
||||
moving right decreases the x raw value and going down increases the y one so the axes
|
||||
match and we *don't* need to use ``swap_xy``. If the raw x is the display's y,
|
||||
use ``swap_xy = true``.
|
||||
|
||||
If one of the coordinates goes in the "wrong" direction it needs to be inverted.
|
||||
The inversion is performed by setting the ``mirror_x`` and/or ``mirror_y`` to true.
|
||||
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
touchscreen:
|
||||
platform: xpt2046
|
||||
calibration:
|
||||
x_min: 281
|
||||
x_max: 3848
|
||||
y_min: 347
|
||||
y_max: 3878
|
||||
transform:
|
||||
mirror_x: false
|
||||
mirror_y: false
|
||||
swap_xy: false
|
||||
|
||||
Compile, run and click on the edges again. The x and y should now match the coordinates
|
||||
of the display.
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
[21:32:34][I][cal:071]: x=7, y=6, x_raw=3755, y_raw=407
|
||||
[21:32:37][I][cal:071]: x=237, y=4, x_raw=313, y_raw=385
|
||||
[21:32:43][I][cal:071]: x=239, y=318, x_raw=284, y_raw=3845
|
||||
[21:33:05][I][cal:071]: x=2, y=313, x_raw=3821, y_raw=3793
|
||||
|
||||
Note that the touch screen is not extremely precise and there might be nonlinearities
|
||||
or similar errors so don't expect a pixel-perfect precision. You can verify the touchpoint
|
||||
using a display lambda similar to the following.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
display:
|
||||
- platform: ili9341
|
||||
lambda: |-
|
||||
auto touch = id(my_touchscreen)->get_touch();
|
||||
if (touch) // or touch.has_value()
|
||||
it.filled_circle(touch.value().x, touch.value().y, 10, RED);
|
||||
|
||||
To be exact, the component does the following
|
||||
|
||||
- reads the raw x and y and normalizes it using (non-inverted) min and max values
|
||||
- swaps x and y if needed
|
||||
- inverts if needed
|
||||
- scales to the display dimensions
|
||||
|
||||
|
||||
.. _touchscreen-on_touch:
|
||||
|
||||
|
@ -85,6 +240,25 @@ This trigger provides one argument named ``touches`` of type :apiref:`touchscree
|
|||
|
||||
This trigger may be useful to detect gestures such as swiping across the display.
|
||||
|
||||
For example you could do:
|
||||
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
on_update:
|
||||
- lambda: |-
|
||||
for (auto touch: touches) {
|
||||
if (touch.state <= 2) {
|
||||
ESP_LOGI("Touch points:", "id=%d x=%d, y=%d", touch.id, touch.x, touch.y);
|
||||
}
|
||||
}
|
||||
|
||||
Be aware that you need to check the state flag every time to see if the touch is still valid.
|
||||
|
||||
- state value 0. means the touch is invalid as the touch is no longer detected.
|
||||
- state value 1 means is being the first time detected.
|
||||
- state value 2 means the touch is still being detected but is moved on the screen.
|
||||
- state value 4 and higher means a touch release is detected.
|
||||
|
||||
.. _touchscreen-on_release:
|
||||
|
||||
|
|
|
@ -31,14 +31,12 @@ The :ref:`SPI <spi>` is required to be set up in your configuration for this sen
|
|||
cs_pin: 17
|
||||
interrupt_pin: 16
|
||||
update_interval: 50ms
|
||||
report_interval: 1s
|
||||
threshold: 400
|
||||
calibration_x_min: 3860
|
||||
calibration_x_max: 280
|
||||
calibration_y_min: 340
|
||||
calibration_y_max: 3860
|
||||
swap_x_y: false
|
||||
|
||||
calibration:
|
||||
x_min: 3860
|
||||
x_max: 280
|
||||
y_min: 340
|
||||
y_max: 3860
|
||||
|
||||
Configuration variables:
|
||||
------------------------
|
||||
|
@ -59,134 +57,24 @@ Base Configuration:
|
|||
sensor. If ``interrupt_pin`` is specified the touch will be detected nearly instantaneously and this setting
|
||||
will be used only for the release detection. Defaults to ``50ms``.
|
||||
|
||||
- **report_interval** (*Optional*, :ref:`config-time`): The interval to periodically
|
||||
report the coordinates while the touch screen is touched. Defaults to ``never``.
|
||||
|
||||
- **threshold** (*Optional*, int): The value to detect the touch or release. Defaults to ``400``.
|
||||
|
||||
- **calibration_x_min** (*Optional*, int): The raw value corresponding to the left
|
||||
(or top if ``swap_x_y`` is specified) edge of the display. See :ref:`xpt2046-calibration`
|
||||
for the process to calibrate the touch screen. Defaults to ``0``.
|
||||
|
||||
- **calibration_x_max** (*Optional*, int): The raw value corresponding to the right
|
||||
(or bottom if ``swap_x_y`` is specified) edge of the display. Defaults to ``4095``.
|
||||
- **calibration_x_min** (*Depricated*): This value is moved to the ``calibration`` values
|
||||
|
||||
- **calibration_y_min** (*Optional*, int): The raw value corresponding to the top
|
||||
(or left if ``swap_x_y`` is specified) edge of the display. Defaults to ``0``.
|
||||
- **calibration_x_max** (*Depricated*): This value is moved to the ``calibration`` values.
|
||||
|
||||
- **calibration_y_max** (*Optional*, int): The raw value corresponding to the bottom
|
||||
(or right if ``swap_x_y`` is specified) edge of the display. Defaults to ``4095``.
|
||||
- **calibration_y_min** (*Depricated*): This value is moved to the ``calibration`` values.
|
||||
|
||||
- **swap_x_y** (*Optional*, boolean): If true the x and y axes are swapped. Defaults to ``false``.
|
||||
- **calibration_y_max** (*Depricated*): This value is moved to the ``calibration`` values.
|
||||
|
||||
- **swap_x_y** (*Depricated*): This value is moved to the ``transform`` values as ``swap_xy`` see :ref:`config-touchscreen`.
|
||||
|
||||
- **report_interval** (*Depricated*): This interval is removed in favor of the ``update_interval``.
|
||||
|
||||
- All other options from :ref:`config-touchscreen`.
|
||||
|
||||
|
||||
.. _xpt2046-calibration:
|
||||
|
||||
Calibration
|
||||
-----------
|
||||
|
||||
To match the point of the touch to the display coordinates the touch screen has to be calibrated.
|
||||
The XPT2046 component returns raw values in the 0 to 4095 range. Those raw values are available
|
||||
as the ``x_raw`` and ``y_raw`` member variables and for example write them out as in the example
|
||||
:ref:`touchscreen-on_touch`. The goal of the calibration is to identify the raw values corresponding
|
||||
to the edges of the screen.
|
||||
|
||||
The calibration assumes a display oriented in a way that you will be using it, i.e. your
|
||||
:ref:`display-engine` component has to have the [0,0] logical coordinate at the top left.
|
||||
Set the dimensions as ``dimension_x`` and ``dimension_y`` and do not set any calibration
|
||||
values nor ``swap_x_y``.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
# Touchscreen
|
||||
touchscreen:
|
||||
platform: xpt2046
|
||||
id: my_touchscreen
|
||||
cs_pin: 17
|
||||
on_touch:
|
||||
- lambda: |-
|
||||
ESP_LOGI("cal", "x=%d, y=%d, x_raw=%d, y_raw=%0d",
|
||||
touch.x,
|
||||
touch.y,
|
||||
touch.x_raw,
|
||||
touch.y_raw
|
||||
);
|
||||
|
||||
Get a stylus or a similar object, run the project and touch the corners of the screen at
|
||||
the edge pixels. Repeat several times and note minimum and maximum x and y raw values.
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
... top left ...
|
||||
[21:07:48][I][cal:071]: x=217, y=34, x_raw=3718, y_raw=445
|
||||
[21:07:49][I][cal:071]: x=222, y=32, x_raw=3804, y_raw=419
|
||||
... top right ...
|
||||
[21:07:52][I][cal:071]: x=19, y=36, x_raw=334, y_raw=370
|
||||
[21:07:52][I][cal:071]: x=22, y=35, x_raw=386, y_raw=347
|
||||
... bottom left ...
|
||||
[21:08:00][I][cal:071]: x=224, y=299, x_raw=3836, y_raw=3835
|
||||
[21:08:00][I][cal:071]: x=225, y=303, x_raw=3848, y_raw=3878
|
||||
[21:08:01][I][cal:071]: x=223, y=299, x_raw=3807, y_raw=3829
|
||||
... bottom right ...
|
||||
[21:08:11][I][cal:071]: x=16, y=299, x_raw=281, y_raw=3839
|
||||
[21:08:12][I][cal:071]: x=19, y=302, x_raw=328, y_raw=3866
|
||||
[21:08:13][I][cal:071]: x=20, y=296, x_raw=358, y_raw=3799
|
||||
|
||||
That means that the minimum raw x is 281, maximum 3848, minimum y 347 and maximum 3878.
|
||||
|
||||
Identify which raw value is the display's x direction and what the y one. In our case
|
||||
moving right decreases the x raw value and going down increases the y one so the axes
|
||||
match and we *don't* need to use ``swap_x_y``. If the raw x is the display's y,
|
||||
use ``swap_x_y = true``.
|
||||
|
||||
If one of the coordinates goes in the "wrong" direction it needs to be inverted.
|
||||
The inversion is performed by swapping the minimum and maximum values. In our
|
||||
case the horizontal direction represented by the raw x (no swap) is inverted
|
||||
so the ``calibration_x_min`` needs to be larger than ``calibration_x_max``.
|
||||
The vertical direction is fine. The configuration would thus be
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
touchscreen:
|
||||
platform: xpt2046
|
||||
calibration_x_min: 3848
|
||||
calibration_x_max: 281
|
||||
calibration_y_min: 347
|
||||
calibration_y_max: 3878
|
||||
|
||||
Compile, run and click on the edges again. The x and y should now match the coordinates
|
||||
of the display.
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
[21:32:34][I][cal:071]: x=7, y=6, x_raw=3755, y_raw=407
|
||||
[21:32:37][I][cal:071]: x=237, y=4, x_raw=313, y_raw=385
|
||||
[21:32:43][I][cal:071]: x=239, y=318, x_raw=284, y_raw=3845
|
||||
[21:33:05][I][cal:071]: x=2, y=313, x_raw=3821, y_raw=3793
|
||||
|
||||
Note that the touch screen is not extremely precise and there might be nonlinearities
|
||||
or similar errors so don't expect a pixel-perfect precision. You can verify the touchpoint
|
||||
using a display lambda similar to the following.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
display:
|
||||
- platform: ili9341
|
||||
lambda: |-
|
||||
auto touch = id(my_touchscreen)->get_touch();
|
||||
if (touch) // or touch.has_value()
|
||||
it.filled_circle(touch.value().x, touch.value().y, 10, RED);
|
||||
|
||||
To be exact, the component does the following
|
||||
|
||||
- reads the raw x and y and normalizes it using (non-inverted) min and max values
|
||||
- swaps x and y if needed
|
||||
- inverts if needed
|
||||
- scales to the display dimensions
|
||||
|
||||
|
||||
See Also
|
||||
--------
|
||||
|
||||
|
|
|
@ -92,6 +92,7 @@ Custom Components & Code
|
|||
- `Custom esp32 media player and notifier <https://www.printables.com/model/327708-esphome-nodemcu-esp32-media-player>`__ by :ghuser:`rananna`
|
||||
- `Blauberg recuperator S22 controller replacement <https://github.com/Benas09/Blauberg_S22>`__ by :ghuser:`Benas09`
|
||||
- `Rheem Econet Water Heater and Furnace Controller <https://github.com/esphome-econet/esphome-econet>`__ by `ESPHome-econet <https://github.com/esphome-econet>`__
|
||||
- `Medisana BS440 (and propably more scales) <https://github.com/bwynants/weegschaal>`__ by `bwynants <https://github.com/bwynants>`__
|
||||
|
||||
Sample Configurations
|
||||
---------------------
|
||||
|
|
Loading…
Reference in New Issue