I was writing/learning with a controller homebrew to use with some WinAPI stuff. That turned out to be really fun and useful. Here starts my problem:
I have used SceCtrlData objects and sceCtrlReadBufferPositive() to get key presses.
Everything was going great untill i felt the need to use key releases events. I know i could have just used sceCtrlReadBufferNegative(), but another solution seemed more easy and usefull, since it gets just ONE key press, which is what I'm looking for. So in one of the topics here, someone suggested using SceCtrlLatch and sceCtrlReadLatch(), which is great. Everything worked out. Its all working. Only problem is: PSP freezes on program exit.
Here the main loop from main.c:
Code: Select all
while(1)
{
if((button = get_button(&ispressed)))
{
if(button == PSP_CTRL_SELECT)
{
//Do some stuff
}
else
{
//----> This also works
printf("\nPressed = %d\n", ispressed);
//-----> Send info to socket on server - Its working
//A dumb try to avoid freezing
sleep(2000);
}
}
}
Code: Select all
int get_button(int *ispressed)
{
SceCtrlLatch latch;
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);
while(1)
{
//Read Pad
sceCtrlReadLatch(&latch);
if(latch.uiMake)
{
//Means a button was pressed
*ispressed = 1;
if(latch.uiMake & PSP_CTRL_CROSS) return PSP_CTRL_CROSS;
else if(latch.uiMake & PSP_CTRL_CIRCLE) return PSP_CTRL_CIRCLE;
else if(latch.uiMake & PSP_CTRL_SQUARE) return PSP_CTRL_SQUARE;
else if(latch.uiMake & PSP_CTRL_TRIANGLE) return PSP_CTRL_TRIANGLE;
else if(latch.uiMake & PSP_CTRL_START) return PSP_CTRL_START;
else if(latch.uiMake & PSP_CTRL_SELECT) return PSP_CTRL_SELECT;
else if(latch.uiMake & PSP_CTRL_LTRIGGER) return PSP_CTRL_LTRIGGER;
else if(latch.uiMake & PSP_CTRL_RTRIGGER) return PSP_CTRL_RTRIGGER;
else if(latch.uiMake & PSP_CTRL_UP) return PSP_CTRL_UP;
else if(latch.uiMake & PSP_CTRL_DOWN) return PSP_CTRL_DOWN;
else if(latch.uiMake & PSP_CTRL_LEFT) return PSP_CTRL_LEFT;
else if(latch.uiMake & PSP_CTRL_RIGHT) return PSP_CTRL_RIGHT;
//And if a useless button was pressed, return 0
else return 0;
}
else if(latch.uiBreak)
{
//Means a button was relesead
*ispressed = 0;
if(latch.uiBreak & PSP_CTRL_CROSS) return PSP_CTRL_CROSS;
else if(latch.uiBreak & PSP_CTRL_CIRCLE) return PSP_CTRL_CIRCLE;
else if(latch.uiBreak & PSP_CTRL_SQUARE) return PSP_CTRL_SQUARE;
else if(latch.uiBreak & PSP_CTRL_TRIANGLE) return PSP_CTRL_TRIANGLE;
else if(latch.uiBreak & PSP_CTRL_START) return PSP_CTRL_START;
else if(latch.uiBreak & PSP_CTRL_SELECT) return PSP_CTRL_SELECT;
else if(latch.uiBreak & PSP_CTRL_LTRIGGER) return PSP_CTRL_LTRIGGER;
else if(latch.uiBreak & PSP_CTRL_RTRIGGER) return PSP_CTRL_RTRIGGER;
else if(latch.uiBreak & PSP_CTRL_UP) return PSP_CTRL_UP;
else if(latch.uiBreak & PSP_CTRL_DOWN) return PSP_CTRL_DOWN;
else if(latch.uiBreak & PSP_CTRL_LEFT) return PSP_CTRL_LEFT;
else if(latch.uiBreak & PSP_CTRL_RIGHT) return PSP_CTRL_RIGHT;
//And if a useless button was released, return 0
else return 0;
}
}
}
Sorry for my bad English and thanks in advance. Also, others suggestions are encouraged. Thanks!