Help, I'm a newbie

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Zanith
Posts: 1
Joined: Sun Feb 04, 2007 7:17 am

Help, I'm a newbie

Post by Zanith »

Hi, I'm new, notice the '1' post count, well I'm also new to PSP developing (after finally downgrading my PSP). Well I'm interested in Ir applications, and decided to forgo and make one, I thought somthing simple, somthing which will send back the data received after a short timespace.
Well it sounded easy, but its not working. Can anybody see anything obviously wrong with it....

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 printf	pspDebugScreenPrintf

PSP_MODULE_INFO&#40;"IrDA Relay", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER | THREAD_ATTR_VFPU&#41;;

void delay_loop&#40;int num&#41; &#123;
	if &#40;num <= 0&#41; return;
	for &#40;; num > 0; num--&#41;
		sceDisplayWaitVblankStart&#40;&#41;;
&#125;

int exit_callback&#40;void&#41;
&#123;
	sceKernelExitGame&#40;&#41;;
	return 0;
&#125;

void CallbackThread&#40;void *arg&#41;
&#123;
	int cbid;

	cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
	sceKernelRegisterExitCallback&#40;cbid&#41;;

	sceKernelSleepThreadCB&#40;&#41;;
&#125;

int SetupCallbacks&#40;void&#41;
&#123;
	int thid = 0;

	thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
	if&#40;thid >= 0&#41;
	&#123;
		sceKernelStartThread&#40;thid, 0, 0&#41;;
	&#125;

	return thid;
&#125;

/*
*Main Function
*/

int main&#40;int argc, char *argv&#91;&#93;&#41; &#123;
	SceCtrlData pad;
	SetupCallbacks&#40;&#41;;
	pspDebugScreenInit&#40;&#41;;
	sceCtrlSetSamplingCycle&#40;0&#41;;
	sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_DIGITAL&#41;;
	
	printf&#40;"IrDA Relay\n-Will send the same signal back\n--several seconds after recieving it.\n\n"&#41;;
	
	int fd = sceIoOpen&#40;"irda0&#58;", PSP_O_RDWR, 0&#41;;
 	
	if &#40;fd < 0&#41; &#123;
		printf&#40;"ERROR&#58; Could not open irda device!\n"&#41;;
		printf&#40;"Press any button to exit...\n"&#41;;
		while &#40;pad.Buttons == 0&#41; &#123;
			delay_loop&#40;2&#41;;
			sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		&#125;
		return -1;
	&#125;
	
	while &#40;1&#41; &#123;
	    unsigned char data;
	    data = sceIoRead&#40;fd, &data, 32&#41;;

		if &#40;data <= 32&#41; &#123;
		        delay_loop&#40;50&#41;;
		        sceIoWrite&#40;fd, &data, 32&#41;;
		        printf&#40;"%c", data&#41;;
 		&#125;    
        sceDisplayWaitVblankStart&#40;&#41;;
     &#125;
    sceIoClose&#40;fd&#41;;
	return 0;
&#125;
Post Reply