# Calibrating the HTC TouchPro's touchscreen

For the record, and because it gave me a hard time, here is how I could finally calibrate the touchscreen of an HTC TouchPro running hackable:1:

# rm -f /etc/pointercal

# export TSLIB_FBDEVICE=/dev/fb0

# export TSLIB_TSDEVICE=/dev/input/event3

# export TSLIB_CALIBFILE=/etc/pointercal

# export TSLIB_CONFFILE=/etc/ts.conf

# ts_calibrate

And the winner is:

# cat /etc/pointercal

-626 -42507 37731912 53487 254 -5420672 65536

I had to do this while running X, otherwise I only got trash on the framebuffer at best, and then nothing seemed to really happen.

Initially, I tried to find a way to understand and convert Android's data to the values expected by tslib. I started with the latter, and eventually gave up as these values seemed poorly documented at best: it essentially consisted in a couple mailing-list posts basically saying that "no, you should not generate calibration values yourself". But what if I have known, valid data?

Anyway, I could finally find some hints there:

http://doc.trolltech.com/4.3/qwscalibratedmousehandler.html#transform

And then in the source code for tslib:

plugins/linear.c, struct tslib_linear:

25 struct tslib_linear {

26 struct tslib_module_info module;

27 int swap_xy;

28

29 // Linear scaling and offset parameters for pressure

30 int p_offset;

31 int p_mult;

32 int p_div;

34 // Linear scaling and offset parameters for x,y (can include rotation)

35 int a[7];

36 };

plugins/linear.c, mod_init():

132 /*

133 * Check calibration file

134 */

135 if( (calfile = getenv("TSLIB_CALIBFILE")) == NULL) calfile = defaultcalfile;

136 if(stat(calfile,&sbuf)==0) {

137 pcal_fd = open(calfile,O_RDONLY);

138 read(pcal_fd,pcalbuf,200);

139 lin->a[0] = atoi(strtok(pcalbuf," "));

140 index=1;

141 while(index<7) {

142 tokptr = strtok(NULL," ");

143 if(*tokptr!='\0') {

144 lin->a[index] = atoi(tokptr);

145 index++;

146 }

147 }

plugins/linear.c, linear_read():

53 xtemp = samp->x; ytemp = samp->y;

54 samp->x = ( lin->a[2] +

55 lin->a[0]*xtemp +

56 lin->a[1]*ytemp ) / lin->a[6];

57 samp->y = ( lin->a[5] +

58 lin->a[3]*xtemp +

59 lin->a[4]*ytemp ) / lin->a[6];

Credits go there:

http://automon.donaloconnor.net/installing-tslib-and-calibrating-it/83/

# rm -f /etc/pointercal

# export TSLIB_FBDEVICE=/dev/fb0

# export TSLIB_TSDEVICE=/dev/input/event3

# export TSLIB_CALIBFILE=/etc/pointercal

# export TSLIB_CONFFILE=/etc/ts.conf

# ts_calibrate

And the winner is:

# cat /etc/pointercal

-626 -42507 37731912 53487 254 -5420672 65536

I had to do this while running X, otherwise I only got trash on the framebuffer at best, and then nothing seemed to really happen.

Initially, I tried to find a way to understand and convert Android's data to the values expected by tslib. I started with the latter, and eventually gave up as these values seemed poorly documented at best: it essentially consisted in a couple mailing-list posts basically saying that "no, you should not generate calibration values yourself". But what if I have known, valid data?

Anyway, I could finally find some hints there:

http://doc.trolltech.com/4.3/qwscalibratedmousehandler.html#transform

And then in the source code for tslib:

plugins/linear.c, struct tslib_linear:

25 struct tslib_linear {

26 struct tslib_module_info module;

27 int swap_xy;

28

29 // Linear scaling and offset parameters for pressure

30 int p_offset;

31 int p_mult;

32 int p_div;

34 // Linear scaling and offset parameters for x,y (can include rotation)

35 int a[7];

36 };

plugins/linear.c, mod_init():

132 /*

133 * Check calibration file

134 */

135 if( (calfile = getenv("TSLIB_CALIBFILE")) == NULL) calfile = defaultcalfile;

136 if(stat(calfile,&sbuf)==0) {

137 pcal_fd = open(calfile,O_RDONLY);

138 read(pcal_fd,pcalbuf,200);

139 lin->a[0] = atoi(strtok(pcalbuf," "));

140 index=1;

141 while(index<7) {

142 tokptr = strtok(NULL," ");

143 if(*tokptr!='\0') {

144 lin->a[index] = atoi(tokptr);

145 index++;

146 }

147 }

plugins/linear.c, linear_read():

53 xtemp = samp->x; ytemp = samp->y;

54 samp->x = ( lin->a[2] +

55 lin->a[0]*xtemp +

56 lin->a[1]*ytemp ) / lin->a[6];

57 samp->y = ( lin->a[5] +

58 lin->a[3]*xtemp +

59 lin->a[4]*ytemp ) / lin->a[6];

Credits go there:

http://automon.donaloconnor.net/installing-tslib-and-calibrating-it/83/