Touchscreen - Help!


MilloCz

Still Fresh
Joined
Apr 13, 2010
Messages
66
Age
28
Location
Czech Republic - Jihomoravské kraj
Website
www.millocz.blog.cz
Hi all, i have problem with touchscreen.
When im trying to stay on one point, it is shaking to nearby 2-3 pixels to all sides <_<
And sometimes, when im trying to draw a line, it replaces touched point to another position of display.
(my english is bad so there you can look on example pic.)
image1f.png
 
I think it is because you are getting raw data from the touch screen. You can/should probably run the values through a filter of some sort, if you need more stable values.

/Uni
 
Noisy touchscreen values, especially on the horizontal axis, have been a problem on GPH devices since it was first introduced on the GP2X F200, the Wiz's predecessor.

There is a touchscreen library, tslib, that supports most touchscreen device drivers under linux. It has modules that can be inserted to filter and smooth out touchscreens. I did not find them to be particularly helpful for curing the amount of noise in the GP2X F200 touchscreen, however.

I ultimately pulled a lot of code out of tslib and inserted it directly into the hardware-accelerated SDL for the GP2X F200. I heavily optimized it and also created a filter of my own that I found to be very successful in smoothing out the noise. You can find that code here:
http://open2x.svn.sourceforge.net/viewvc/open2x/trunk/libs-new/sdl/sdl/SDL-1.2.11/src/video/gp2x/gp2x_tslib.c?revision=375&view=markup

There is a header file it includes in that same folder. It is quite well-commented so you should be able to work things out for yourself. I can give you a brief description here, though. I hope I am remembering it correctly. It has a 15-sample buffer. When it reads a new value, it performs a weighted average of the new sample combined with all the old samples. The weights are as follows: 1-2-3-4-5-6-7-8-7-6-5-4-3-2-1 (15 samples) going from oldest to most recent, and the current sample having a relatively low weight of one. Then, it divides by the total of the weights very quickly by bit-shifting to the right 6 places (same as dividing by 64). I intentionally made the weights add up to 64, a power of 2, so the final division would be fast. Notice also in the code that it performs the multiplications required for the weighted averagings by using nothing but left-shifts and additions. It performs this for both the x and y-axis readings, and adds the averaged sample to its history and the oldest one is discarded. This averaged sample is what is reported to SDL's higher layers.

For most small movements (navigating a GUI, drawing on the screen) it is fantastic. It is very laggy for fast movements, however. Because of this, it is constantly comparing the new sample to the most recent sample. If the difference between the two is over a certain threshold, it determines that fast movement has occured and instead of performing the weighted average it instead flushes the entire history and begins it anew, reporting the sample as an unfiltered value.

The touchscreen device driver only updates its reported values at a rate of 100hz, and I actually determined that reading from it at a rate of ~50hz is more than adequate, saving CPU cycles.

I don't have enough time right now to add this to SDL for the Wiz but you could quickly adapt this to your own program and read the touchscreen device directly instead of going through SDL. I might add this to SDL later in the coming months.
 
Hopez made a modified tslib:

http://sbock.net/upload/tslib_fix_0_1.zip


DIRTY fix to tslib variance problem on GP2X WIZ

This patch replaces the variance.so file from /lib/ts on WIZ's NAND
It also modifies the /etc/tslib/ts.conf-input variance delta value that uses the touchscreen.

For greater values the stylus is more stable but has more lag on movement.
For smaller values it'll be faster but instable.

To tune up the DELTA value just edit the fixit.gpe file

This modification is experimental, don't blame me if your WIZ got screwed.

In case of errors or problems all original files are backuped to the original folder and also to the gpe folder.
So running the restore.gpe program will *hopefully* return filesystem to it's original state.
If everything is still wrong you always can reflash the firmware.

Also, on src, folder is included the modification done on tslib1.0 sourcecode.

Bugs, questions or problems: hopez13[at]gmail[dot]com or gp32spain.com forums
 
Back
Top