Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspsircs.h>
#include <stdlib.h>
#include <string.h>
/* Define the module info section */
PSP_MODULE_INFO("IRDA Learner", 0, 1, 1);
/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
unsigned char my_cmd[37];
int a=1;
/* Define printf, just to make typing easier */
#define printf pspDebugScreenPrintf
/* Exit callback */
int exit_callback(void)
{
sceKernelExitGame();
return 0;
}
/* Callback thread */
void CallbackThread(void *arg)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
}
/* 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 irda_capture(int irdafd, int filefd) {
SceCtrlData pad;
unsigned char data;
int len;
printf("Press the START button to stop.\n");
while (1) {
/* Read a byte */
len = sceIoRead(irdafd, &data, 1);
if (len != 0) {
/* Print it out and put it in the file */
printf("%c", data);
len = sceIoWrite(filefd, &data, 1);
}
/* Check for the start button */
}
return 0;
}
int main(void)
{
char buffer[10];
unsigned char data;
SceCtrlData pad;
u32 buttonsold = 0;
SetupCallbacks();
pspDebugScreenInit();
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);
printf ("Wait for data...\n");
int irdafd = sceIoOpen("irda0:", PSP_O_RDWR, 0);
int filefd = sceIoOpen("irda0:", PSP_O_RDWR, 0);
while(a==1)
{
// read pad and send it
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons & PSP_CTRL_START)
irda_capture(irdafd, filefd);
}
sceIoClose(irdafd);
sceIoClose(filefd);
sceDisplayWaitVblankStart();
return 0;
}