- Posts: 1433
Devo12 with improved touch screen
- rbe2012
- Topic Author
- Offline
- So much to do, so little time...
The new method reads the coordinates three times, calculates the middle point, discards the coordinate with the highest distance to the middle point and returns the middle between the two remaining coordinates. It is a simple implementation, but it might eliminate coordinated which are far away.
I have tested the code on my Devo12 and my Devo8 and had no issues. I can use the touch screen from my Devo12 with my finger nails and it is quite exact.
I would like to know if there is a real improvement. I did not have great issues with the touch screen before so I am not sure if it is really better now or if I only believe it might be...
So if you are brave, install the appended dfus and tell me if you see an improvement.
The build includes some bugfixes I have implemented for the actual nightly build (PBs last version from Aug. 12). If you want to look what else has been changed: bitbucket: rbe2012-bugfixing
EDIT:
New version with activated MAV mode, untested!
Please Log in or Create an account to join the conversation.
- rbe2012
- Topic Author
- Offline
- So much to do, so little time...
- Posts: 1433
struct touch SPITouch_GetCoords()
{
#define TOUCH_READS 3
struct touch res, data[TOUCH_READS];
u32 center_x = 0, center_y = 0;
CS_LO();
// read TOUCH_READS times from the touchpad and store the values
for (int i=0; i<TOUCH_READS; i++) {
#if _TOUCH_COORDS_REVERSE
/* X and Y are swapped on Devo8 */
/* and X is reversed */
data[i].x = 255 - read_channel(READ_Y);
data[i].y = read_channel(READ_X);
#else
data[i].x = 255 - read_channel(READ_X);
data[i].y = read_channel(READ_Y);
#endif
// TODO: is it necessary to read all values? Must they also be calculated (or: are they used somewhere? AFAIK only in tx_configure.c for display testing)?
data[i].z1 = read_channel(READ_Z1);
data[i].z2 = read_channel(READ_Z2);
// add values to calculate center of measuring points
center_x += data[i].x;
center_y += data[i].y;
}
CS_HI();
#if TOUCH_READS > 1
// divide by number of measurements to correct the range
center_x /= TOUCH_READS;
center_y /= TOUCH_READS;
// search for the data point with the greatest distance to the calculated center
u32 dist = 0, max_dist = 0;
int index_max_dist = 0;
for (int i=0; i<TOUCH_READS; i++) {
dist = ((center_x - data[i].x) * (center_x - data[i].x) + (center_y - data[i].y) * (center_y - data[i].y));
// rather dist^2, but 'dist > 0' and 'a > b ==> a^2 > b^2' this will suffice to search the outlier
if (dist > max_dist) {
max_dist = dist;
index_max_dist = i;
}
}
// reset this data point
data[index_max_dist].x = 0;
data[index_max_dist].y = 0;
// recalculate the center
center_x = 0;
center_y = 0;
for (int i=0; i<TOUCH_READS; i++) {
center_x += data[i].x;
center_y += data[i].y;
}
// divide by number of measurements -1 (!, one data point discarded) to correct the range and store
res.x = center_x / (TOUCH_READS - 1);
res.y = center_y / (TOUCH_READS - 1);
#else
res.x = data[0].x;
res_y = data[0].y;
#endif
res.x = res.x * Transmitter.touch.xscale / 0x10000 + Transmitter.touch.xoffset;
if(res.x & 0x8000)
res.x = 0;
res.y = res.y * Transmitter.touch.yscale / 0x10000 + Transmitter.touch.yoffset;
if(res.y & 0x8000)
res.y = 0;
return res;
}
Please Log in or Create an account to join the conversation.
- PhracturedBlue
- Offline
- Posts: 4402
The big question is what the frequency of noise is.
I'm not sure you can sample 3 points that closely together and get good results.
I was goingto start by building a test firmware that wold sample the touch sensor as fast as possible to try to determine the frequency of the noise. Then to sample at a 1msec rate and then take the median of 'n' samples (where we'd need to determine a good value for 'n'). Since we never need to draw on the screen, we don't need super-fast response for moving the pen, but we need good accuracy for it.
I started plumbing this into the timer, but was unable to finish before I got busy again.
If your simple solution works (implying very high frequency noise), then it is much simpler than what I was going to do.
Please Log in or Create an account to join the conversation.
- FDR
- Offline
Actually I still would like to draw my curves, and it would be great too if I could drag and drop the main form's controls quickly...PhracturedBlue wrote: ...
Since we never need to draw on the screen, we don't need super-fast response for moving the pen, but we need good accuracy for it.
...
Please Log in or Create an account to join the conversation.
- Pattaya01
- Offline
- Posts: 181
Please Log in or Create an account to join the conversation.
- vlad_vy
- Offline
- Posts: 3333
Please Log in or Create an account to join the conversation.
- rbe2012
- Topic Author
- Offline
- So much to do, so little time...
- Posts: 1433
Did you recalibrate your touch screen?vlad_vy wrote: It works much better now, but there is a minor errors, generally when I press the screen at the left or below of any control, with about 1.5mm distance. If I press the screen at the right or from above of any control, it never happens.
Please Log in or Create an account to join the conversation.
- vlad_vy
- Offline
- Posts: 3333
Please Log in or Create an account to join the conversation.
- rbe2012
- Topic Author
- Offline
- So much to do, so little time...
- Posts: 1433
There is a mode called MAV (median value filter and averaging filter) which is actually not used. This does what I have implemented: it measures 7 values and throws the two highest and the to lowest away and takes the average (this costs the time for 7 measurements but should not matter).
I looked into the code. There is no real difference between the command mode and the data mode, but the lower 4 bits have different meanings in command mode. This is why the MAV mode is disabled.
An other test could be to use the differential mode (contrary to single ending mode which is actually used). This does not need a voltage reference and might be more independent from variations of the supply voltage, but needs more power.
I will make some testing in the evening if this MAV mode works and if so, I will update the dfu files for further testing.
Please Log in or Create an account to join the conversation.
- rbe2012
- Topic Author
- Offline
- So much to do, so little time...
- Posts: 1433
I have no more time today; maybe more tomorrow.
Please Log in or Create an account to join the conversation.
- Pattaya01
- Offline
- Posts: 181
1)
The original Devention SW works fundamentally different from Deveation. A command is executed on releasing the stylus, not on pressing. So I guess they just keep on reading for as long as the screen is touched, probably hundreds of readings.
2)
I was electronic hardware engineer before and we also had to de-bounce switches. The procedure was:
- Do nothing for a few miliseconds (for sure is bouncing)
- Read and compare to previous reading
- Having at least XX same readings after each other, debouncing is done
Don't know if this is of any help to you, but better share to much than to little.
Please Log in or Create an account to join the conversation.
- rbe2012
- Topic Author
- Offline
- So much to do, so little time...
- Posts: 1433
This will take us the "repeat press" ability which is often used when you press an arrow for longer time (e.g. positioning a screen element). If we only check the position when releasing we can get only one press event (maybe we could difference between short and long presses).Pattaya01 wrote: The original Devention SW works fundamentally different from Deveation. A command is executed on releasing the stylus, not on pressing. So I guess they just keep on reading for as long as the screen is touched, probably hundreds of readings.
If we would compare different readings we would have to introduce a range to allow slight movements (depends on the accuracy of the chip). I have no idea how stable the values are if the stick is not moved. I believe it might be even worse it not using the stick but the finger (nail) where pressure could change (in time, over the pressing area) and with this the value read.- Do nothing for a few miliseconds (for sure is bouncing)
- Read and compare to previous reading
- Having at least XX same readings after each other, debouncing is done
Your last point could cost many time (again depending on the accuracy) for reading a single coordinate - not sure if we have it or if we would have to do this asynchronously and implement a buffer for the readings, what could make things more difficult.
What vlad has told is quite interesting: the values read are shifted in a special direction (have to look: to -X/-Y or +X/+Y). If we know this we could also eliminate values which are in this direction and keep those closer to the wanted point. Can anybody confirm this?
BTW: I have a protection foil on the screen. Has anybody tested if it makes things better or worse or just doesn't change anything? I don't remember a significant change, but I changed the original foil to one for an iPad and never used the screen without. If I will run out of ideas I will remove mine to see...
Please Log in or Create an account to join the conversation.
- vlad_vy
- Offline
- Posts: 3333
I have not any protection foil on the screen.
Please Log in or Create an account to join the conversation.
- vlad_vy
- Offline
- Posts: 3333
Do you see small artifact at right edge of screen, after pages with scroll bar? It seems that backgroung BMP shifted one pixel to the left.
Please Log in or Create an account to join the conversation.
- rbe2012
- Topic Author
- Offline
- So much to do, so little time...
- Posts: 1433
Is there a "white" area at the top and right of an element where a touch is not registered? Or: is the sensitive area bigger than it should be or slightly shifted?vlad_vy wrote: It works much better now, but there is a minor errors, generally when I press the screen at the left or below of any control, with about 1.5mm distance. If I press the screen at the right or from above of any control, it never happens.
I don't have my tx here and will look later at the background.
Please Log in or Create an account to join the conversation.
- vlad_vy
- Offline
- Posts: 3333
Please Log in or Create an account to join the conversation.
- rbe2012
- Topic Author
- Offline
- So much to do, so little time...
- Posts: 1433
Do you mean you recalibrated the touch screen several times?After several attempts I get perfect calibration...
Sounds like good news. If the behavior you have seen can be confirmed for more Devo12 we might be able to correct the values in this area.
Possibly we could extend the calibration screen with more points so we can make a base calibration with coordinates a little away from the right edge and combine this with some readings from the right.
I will try to add some points to the calibration screen (e.g. diagonal from upper left to lower right) and see if any two points result in the same calibration parameters or if somewhere is a recognizable difference.
Please Log in or Create an account to join the conversation.
- Pattaya01
- Offline
- Posts: 181
Please Log in or Create an account to join the conversation.
- Pattaya01
- Offline
- Posts: 181
I have tried to get an error, couldn't get !!!!!!
Seems you are on the right track. As far as I am concerned, this solves the problem. Congrats.....
I am also using screen protector.
Please Log in or Create an account to join the conversation.
- Pattaya01
- Offline
- Posts: 181
rbe2012 wrote: I will try to add some points to the calibration screen (e.g. diagonal from upper left to lower right) and see if any two points result in the same calibration parameters or if somewhere is a recognizable difference.
Why not like most devices: all 4 corners and the center..
Please Log in or Create an account to join the conversation.
- Home
- Forum
- Development
- Builds
- Devo12 with improved touch screen