From 60b5776c8795b6f52d1dddf89453c42c085da50f Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Mon, 18 Oct 2010 13:32:20 -0700 Subject: [PATCH] Add support for calibrating touch position. Useful for tweaking touch screen alignment without having to modify the kernel device driver x/y axis bounds. Change-Id: I6ca43d3c138548f9dfb76aa33150a0c853698fb6 --- include/ui/InputReader.h | 10 ++++++++++ libs/ui/InputReader.cpp | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/include/ui/InputReader.h b/include/ui/InputReader.h index eb88d8bf6..2d4bf8bb1 100644 --- a/include/ui/InputReader.h +++ b/include/ui/InputReader.h @@ -584,6 +584,16 @@ protected: // Immutable calibration parameters in parsed form. struct Calibration { + // Position + bool haveXOrigin; + int32_t xOrigin; + bool haveYOrigin; + int32_t yOrigin; + bool haveXScale; + float xScale; + bool haveYScale; + float yScale; + // Touch Size enum TouchSizeCalibration { TOUCH_SIZE_CALIBRATION_DEFAULT, diff --git a/libs/ui/InputReader.cpp b/libs/ui/InputReader.cpp index 01ebda919..88b91e029 100644 --- a/libs/ui/InputReader.cpp +++ b/libs/ui/InputReader.cpp @@ -1344,7 +1344,7 @@ void TouchInputMapper::dump(String8& dump) { dumpRawAxes(dump); dumpCalibration(dump); dumpSurfaceLocked(dump); - dump.appendFormat(INDENT3 "Translation and Scaling Factors:"); + dump.appendFormat(INDENT3 "Translation and Scaling Factors:\n"); dump.appendFormat(INDENT4 "XOrigin: %d\n", mLocked.xOrigin); dump.appendFormat(INDENT4 "YOrigin: %d\n", mLocked.yOrigin); dump.appendFormat(INDENT4 "XScale: %0.3f\n", mLocked.xScale); @@ -1481,10 +1481,18 @@ bool TouchInputMapper::configureSurfaceLocked() { // Configure X and Y factors. if (mRawAxes.x.valid && mRawAxes.y.valid) { - mLocked.xOrigin = mRawAxes.x.minValue; - mLocked.yOrigin = mRawAxes.y.minValue; - mLocked.xScale = float(width) / mRawAxes.x.getRange(); - mLocked.yScale = float(height) / mRawAxes.y.getRange(); + mLocked.xOrigin = mCalibration.haveXOrigin + ? mCalibration.xOrigin + : mRawAxes.x.minValue; + mLocked.yOrigin = mCalibration.haveYOrigin + ? mCalibration.yOrigin + : mRawAxes.y.minValue; + mLocked.xScale = mCalibration.haveXScale + ? mCalibration.xScale + : float(width) / mRawAxes.x.getRange(); + mLocked.yScale = mCalibration.haveYScale + ? mCalibration.yScale + : float(height) / mRawAxes.y.getRange(); mLocked.xPrecision = 1.0f / mLocked.xScale; mLocked.yPrecision = 1.0f / mLocked.yScale; @@ -1750,6 +1758,12 @@ void TouchInputMapper::parseCalibration() { const InputDeviceCalibration& in = getDevice()->getCalibration(); Calibration& out = mCalibration; + // Position + out.haveXOrigin = in.tryGetProperty(String8("touch.position.xOrigin"), out.xOrigin); + out.haveYOrigin = in.tryGetProperty(String8("touch.position.yOrigin"), out.yOrigin); + out.haveXScale = in.tryGetProperty(String8("touch.position.xScale"), out.xScale); + out.haveYScale = in.tryGetProperty(String8("touch.position.yScale"), out.yScale); + // Touch Size out.touchSizeCalibration = Calibration::TOUCH_SIZE_CALIBRATION_DEFAULT; String8 touchSizeCalibrationString; @@ -1959,6 +1973,20 @@ void TouchInputMapper::resolveCalibration() { void TouchInputMapper::dumpCalibration(String8& dump) { dump.append(INDENT3 "Calibration:\n"); + // Position + if (mCalibration.haveXOrigin) { + dump.appendFormat(INDENT4 "touch.position.xOrigin: %d\n", mCalibration.xOrigin); + } + if (mCalibration.haveYOrigin) { + dump.appendFormat(INDENT4 "touch.position.yOrigin: %d\n", mCalibration.yOrigin); + } + if (mCalibration.haveXScale) { + dump.appendFormat(INDENT4 "touch.position.xScale: %0.3f\n", mCalibration.xScale); + } + if (mCalibration.haveYScale) { + dump.appendFormat(INDENT4 "touch.position.yScale: %0.3f\n", mCalibration.yScale); + } + // Touch Size switch (mCalibration.touchSizeCalibration) { case Calibration::TOUCH_SIZE_CALIBRATION_NONE: