From ccdfc23de0e5a8f750836580e7b5dc621ffcf36d Mon Sep 17 00:00:00 2001 From: Chih-Wei Huang Date: Sun, 2 Nov 2014 01:21:12 +0800 Subject: [PATCH] InputReader: add 5-point calibration Updated for Android 5.0. --- services/inputflinger/InputReader.cpp | 42 ++++++++++++++++++++++++++++------- services/inputflinger/InputReader.h | 3 +++ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index e00c347144..f5d1d6ff86 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -3305,6 +3305,19 @@ void TouchInputMapper::configure(nsecs_t when, configureSurface(when, &resetNeeded); } + if (!changes || (changes & InputReaderConfiguration::CHANGE_DEVICE_ALIAS)) { + // Get 5-point calibration parameters + int *p = mCalibration.fiveCal; + p[6] = 0; + if (FILE *file = fopen("/data/misc/tscal/pointercal", "r")) { + if (fscanf(file, "%d %d %d %d %d %d %d", &p[0], &p[1], &p[2], &p[3], &p[4], &p[5], &p[6]) == 7) { + p[0] *= mXScale, p[1] *= mYScale, p[3] *= mXScale, p[4] *= mYScale; + ALOGD("pointercal loaded ok"); + } + fclose(file); + } + } + if (changes && resetNeeded) { // Send reset, unless this is the first time the device has been configured, // in which case the reader will call reset itself after all mappers are ready. @@ -5089,11 +5102,24 @@ void TouchInputMapper::cookPointerData() { // Adjust X, Y, and coverage coords for surface orientation. float x, y; float left, top, right, bottom; + float x_temp = float(xTransformed - mRawPointerAxes.x.minValue); + float y_temp = float(yTransformed - mRawPointerAxes.y.minValue); + float x_cal, y_cal; + int *p = mCalibration.fiveCal; + if (p[6]) { + // Apply 5-point calibration algorithm + x_cal = (x_temp * p[0] + y_temp * p[1] + p[2] ) / p[6]; + y_cal = (x_temp * p[3] + y_temp * p[4] + p[5] ) / p[6]; + ALOGV("5cal: x_temp=%f y_temp=%f x_cal=%f y_cal=%f", x_temp, y_temp, x_cal, y_cal); + } else { + x_cal = x_temp * mXScale; + y_cal = y_temp * mYScale; + } switch (mSurfaceOrientation) { case DISPLAY_ORIENTATION_90: - x = float(yTransformed - mRawPointerAxes.y.minValue) * mYScale + mYTranslate; - y = float(mRawPointerAxes.x.maxValue - xTransformed) * mXScale + mXTranslate; + x = y_cal + mYTranslate; + y = mSurfaceWidth - x_cal + mXTranslate; left = float(rawTop - mRawPointerAxes.y.minValue) * mYScale + mYTranslate; right = float(rawBottom- mRawPointerAxes.y.minValue) * mYScale + mYTranslate; bottom = float(mRawPointerAxes.x.maxValue - rawLeft) * mXScale + mXTranslate; @@ -5104,8 +5130,8 @@ void TouchInputMapper::cookPointerData() { } break; case DISPLAY_ORIENTATION_180: - x = float(mRawPointerAxes.x.maxValue - xTransformed) * mXScale + mXTranslate; - y = float(mRawPointerAxes.y.maxValue - yTransformed) * mYScale + mYTranslate; + x = mSurfaceWidth - x_cal + mXTranslate; + y = mSurfaceHeight - y_cal + mYTranslate; left = float(mRawPointerAxes.x.maxValue - rawRight) * mXScale + mXTranslate; right = float(mRawPointerAxes.x.maxValue - rawLeft) * mXScale + mXTranslate; bottom = float(mRawPointerAxes.y.maxValue - rawTop) * mYScale + mYTranslate; @@ -5116,8 +5142,8 @@ void TouchInputMapper::cookPointerData() { } break; case DISPLAY_ORIENTATION_270: - x = float(mRawPointerAxes.y.maxValue - yTransformed) * mYScale + mYTranslate; - y = float(xTransformed - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; + x = mSurfaceHeight - y_cal + mYTranslate; + y = x_cal + mXTranslate; left = float(mRawPointerAxes.y.maxValue - rawBottom) * mYScale + mYTranslate; right = float(mRawPointerAxes.y.maxValue - rawTop) * mYScale + mYTranslate; bottom = float(rawRight - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; @@ -5128,8 +5154,8 @@ void TouchInputMapper::cookPointerData() { } break; default: - x = float(xTransformed - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; - y = float(yTransformed - mRawPointerAxes.y.minValue) * mYScale + mYTranslate; + x = x_cal + mXTranslate; + y = y_cal + mYTranslate; left = float(rawLeft - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; right = float(rawRight - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; bottom = float(rawBottom - mRawPointerAxes.y.minValue) * mYScale + mYTranslate; diff --git a/services/inputflinger/InputReader.h b/services/inputflinger/InputReader.h index 54cf590b4a..e00b9b095f 100644 --- a/services/inputflinger/InputReader.h +++ b/services/inputflinger/InputReader.h @@ -1389,6 +1389,9 @@ protected: *outSize = 0; } } + + // 5-point calibration parameters + int fiveCal[7]; } mCalibration; // Affine location transformation/calibration -- 2.11.0