#166015 - afireohno - Fri Jan 16, 2009 10:19 pm
I'm getting some strangeness using keysDown(), etc in combination with KEY_X and KEY_Y inside a class. It always evaluates to true. KEY_A and KEY_B work exactly as I would expect. I've even tried something like
Code: |
scanKeys();
keysD = keysDown();
myClass->foo(keysD);
|
No luck.
Does anyone have any ideas what I might be doing wrong.
edit: So after messing around some I'm more confused than originally.
Code: |
//in main
bool g = false;
while(1)
{
scanKeys()
if (keysHeld() & KEY_X)
{
g = true;
}
|
g is immediately not zero?
Last edited by afireohno on Sat Jan 17, 2009 7:08 pm; edited 2 times in total
#166020 - elhobbs - Sat Jan 17, 2009 5:30 am
scanKeys must be called at least twice before keysHeld has a usable value. there is a thread on the subject... but I could not find it.
scanKeys stores the state of the keys internally. keysDown can be used to determine if button was pressed since the last call to scanKeys. keysHeld can be used to determine if the button was down for two or more calls to scanKeys.
#166024 - afireohno - Sat Jan 17, 2009 11:22 am
I've tried keysDown()
Everything works normally with KEY_A, KEY_B, etc. It is only KEY_Y, and KEY_X that cause the statement to evaluate true without any presses.
#166025 - TwentySeven - Sat Jan 17, 2009 12:10 pm
You're going to have to post alot more source.
#166026 - Cearn - Sat Jan 17, 2009 2:37 pm
If you don't get any response from X and Y at all, you may still have an irqInit() somewhere. As far as I can know, extra calls to irqInit effectively disables the FIFO system used for inter-processor communication. Since X and Y come from the Arm7, this would leave them inactive.
#166027 - afireohno - Sat Jan 17, 2009 2:52 pm
I don't have irqInit() but maybe I'm missing a needed init somewhere. Here is a simple test prog I made up to demonstrate the behavior with as little code as possible.
Code: |
#include <nds.h>
#include <stdio.h>
int main()
{
consoleDemoInit();
int test = 0;
while(1) {
scanKeys();
if(keysHeld() & KEY_X)
{
test = 1;
}
swiWaitForVBlank();
consoleClear();
printf("test = %i",test);
}
return 0;
}
|
It's probably something simple but I can't figure it out.
edit: took out some more code.
tested on no$gba. I'm away from hardware so I haven't tried that yet.
edit: edit: test with different keys (i.e. KEY_A) and it works as expected.
KEY_X, and KEY_Y set test to 1 without any presses.
could consoleDemoInit() be the culprit?
Last edited by afireohno on Sat Jan 17, 2009 3:17 pm; edited 1 time in total
#166028 - Legolas - Sat Jan 17, 2009 3:08 pm
This works for me:
Code: |
#include <nds.h>
#include <stdio.h>
int main()
{
consoleDemoInit();
int test = 0;
while(1) {
scanKeys();
if(keysHeld() & KEY_X)
{
test = 1;
} else /// <----------
{ /// <----------
test = 0; /// <----------
} /// <----------
swiWaitForVBlank();
consoleClear();
printf("test = %i",test);
}
return 0;
}
|
_________________
My homepage!
#166029 - afireohno - Sat Jan 17, 2009 3:23 pm
Legolas wrote: |
This works for me: |
Yeah this works as expected for me as well.
edit: After testing random things I found that waiting 2 or more VBlanks before calling scanKeys() fixes the problem. I have no idea why so if anyone could explain this behavior or knows what I might be doing wrong I would appreciate the info. Thanks for the help. Working code.
Code: |
#include <nds.h>
#include <stdio.h>
int main()
{
consoleDemoInit();
for (int i = 0; i <2; i++)
{
swiWaitForVBlank();
}
int test = 0;
while(1) {
scanKeys();
if(keysHeld() & KEY_X)
{
test = 1;
}
swiWaitForVBlank();
consoleClear();
printf("test = %i",test);
}
return 0;
}
|
#166036 - Echo49 - Sun Jan 18, 2009 1:56 am
elhobbs wrote: |
scanKeys must be called at least twice before keysHeld has a usable value. there is a thread on the subject... but I could not find it.
scanKeys stores the state of the keys internally. keysDown can be used to determine if button was pressed since the last call to scanKeys. keysHeld can be used to determine if the button was down for two or more calls to scanKeys. |
edit: i'm sorry, i read the question wrong
Last edited by Echo49 on Mon Jan 19, 2009 6:13 am; edited 1 time in total
#166049 - afireohno - Sun Jan 18, 2009 9:52 pm
Echo49 wrote: |
elhobbs wrote: | scanKeys must be called at least twice before keysHeld has a usable value. there is a thread on the subject... but I could not find it.
scanKeys stores the state of the keys internally. keysDown can be used to determine if button was pressed since the last call to scanKeys. keysHeld can be used to determine if the button was down for two or more calls to scanKeys. |
|
This doesn't really explain the odd behavior I was asking about.
In the code I posted above changing KEY_X to KEY_A and removing the loop causes normal behavior. test = 0 until KEY_A is pressed. If I then change KEY_A to KEY_X or KEY_Y and leave the for loop commented out, test is immediately assigned the value 1. The code behaves similarly regardless if I use keysHeld() or keyDown().
#166050 - Maxxie - Sun Jan 18, 2009 10:06 pm
It does. Key_X/Y requires communication with the ARM7. Key_A can be read locally. I think that this internal difference gets to the surface at this point is a bug and should be solved in the lib.
Just live with it right now, and make sure everything is up and running before relying on it. The least ppl will notice a 2-vblank-delay at startup.
_________________
Trying to bring more detail into understanding the wireless hardware
#166086 - sverx - Mon Jan 26, 2009 10:49 am
elhobbs wrote: |
scanKeys must be called at least twice before keysHeld has a usable value. there is a thread on the subject... but I could not find it. |
Maybe is this one (reposting it because my post was lost in yesterday HD failure...)
btw I ended up using keys A & B instead of X & Y in my little example program. I didn't want to add other code and make things look more complicated, and I still believe it should be marked as bug. Ok, maybe not, but it shouldn't behave like that... :|
?
_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary
#166434 - paladine - Sun Feb 08, 2009 6:08 am
I'm having the same problem. Everything was working great, but then I upgraded to the latest devkitARM + libnds 1.3.1. Now my X/Y aren't recognizing as pressed, and neither is the touchscreen.
I'm thinking perhaps there's a problem with the lib.
#166436 - elhobbs - Sun Feb 08, 2009 6:26 am
make sure you did not call IrqInit in your code
#166438 - Emmanuel - Sun Feb 08, 2009 8:03 am
elhobbs wrote: |
make sure you did not call IrqInit in your code |
Why is that? I noticed it worked when I commented the IrqInit...
#166439 - Echo49 - Sun Feb 08, 2009 9:11 am
devkitpro.org wrote: |
Important Note: breaking changes.
Interrupt initialisation is now done before main including enabling the vblank interrupt. Since the functions to do this are common to most if not all homebrew apps we decided to simplify things rather than adding extra initialisation in user code for the FIFO based command system. Calling irqInit in main will currently break your code. |