Hi all,
sorry for the topic, but couldn't find anything better.
Here's what I need: a procedure that is being constantly called every certain amount of time (I don't care about how often, provided I can count on it being every frame-start, or 60 times a second... I think it should be enough).
I guess this may be done with a separate thread in my application (all I need to do is read the keys and/or analog pad, and store the last-read data in some variables to access them later)
I am very new to using threads (or whatever is necessary to achieve this task); can any of you please shed some light?
Thank you all in advance,
A.
threads
That's pretty much what sceCtrlReadBuffer() does. It reads the keys and then reschedules your thread to run at the next vblank.
so just
does what you want.
Jim
so just
Code: Select all
do{
sceCtrlReadBuffer(...);
//i get here once per vblank
...
} while (!exit_program);
Jim
nope... ehm, what I catually want is something like a function that gets called "automatically", without me to include "check-the-keys();" in my main loop... sorry, to that i can get ;-)Jim wrote:That's pretty much what sceCtrlReadBuffer() does. It reads the keys and then reschedules your thread to run at the next vblank.
so justdoes what you want.Code: Select all
do{ sceCtrlReadBuffer(...); //i get here once per vblank ... } while (!exit_program);
Jim
Like a callback on button-presses or on analog-nub movement, or a sort of callback called every framestart.
Actually, I was reading through the toolchain source, and found sceRegisterButtonCallback (and if there was something for the analog nub too would be great...) but cannot get to compile, as it doesn't find a reference to sce_Kernel_{hex numbers here}...
Cheers, A.
of course you can ask; just because I would like to implement something like a keys (and not only) bufferJim wrote:Can I ask why you want that? It doesn't seem all that useful.
yeah, that was just a thought.Jim wrote:The callback for the analog joystick sounds like a bad requirement - how far should the nub move before you get a callback, for instance.
What about an interrupt handler? I've been looking at "pspintrman.h" but I cannot succeed in hooking anything: either returns negative - error - codes in USER mode, or it freezes at startup in KERNEL mode.
Can you be of any help about?
Thanks,
A.
-
- Posts: 18
- Joined: Thu Aug 13, 2009 11:42 pm
You could write your own callback mechanism using a thread that checks the keys and on changes calls another function (your callback function).
Something like this (I guess this also answers how to create a thread):
Something like this (I guess this also answers how to create a thread):
Code: Select all
void inputThread(SceSize args, void *argp)
{
unsigned int lastButtons = 0;
sceCtrlData currentCtrlData;
while (1)
{
sceCtrlPeekButterPositive(¤tCtrlData, 1);
if ((currentCtrlData.buttons && PSP_CTRL_CROSS) && !(lastButtons && PSP_CTRL_CROSS))
{
myButtonCallback(PSP_CTRL_CROSS, KEY_DOWN);
}
else if .... etc.
lastButtons = currentCtrlData.buttons;
sceKernelDelayThread(10000); // 10 ms
}
}
int main()
{
SceUID inputThreadId = sceKernelCreateThread("inputThread", (SceKernelThreadEntry)inputThread, 0x18, 0x10000, PSP_THREAD_ATTR_USER, 0);
sceKernelStartThread(inputThreadId, 0, 0);
while (1)
{
// whatever
}
}
yes, indeed that is what I was finally worging on, today... seems the only possibility.unsigned int wrote:You could write your own callback mechanism using a thread that checks the keys and on changes calls another function (your callback function).
Anyway, as I see I cannot have two threads working at the same time, that I need to sceKernelDelayThread() both of them.
But in the while(1) loop of the main in your example, I don't see any delay for the main application thread; have you just forgotten it or is there actually a way to have things run in parallel, and I don't find it?
unsigned int wrote:Code: Select all
int main() { SceUID inputThreadId = sceKernelCreateThread("inputThread", (SceKernelThreadEntry)inputThread, 0x18, 0x10000, PSP_THREAD_ATTR_USER, 0); sceKernelStartThread(inputThreadId, 0, 0); while (1) { // whatever } }
-
- Posts: 18
- Joined: Thu Aug 13, 2009 11:42 pm