gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Better Touch Code

#42096 - Pacifist - Thu May 05, 2005 9:26 pm

I've been using Darkain's calibration code to read the touch-screen.

Like everyone else it works very well for me except that I get those shooting lines into the middle of the screen when using the darkstar paint program.

I've found a way to eliminate this effect in my own project using natrium42's under pressure code.

Instead of reading the DS's guess at if the pen is down

Code:

return( ((~IPC->buttons) << 6) & (1<<12) );


You roll your own touchPressed method by stealing natruims code straight out of his demo:

Code:

int TouchPad::touchPressed()
{
   uint16 touchZ1 = IPC->touchZ1;
   uint16 touchZ2 = IPC->touchZ2;
   uint16 touchX = IPC->touchX;

   uint16 pressure = (touchX * touchZ2) / (64 * touchZ1) - touchX / 64;

   if( pressure > 0 && pressure < MAX_PRESSURE )
      return 1;
   else
      return 0;
}


Using a MAX_PRESSURE of 70 I get no anomolous readings and, strangely enough, a more sensitive touch pad.

I am worried that all the DS's are going to have different touch threshholds though and am curious about other people's findings with this code.

(when experimenting remember that lower numbers represent higher pressures)

#42110 - DaBigJHall - Fri May 06, 2005 3:08 am

I tried something similar; I modified the ARM7 stub so it calculates the pressure and doesn't actually fill in the relevant members of the IPC unless 5 < pressure < 75. One less thing for the ARM9 to do :D. For some reason the shooting-lines-things were reading a pressure of 0, that's why I made a lower limit of 5. Did you notice anything like this? I wonder if it's just my DS, since the touch screen's a little scratched.
_________________
Yep, it's a signature.

#42116 - Pacifist - Fri May 06, 2005 6:13 am

no I actually tested for that specifically.

I was a little surprised that zero worked for me but I'll change it to 5 now that I know that isn't true of all DSs.

#42138 - Darkain - Fri May 06, 2005 5:20 pm

the problem is that his code isnt correct. between my two units, one of them has a NORMAL pressure of around 70 (and maxs around 90 for errors), and the other has normal around 20, and around 30 for errors. i used to use his code, and everyone complained because the touch screen no longer worked.

its a nice theory, but bad in practice, sorries. :(

[EDIT]
in DarkStar, in the debug screen, if you look at the top, you will see "TOUCH Z" followed by 2 numbers. the first number is a pair of 16 bit values representing Z1 and Z2, the second value is the calculated pressure value using natriums code, for anyone curious (damn, i love that debug screen :)
[/EDIT]
_________________
-=- Darkain Dragoon -=-
http://www.darkain.com
DarkStar for Nintendo DS

#42140 - Pacifist - Fri May 06, 2005 5:55 pm

So natrium's formula is TI's pressure formula

pressure = "resistance across the x-plate" * (touchX/4096) * ( (touchZ2/touchZ1)-1 )

multiplied by 64 and without the resistance across the x-plate.

Is it possible that the resistance would somehow normalize the pressure value between different DSs?

Presumably we don't have access to the pressure accross the x plate or natrium would have included it in his formula, correct?

Also, I assume the DS doesn't store callibration information for Z values. :/

Using natrium's pressure formula just works so well I don't want to give it up. It should be reasonably easy to callibrate a pressure based on the user navigating the start menus of a game.

Failing that the first few actions in gameplay could be used.