frameworks/base
Révision | 8b3ef0923b08854d1593b91637c304e2f28a45ea (tree) |
---|---|
l'heure | 2012-01-01 21:32:46 |
Auteur | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
InputReader: add 5-point calibration
@@ -2481,6 +2481,16 @@ void TouchInputMapper::parseCalibration() { | ||
2481 | 2481 | orientationCalibrationString.string()); |
2482 | 2482 | } |
2483 | 2483 | } |
2484 | + | |
2485 | + // Get 5-point calibration parameters | |
2486 | + FILE *file = fopen("/data/system/tslib/pointercal", "r"); | |
2487 | + int *p = out.fiveCal; | |
2488 | + if (file) { | |
2489 | + fscanf(file, "%d %d %d %d %d %d %d", &p[0], &p[1], &p[2], &p[3], &p[4], &p[5], &p[6]); | |
2490 | + fclose(file); | |
2491 | + } else { | |
2492 | + p[6] = 0; | |
2493 | + } | |
2484 | 2494 | } |
2485 | 2495 | |
2486 | 2496 | void TouchInputMapper::resolveCalibration() { |
@@ -3191,33 +3201,47 @@ void TouchInputMapper::prepareTouches(int32_t* outEdgeFlags, | ||
3191 | 3201 | orientation = 0; |
3192 | 3202 | } |
3193 | 3203 | |
3204 | + float x_temp = float(in.x - mRawAxes.x.minValue); | |
3205 | + float y_temp = float(in.y - mRawAxes.y.minValue); | |
3206 | + float x_cal, y_cal; | |
3207 | + int *p = mCalibration.fiveCal; | |
3208 | + if (p[6]) { | |
3209 | + // Apply 5-point calibration algorithm | |
3210 | + x_cal = (x_temp * p[0] + y_temp * p[1] + p[2] ) / p[6]; | |
3211 | + y_cal = (x_temp * p[3] + y_temp * p[4] + p[5] ) / p[6]; | |
3212 | + LOGV("5cal: x_temp=%f y_temp=%f x_cal=%f y_cal=%f", x_temp, y_temp, x_cal, y_cal); | |
3213 | + } else { | |
3214 | + x_cal = x_temp * mLocked.xScale; | |
3215 | + y_cal = y_temp * mLocked.yScale; | |
3216 | + } | |
3217 | + | |
3194 | 3218 | // X and Y |
3195 | 3219 | // Adjust coords for surface orientation. |
3196 | 3220 | float x, y; |
3197 | 3221 | switch (mLocked.surfaceOrientation) { |
3198 | 3222 | case DISPLAY_ORIENTATION_90: |
3199 | - x = float(in.y - mRawAxes.y.minValue) * mLocked.yScale; | |
3200 | - y = float(mRawAxes.x.maxValue - in.x) * mLocked.xScale; | |
3223 | + x = y_cal; | |
3224 | + y = mLocked.surfaceWidth - x_cal; | |
3201 | 3225 | orientation -= M_PI_2; |
3202 | 3226 | if (orientation < - M_PI_2) { |
3203 | 3227 | orientation += M_PI; |
3204 | 3228 | } |
3205 | 3229 | break; |
3206 | 3230 | case DISPLAY_ORIENTATION_180: |
3207 | - x = float(mRawAxes.x.maxValue - in.x) * mLocked.xScale; | |
3208 | - y = float(mRawAxes.y.maxValue - in.y) * mLocked.yScale; | |
3231 | + x = mLocked.surfaceWidth - x_cal; | |
3232 | + y = mLocked.surfaceHeight - y_cal; | |
3209 | 3233 | break; |
3210 | 3234 | case DISPLAY_ORIENTATION_270: |
3211 | - x = float(mRawAxes.y.maxValue - in.y) * mLocked.yScale; | |
3212 | - y = float(in.x - mRawAxes.x.minValue) * mLocked.xScale; | |
3235 | + x = mLocked.surfaceHeight - y_cal; | |
3236 | + y = x_cal; | |
3213 | 3237 | orientation += M_PI_2; |
3214 | 3238 | if (orientation > M_PI_2) { |
3215 | 3239 | orientation -= M_PI; |
3216 | 3240 | } |
3217 | 3241 | break; |
3218 | 3242 | default: |
3219 | - x = float(in.x - mRawAxes.x.minValue) * mLocked.xScale; | |
3220 | - y = float(in.y - mRawAxes.y.minValue) * mLocked.yScale; | |
3243 | + x = x_cal; | |
3244 | + y = y_cal; | |
3221 | 3245 | break; |
3222 | 3246 | } |
3223 | 3247 |
@@ -873,6 +873,9 @@ protected: | ||
873 | 873 | }; |
874 | 874 | |
875 | 875 | OrientationCalibration orientationCalibration; |
876 | + | |
877 | + // 5-point calibration parameters | |
878 | + int fiveCal[7]; | |
876 | 879 | } mCalibration; |
877 | 880 | |
878 | 881 | // Raw axis information from the driver. |