Irda

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

Moderators: cheriff, TyRaNiD

Post Reply
Energy
Posts: 133
Joined: Sat Mar 26, 2005 4:13 pm
Location: uk/beds/flitwick
Contact:

Irda

Post by Energy »

Hey all -
I'm playing around with the IR port and seeing all the other demos that are flying about it looked pretty fun. I'm still slowly working my way through the PSP dev world.

Something that I thought would be fun and useful to make is an IRLearner. The idea is that you could place an IR remote infront of the psp it would be able to capture the information and then send out a duplicate of that information back out.

In theory, you could then expand it with profiles and other such stuff so that you'd be able to control multiple devices with the PSP, slap on a nice GUI and it'd be a simple yet handy app... anyway as this is my first attempt I'd like to ask a question:

This is my source so far (as you can see I've only been playing for an hour, and it's mainly a rip off of other code, like shines! thanks man! You've been so much help!):

Code: Select all

/*
 * PSP Software Development Kit - http://www.pspdev.org
 * -----------------------------------------------------------------------
 * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
 *
 * main.c - IrDA example
 *
 * Copyright &#40;c&#41; 2005 Frank Buss <[email protected]> &#40;aka Shine&#41;
 *
 * $Id$
 */
#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&#40;"IRDA Learner", 0, 1, 1&#41;;

/* Define the main thread's attribute value &#40;optional&#41; */
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER | THREAD_ATTR_VFPU&#41;;

/* Define printf, just to make typing easier */
#define printf	pspDebugScreenPrintf

/* Exit callback */
int exit_callback&#40;void&#41;
&#123;
	sceKernelExitGame&#40;&#41;;

	return 0;
&#125;

/* Callback thread */
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;

/* Sets up the callback thread and returns its thread id */
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;

int main&#40;void&#41;
&#123;
	char buffer&#91;10&#93;;
	unsigned char data;
	SceCtrlData pad;
	u32 buttonsold = 0;

	SetupCallbacks&#40;&#41;;
	pspDebugScreenInit&#40;&#41;;

	sceCtrlSetSamplingCycle&#40;0&#41;;
	sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_DIGITAL&#41;;

	printf &#40;"IrDA Learner Demo Energy\n"&#41;;
    printf &#40;"-------------------------------------------------\n"&#41;;
	printf &#40;"Get an IR device and press by the psp.\n\n"&#41;;
    printf &#40;"Once you got a data sent message press the start button\n"&#41;;
    printf &#40;"this should then repeat the command\n\n"&#41;;

	int fd = sceIoOpen&#40;"irda0&#58;", PSP_O_RDWR, 0&#41;;

	int q = 0;

	while &#40;q < 2&#41;
	&#123;
		// check for pad info from other PSP
		int len = sceIoRead&#40;fd, &data, 1&#41;;
		int otherPad = data << 8;
		if &#40;len == 1&#41;
		&#123;
			printf&#40;"Got Data&#58;"&#41;;
			printf&#40;"%c", data&#41;;
			printf&#40;"\n\n"&#41;;
			q = q + 1;
		&#125;

	sceDisplayWaitVblankStart&#40;&#41;;

	&#125;


	while&#40;1&#41;
	&#123;
		// read pad and send it
		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		if &#40;pad.Buttons & PSP_CTRL_START&#41;
		&#123;
			sceIoWrite&#40;fd, &data, 1&#41;;
			printf&#40;"Sent Data&#58;"&#41;;
			printf&#40;"%c", data&#41;;
			printf&#40;"\n\n"&#41;;
		&#125;

	sceDisplayWaitVblankStart&#40;&#41;;

	&#125;



	return 0;
&#125;
Now my question is this - at the moment I only recieve one byte at a time (I'm guessing), so in theory would I have to put each recieved byte (until len == 0) in to an array, and then when I press start would I have to send each byte that is sitting in the array back out?

Thanks for any help,
Energy
Energy
Posts: 133
Joined: Sat Mar 26, 2005 4:13 pm
Location: uk/beds/flitwick
Contact:

Post by Energy »

anyone any ideas?
if it doesn't make sence please just tell me, I won't be offended. Just means I got to work harder. I want to know if I'm on the right path... :)
User avatar
Agoln
Posts: 326
Joined: Wed Jun 08, 2005 3:14 am
Location: Fort Wayne, IN

Post by Agoln »

I'm not sure if it does this by default, but try making your controller and IRDA non-blocking.
Lego of my Ago!
Energy
Posts: 133
Joined: Sat Mar 26, 2005 4:13 pm
Location: uk/beds/flitwick
Contact:

Post by Energy »

Agoln wrote:I'm not sure if it does this by default, but try making your controller and IRDA non-blocking.
Do you mean that it's constantly capturing and sending the information back out? Sorry I'm thick. lol. I think I get what you mean...

My plan is to write all info the psp gets into an array, then when you press start it reads from the array and transmits.

I really need to learn more about hardware...
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Post by Arwin »

Energy wrote:
Agoln wrote:I'm not sure if it does this by default, but try making your controller and IRDA non-blocking.
Do you mean that it's constantly capturing and sending the information back out? Sorry I'm thick. lol. I think I get what you mean...

My plan is to write all info the psp gets into an array, then when you press start it reads from the array and transmits.

I really need to learn more about hardware...
I think that should work. From looking at the example in the svn, it really doesn't seem to be all that difficult:

http://svn.pspdev.org/filedetails.php?r ... rev=0&sc=0

Also there's an example in the forums somewhere that captures the incoming bytes to the IrDA and outputs them to the screen and to a file. So now you just need to write the code to send the file back out ... :D
Energy
Posts: 133
Joined: Sat Mar 26, 2005 4:13 pm
Location: uk/beds/flitwick
Contact:

Post by Energy »

Yeah I saw those examples. I suppose the most obvious thing to do is look to see if there are particular rules for IR transmitted data. I suppose setting the array at a size of 255 and just transmitting until a null value.

I suppose actually trying to use hardware worries me. lol
Oh well I'll give a go, I love playing with the PSP but I always feel that I'm going to send the wrong value to somewhere or something and I'm gonna make a brick lol.
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Post by Arwin »

Energy wrote:Yeah I saw those examples. I suppose the most obvious thing to do is look to see if there are particular rules for IR transmitted data. I suppose setting the array at a size of 255 and just transmitting until a null value.

I suppose actually trying to use hardware worries me. lol
Oh well I'll give a go, I love playing with the PSP but I always feel that I'm going to send the wrong value to somewhere or something and I'm gonna make a brick lol.
Well, it seems very unlikely you can do much harm with sending a few wrong IrDA values, especially in this context ;).
Energy
Posts: 133
Joined: Sat Mar 26, 2005 4:13 pm
Location: uk/beds/flitwick
Contact:

Post by Energy »

Ahh found out why my attempts are failing.
Found in the software forum apsd's thread shows that there are points in a remote control where there are delays and stuff like that. So when I get the data it's raw and sending out the raw data does nothing to the TV.

So for now I think it's a bit beyond me, but I'm going to keep looking at source code and see if I can work it out... :)
Post Reply