Thanks for your post Elvis! Android was having an issue with my touchscreen (both the x and y axis were inverted) and this was the perfect patch! I just copied over my existing tslib calibration to /pointercal (I changed the default filename) and now it's quite precise. Naturally, I generated the tslib calibration using a different distro (Gentoo).
Touchscreen calibration is a bit of a tricky issue - even identical touchscreen models will have some variance in their calibration. Even though that variance is often only be a few pixels, it's still naive to think that Android does not need a calibration utility. Seriously, even WinCE has one. One simple way to fix this issue is to use set average pointer calibration data in /default.prop. The defaults will be good enough for devices with the same touchscreen hardware (i.e. vendor-product), and the user could override those values by using a calibration utility, updating the property inside of the sqlite database. Properties could be named something along the lines of com.android.server.InputDevice.TransformInfo.x1 com.android.server.InputDevice.TransformInfo.y1 com.android.server.InputDevice.TransformInfo.z1 com.android.server.InputDevice.TransformInfo.x2 com.android.server.InputDevice.TransformInfo.y2 Again, thanks for your patch, it was quite helpful. Cheers, Chris On Mon, Jun 22, 2009 at 9:31 PM, Elvis Dowson <[email protected]> wrote: > Hi, > Try applying this patch. > diff --git a/services/java/com/android/server/InputDevice.java > b/services/java/com/android/server/InputDevice.java > index 7b8a2a4..d9304c1 100644 > --- a/services/java/com/android/server/InputDevice.java > +++ b/services/java/com/android/server/InputDevice.java > @@ -21,10 +21,15 @@ import android.view.Display; > import android.view.MotionEvent; > import android.view.Surface; > import android.view.WindowManagerPolicy; > +import java.io.FileInputStream; > +import java.util.StringTokenizer; > > public class InputDevice { > /** Amount that trackball needs to move in order to generate a key > event. */ > static final int TRACKBALL_MOVEMENT_THRESHOLD = 6; > + > + /** Touchscreen calibration file. */ > + static final String CALIBRATION_FILE = "/etc/pointercal"; > > final int id; > final int classes; > @@ -33,6 +38,7 @@ public class InputDevice { > final AbsoluteInfo absY; > final AbsoluteInfo absPressure; > final AbsoluteInfo absSize; > + final TransformInfo tInfo; > > long mDownTime = 0; > int mMetaKeysState = 0; > @@ -86,12 +92,24 @@ public class InputDevice { > h = tmp; > } > if (device.absX != null) { > - scaledX = ((scaledX-device.absX.minValue) > - / device.absX.range) * w; > + if (device.tInfo != null) > + scaledX = (device.tInfo.x1 * x + > + device.tInfo.y1 * y + > + device.tInfo.z1) > + / device.tInfo.s; > + else > + scaledX = ((scaledX-device.absX.minValue) > + / device.absX.range) * w; > } > if (device.absY != null) { > - scaledY = ((scaledY-device.absY.minValue) > - / device.absY.range) * h; > + if (device.tInfo != null) > + scaledY = (device.tInfo.x2 * x + > + device.tInfo.y2 * y + > + device.tInfo.z2) > + / device.tInfo.s; > + else > + scaledY = ((scaledY-device.absY.minValue) > + / device.absY.range) * h; > } > if (device.absPressure != null) { > scaledPressure = > @@ -199,6 +217,16 @@ public class InputDevice { > int fuzz; > }; > > + static class TransformInfo { > + float x1; > + float y1; > + float z1; > + float x2; > + float y2; > + float z2; > + float s; > + }; > + > InputDevice(int _id, int _classes, String _name, > AbsoluteInfo _absX, AbsoluteInfo _absY, > AbsoluteInfo _absPressure, AbsoluteInfo _absSize) { > @@ -209,5 +237,38 @@ public class InputDevice { > absY = _absY; > absPressure = _absPressure; > absSize = _absSize; > + TransformInfo t = null; > + > + try { > + FileInputStream is = new FileInputStream(CALIBRATION_FILE); > + byte[] mBuffer = new byte[64]; > + int len = is.read(mBuffer); > + is.close(); > + > + if (len > 0) { > + int i; > + for (i = 0 ; i < len ; i++) { > + if (mBuffer[i] == '\n' || mBuffer[i] == 0) { > + break; > + } > + } > + len = i; > + } > + > + StringTokenizer st = new StringTokenizer( new String(mBuffer, 0, 0, len) > ); > + > + t = new TransformInfo (); > + t.x1 = Integer.parseInt( st.nextToken() ); > + t.y1 = Integer.parseInt( st.nextToken() ); > + t.z1 = Integer.parseInt( st.nextToken() ); > + t.x2 = Integer.parseInt( st.nextToken() ); > + t.y2 = Integer.parseInt( st.nextToken() ); > + t.z2 = Integer.parseInt( st.nextToken() ); > + t.s = Integer.parseInt( st.nextToken() ); > + } catch (java.io.FileNotFoundException e) { > + } catch (java.io.IOException e) { > + } > + tInfo = t; > + > } > }; > > Elvis > > > --~--~---------~--~----~------------~-------~--~----~ unsubscribe: [email protected] website: http://groups.google.com/group/android-porting -~----------~----~----~----~------~----~------~--~---
