1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-28 05:33:53 +00:00

Touchscreen component and driver fixes (#5997)

* Introduce calibration settings for all touchscreen drivers.
this will override the common values.
The x,y coordinates only calculated when the right calibrations are set.

* resolve issues reported by CI

* remove unneeded spaces and newlines

* Forgot to remove some obsolete code

* remove get_setup_priority from xpt2046

* remove media_player changes.

* media_player: removed to much,

* Update suggestions

* referd back the `get_setup_priority` removal so it can be moved into a othe PR.

* tt21100: restore init read

* fix spacing

* load native display dimensions instead of using internal dimensons.
and load it only onse on setup

* moved `update_touches()` to protexted section

* adding Clydes PR#6049

* add multitouch test script

* Update all Touchscreen replacing `get_*_internal` to `get_native_*`

* fixed some CI recomendations

* couple of fixes

* make sure the display is running before  touchscreen is setup

* fix clang

* revert back last changes

* xpt2046: change log level for testing

* logging information

* add test file

* fix polling issue with the for example the xpt2046

* fixed some CI issues

* fixed some CI issues

* restore mirror parameter discriptions

* same for the swap_xy

* same for the transform

* remove the above const from const.py

* and put  the above const bacl const.py

* Merge branch 'nvds-touchscreen-fix1' of https://github.com/nielsnl68/esphome into nvds-touchscreen-fix1

* and put  the above const bacl const.py

* [tt21100] making interupt pin optional

* [tt21100] making interupt pin optional (now complete)

* update the display part based on @clyde'
s changes.

* fix issue with ft6x36 touvhscreen

* reverd back touch check. add comment

* add some extra checks to the ft6x36

* add an other log and a typo fixed

* okay an other fix.

* add an extra check like others do
and fix data type

* [ft6336] fix update race when ts is touched.

* [touchscreen] update some log's with a verbose level.

* fix clang issues

* fix the clang issues

* fix the clang issues

* fix virtual issue.

* fix the clang issues

* an other clang issues

* remove anti-aliased fonts support. It does not belong here.

* remove anti-aliased fonts support. It does not belong here.

* rename test script

* Moving the test files to there right location.

* rename the test files

* clean up the code

* add a new line

* clang fixings

* clang fixings

* remove comment

* remove comment

* Update esphome/components/touchscreen/__init__.py

Co-authored-by: guillempages <guillempages@users.noreply.github.com>

* Update esphome/components/touchscreen/__init__.py

Co-authored-by: guillempages <guillempages@users.noreply.github.com>

* Update esphome/components/touchscreen/__init__.py

Co-authored-by: guillempages <guillempages@users.noreply.github.com>

* Update esphome/components/touchscreen/touchscreen.cpp

* Update esphome/components/touchscreen/touchscreen.cpp

* [ft63x6] add threshold

---------

Co-authored-by: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com>
Co-authored-by: guillempages <guillempages@users.noreply.github.com>
This commit is contained in:
NP v/d Spek
2024-02-28 03:42:11 +01:00
committed by GitHub
parent c43c9ad1c5
commit 5393a09872
21 changed files with 422 additions and 157 deletions

View File

@@ -3,14 +3,17 @@ import esphome.codegen as cg
from esphome.components import display
from esphome import automation
from esphome.const import (
CONF_ON_TOUCH,
CONF_ON_RELEASE,
CONF_SWAP_XY,
CONF_MIRROR_X,
CONF_MIRROR_Y,
CONF_SWAP_XY,
CONF_TRANSFORM,
CONF_CALIBRATION,
)
from esphome.core import coroutine_with_priority
CODEOWNERS = ["@jesserockz", "@nielsnl68"]
@@ -34,6 +37,56 @@ CONF_ON_UPDATE = "on_update"
CONF_TOUCH_TIMEOUT = "touch_timeout"
CONF_X_MIN = "x_min"
CONF_X_MAX = "x_max"
CONF_Y_MIN = "y_min"
CONF_Y_MAX = "y_max"
def validate_calibration(config):
if CONF_CALIBRATION in config:
calibration_config = config[CONF_CALIBRATION]
if (
cv.int_([CONF_X_MIN]) != 0
and cv.int_(calibration_config[CONF_X_MAX]) != 0
and abs(
cv.int_(calibration_config[CONF_X_MIN])
- cv.int_(calibration_config[CONF_X_MAX])
)
< 10
):
raise cv.Invalid("Calibration X values difference must be more than 10")
if (
cv.int_(calibration_config[CONF_Y_MIN]) != 0
and cv.int_(calibration_config[CONF_Y_MAX]) != 0
and abs(
cv.int_(calibration_config[CONF_Y_MIN])
- cv.int_(calibration_config[CONF_Y_MAX])
)
< 10
):
raise cv.Invalid("Calibration Y values difference must be more than 10")
return config
def calibration_schema(default_max_values):
return cv.Schema(
{
cv.Optional(CONF_X_MIN, default=0): cv.int_range(min=0, max=4095),
cv.Optional(CONF_X_MAX, default=default_max_values): cv.int_range(
min=0, max=4095
),
cv.Optional(CONF_Y_MIN, default=0): cv.int_range(min=0, max=4095),
cv.Optional(CONF_Y_MAX, default=default_max_values): cv.int_range(
min=0, max=4095
),
},
validate_calibration,
)
def touchscreen_schema(default_touch_timeout):
return cv.Schema(
{
@@ -49,6 +102,7 @@ def touchscreen_schema(default_touch_timeout):
cv.positive_time_period_milliseconds,
cv.Range(max=cv.TimePeriod(milliseconds=65535)),
),
cv.Optional(CONF_CALIBRATION): calibration_schema(0),
cv.Optional(CONF_ON_TOUCH): automation.validate_automation(single=True),
cv.Optional(CONF_ON_UPDATE): automation.validate_automation(single=True),
cv.Optional(CONF_ON_RELEASE): automation.validate_automation(single=True),
@@ -74,6 +128,17 @@ async def register_touchscreen(var, config):
cg.add(var.set_mirror_x(transform[CONF_MIRROR_X]))
cg.add(var.set_mirror_y(transform[CONF_MIRROR_Y]))
if CONF_CALIBRATION in config:
calibration_config = config[CONF_CALIBRATION]
cg.add(
var.set_calibration(
calibration_config[CONF_X_MIN],
calibration_config[CONF_X_MAX],
calibration_config[CONF_Y_MIN],
calibration_config[CONF_Y_MAX],
)
)
if CONF_ON_TOUCH in config:
await automation.build_automation(
var.get_touch_trigger(),