I've edited the piKey Sample so it works and runs in the 3.XX kernel. I've also added a callback.
The anoying thing, is that it freezes on the "Please Wait..." screen after home is pressed.
What could be wrong? I think maybe IRDA is still active and the PSP doesn't like it, but yet a callback has been added which should stop that.
Here's the code:
Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <stdlib.h>
#include <string.h>
#include <pikeylib.h>
#include "../sdk/pikeytypes.h"
/* Define the module info section */
PSP_MODULE_INFO("PIKEYTEST", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
PSP_MAIN_THREAD_STACK_SIZE_KB(64);
/* Define printf, just to make typing easier */
#define printf pspDebugScreenPrintf
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int done = 0;
int blink = 0;
int main(void)
{
pspDebugScreenInit();
SetupCallbacks();
int ii;
printf("piKey Sample.\n");
initPikey();
sceKernelDelayThread(1000000);
printf("piKey is detected as %s\n", isPikeyLoaded() ? "running." : "not running.");
requestExclusive();
setMode(PIKEY_KEYMODE_KEYPRESS);
sceKernelDelayThread(1000000);
pspDebugScreenClear();
pspDebugScreenSetXY(0, 5);
printf("Waiting for keys, press ESC to exit...\n\n");
while(!done)
{
sceKernelDelayThread(1000); // don't tight-loop
sceDisplayWaitVblank();
blink += 1;
// clear old display
if(blink > 5){
pspDebugScreenClear();
blink = 0;
}
pspDebugScreenSetXY(0, 5);
printf("Waiting for keys, press 'Home' to exit...\n\n");
#if 0
pspDebugScreenSetXY(0,7);
for (ii = 7; ii < 20; ii++)
{
printf(" \n");
}
#endif
// nothing to do if no keys pressed.
if (numKeysPressed() == 0)
{
continue;
}
pspDebugScreenSetXY(0,7);
for (ii = 0; ii < KEY_MAX; ii++)
{
if (isKeyPressed(ii))
{
printf("Pressed scancode: %d\n", ii);
}
}
int ctrl, alt, shift;
getMetaKeys(&alt, &ctrl, &shift);
pspDebugScreenSetXY(0, 20);
printf(" %s %s %s\n",
ctrl? "CTRL" : " ",
alt? "ALT" : " ",
shift? "SHIFT" : " ");
}
sceKernelSleepThread();
return 0;
}