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 > Won't read touchscreen

#43086 - ANeo7782 - Wed May 18, 2005 11:18 pm

I wrote a bit of code based on a couple other programs, and I absolutely cannot get my program to read touchscreen input. It absolutely loves to think there's input throughout the whole run, but it doesn't give me any valid values.

I'm using
Code:
if (((~IPC->buttons) << 6) & (1<<12)) {
  x = ((IPC->touchX - 0x0113) / 14) << 8;
  y = ((IPC->touchY - 0x00E0) / 19) << 8;
}

in a while loop and trying to go from there.
_________________
AndrewNeo - Username disallowed.
NCN DSDev Team Leader

#43098 - josath - Thu May 19, 2005 1:40 am

If you are basing your code of the newer ndslib, and you use the template arm7 binary, you can call IPC->touchXpx and IPC->touchYpx to get actual x & y coordinates. If not, here is the touch calibration code:

Code:

//////////////////////////////////////////////////////////////////////


#define TOUCH_CAL_X1 (*(vs16*)0x027FFCD8)
#define TOUCH_CAL_Y1 (*(vs16*)0x027FFCDA)
#define TOUCH_CAL_X2 (*(vs16*)0x027FFCDE)
#define TOUCH_CAL_Y2 (*(vs16*)0x027FFCE0)
#define SCREEN_WIDTH    256
#define SCREEN_HEIGHT   192
s32 TOUCH_WIDTH  = TOUCH_CAL_X2 - TOUCH_CAL_X1;
s32 TOUCH_HEIGHT = TOUCH_CAL_Y2 - TOUCH_CAL_Y1;
s32 TOUCH_OFFSET_X = ( ((SCREEN_WIDTH -60) * TOUCH_CAL_X1) / TOUCH_WIDTH  ) - 28;
s32 TOUCH_OFFSET_Y = ( ((SCREEN_HEIGHT-60) * TOUCH_CAL_Y1) / TOUCH_HEIGHT ) - 28;


//////////////////////////////////////////////////////////////////////

    if (!(IPC->buttons & 0x40)) { // pen is down
      x = IPC->touchX;
      y = IPC->touchY;
      xpx = ( ((SCREEN_WIDTH -60) * x) / TOUCH_WIDTH  ) - TOUCH_OFFSET_X;
      ypx = ( ((SCREEN_HEIGHT-60) * y) / TOUCH_HEIGHT ) - TOUCH_OFFSET_Y;
    }

#43103 - Darkain - Thu May 19, 2005 3:10 am

actually, to 1-up all of you... just get latest NDSLIB, and use IPC-touchXpx/Ypx... these are the pre-calculated pixel values. plus, once we come up w/ a better algorithm for calculating pixel values, the most you would have to do to your code is recompile. no other modifications would be needed.

nice n easy, eh? ;)
_________________
-=- Darkain Dragoon -=-
http://www.darkain.com
DarkStar for Nintendo DS

#43107 - tepples - Thu May 19, 2005 5:38 am

Does latest NDSLIB have a flag for when the coordinates have stabilized (as opposed to the widely-complained-about random lines in dspaint)?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#43162 - ANeo7782 - Thu May 19, 2005 6:47 pm

I am using the very newest ndslib from CVS, and when I try to use touchX and touchY I get weird values, and touchXpx and touchYpx get 0 for both. Also, the ((~IPC->buttons) << 6) & (1<<12) code constantly returns true, even if I'm not touching the screen. I've only been able to test on an emulator (usually dualis) so far, but it's not registering nada when I click on the bottom (and touch works with other demos).

To me, it's almost like it's not processing the ARM7 code (I've been executing the ARM9/arm9.bin file, is that right?) because I couldn't get the RTC to return values either (though I may have just been doing that wrong.)
_________________
AndrewNeo - Username disallowed.
NCN DSDev Team Leader

#43164 - tepples - Thu May 19, 2005 7:03 pm

ANeo7782 wrote:
Also, the ((~IPC->buttons) << 6) & (1<<12) code constantly returns true, even if I'm not touching the screen. I've only been able to test on an emulator (usually dualis) so far [...] To me, it's almost like it's not processing the ARM7 code

Dualis emulates the ARM9 and high-level-emulates the ARM7, which means that if the format of the IPC structure changes, Dualis won't notice and will continue to assume the old structure. Use iDeaS.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#43166 - ANeo7782 - Thu May 19, 2005 7:06 pm

That'd be a good reason.. though I think with ideas I had trouble getting anything but the background to appear on the screen..
_________________
AndrewNeo - Username disallowed.
NCN DSDev Team Leader

#43167 - dovoto - Thu May 19, 2005 7:35 pm

Be sure and reinstall the startup files if you are using the newest cvs. They were all out of synch for a few days causeing arm7 code to not exicute at all.
_________________
www.drunkencoders.com

#43171 - Ethos - Thu May 19, 2005 7:57 pm

Well I wouldn't use ideas with the newest CVS, it sorta crashes!! (or at least on my end)
_________________
Ethos' Homepage (Demos/NDS 3D Tutorial)

#43173 - ANeo7782 - Thu May 19, 2005 8:26 pm

I'm using iDeaS 1.0.0.2, not from CVS. I'll download 1.0.0.4 and see if it makes a difference.

Edit: Okay, I can see top and bottom (it was probably an error in my code) but touchscreen still doesn't work..
_________________
AndrewNeo - Username disallowed.
NCN DSDev Team Leader