From 276ccda2f3e96984b392c0429a5da8b804baacdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=81o=C5=9B?= Date: Fri, 14 Mar 2025 14:28:06 +0100 Subject: [PATCH] Pass VxWorks touch ranges via environment variable Some VxWorks touch device drivers return improper value of min and max ranges in both axes (both 0 for both axes). This makes any touch point position equal to (0, 0), making touch unusable in Qt. [ChangeLog][Platform Specific Changes][VxWorks] The user can now override touch ranges that the driver returns, by setting the new parameters "rangex" and "rangey" on the environment variable QT_QPA_VXEVDEV_TOUCHSCREEN_PARAMETERS with comma-separated min and max touch ranges for X and Y axis respectively. For example, add rangex=10,815:rangey=15,1024 Pick-to: 6.9 Task-number: QTBUG-115777 Change-Id: I4f4aba7ee66e76b80438888697f84c4db9896c3d Reviewed-by: Shawn Rutledge --- .../input/vxtouch/qvxtouchhandler.cpp | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/platformsupport/input/vxtouch/qvxtouchhandler.cpp b/src/platformsupport/input/vxtouch/qvxtouchhandler.cpp index 16c90adc95b..e1997b00d20 100644 --- a/src/platformsupport/input/vxtouch/qvxtouchhandler.cpp +++ b/src/platformsupport/input/vxtouch/qvxtouchhandler.cpp @@ -172,10 +172,37 @@ QVxTouchScreenHandler::QVxTouchScreenHandler(const QString &device, const QStrin { setObjectName("Vx Touch Handler"_L1); + // range is described as a pair of two unsigned numbers separated by comma, for example: + // rangex=123,543 + // If any number is incorrect, range description is ignored. + auto updateRange = [](const QString& argString, int& rangeMin, int& rangeMax) { + QString rangeDefinition = argString.section(u'=', 1, 1); + auto rangeMinMax = rangeDefinition.split(u','); + + if (rangeMinMax.size() != 2) + return false; + + bool minOk = false; + bool maxOk = false; + int min = rangeMinMax[0].toUInt(&minOk); + int max = rangeMinMax[1].toUInt(&maxOk); + if (!minOk || !maxOk) + return false; + + rangeMin = min; + rangeMax = max; + return true; + }; + const QStringList args = spec.split(u':'); + + d = new QVxTouchScreenData(this, args); + int rotationAngle = 0; bool invertx = false; bool inverty = false; + bool rangeXOverride = false; + bool rangeYOverride = false; for (int i = 0; i < args.size(); ++i) { if (args.at(i).startsWith("rotate"_L1)) { QString rotateArg = args.at(i).section(u'=', 1, 1); @@ -196,6 +223,10 @@ QVxTouchScreenHandler::QVxTouchScreenHandler(const QString &device, const QStrin invertx = true; } else if (args.at(i) == "inverty"_L1) { inverty = true; + } else if (args.at(i).startsWith("rangex"_L1)) { + rangeXOverride = updateRange(args.at(i), d->hw_range_x_min, d->hw_range_x_max); + } else if (args.at(i).startsWith("rangey"_L1)) { + rangeYOverride = updateRange(args.at(i), d->hw_range_y_min, d->hw_range_y_max); } } @@ -211,8 +242,6 @@ QVxTouchScreenHandler::QVxTouchScreenHandler(const QString &device, const QStrin return; } - d = new QVxTouchScreenData(this, args); - UINT32 devCap = 0; if (ioctl(m_fd, EV_DEV_IO_GET_CAP, (char *)&devCap) != ERROR) { @@ -239,7 +268,7 @@ QVxTouchScreenHandler::QVxTouchScreenHandler(const QString &device, const QStrin axisVal[0].axisIndex = 0; axisVal[1].axisIndex = 1; - if (ioctl(m_fd, EV_DEV_IO_GET_AXIS_VAL, (char *)&axisVal[0]) != ERROR) { + if (!rangeXOverride && ioctl(m_fd, EV_DEV_IO_GET_AXIS_VAL, (char *)&axisVal[0]) != ERROR) { qCDebug(qLcVxTouch, "vxtouch: %s: min X: %d max X: %d", qPrintable(device), axisVal[0].minVal, axisVal[0].maxVal); d->hw_range_x_min = axisVal[0].minVal; @@ -247,7 +276,7 @@ QVxTouchScreenHandler::QVxTouchScreenHandler(const QString &device, const QStrin has_x_range = true; } - if (ioctl(m_fd, EV_DEV_IO_GET_AXIS_VAL, (char *)&axisVal[1]) != ERROR) { + if (!rangeXOverride && ioctl(m_fd, EV_DEV_IO_GET_AXIS_VAL, (char *)&axisVal[1]) != ERROR) { qCDebug(qLcVxTouch, "vxtouch: %s: min Y: %d max Y: %d", qPrintable(device), axisVal[1].minVal, axisVal[1].maxVal); d->hw_range_y_min = axisVal[1].minVal; @@ -260,11 +289,11 @@ QVxTouchScreenHandler::QVxTouchScreenHandler(const QString &device, const QStrin // Fix up the coordinate ranges for am335x in case the kernel driver does not have them fixed. if (d->hw_name == "ti-tsc"_L1) { - if (d->hw_range_x_min == 0 && d->hw_range_x_max == 4095) { + if (!rangeXOverride && d->hw_range_x_min == 0 && d->hw_range_x_max == 4095) { d->hw_range_x_min = 165; d->hw_range_x_max = 4016; } - if (d->hw_range_y_min == 0 && d->hw_range_y_max == 4095) { + if (!rangeYOverride && d->hw_range_y_min == 0 && d->hw_range_y_max == 4095) { d->hw_range_y_min = 220; d->hw_range_y_max = 3907; }