forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Irda

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Mon Jul 18, 2005 5:12 am    Post subject: Irda Reply with quote

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:

/*
 * 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 (c) 2005 Frank Buss <fb@frank-buss.de> (aka Shine)
 *
 * $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("IRDA Learner", 0, 1, 1);

/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);

/* 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 main(void)
{
   char buffer[10];
   unsigned char data;
   SceCtrlData pad;
   u32 buttonsold = 0;

   SetupCallbacks();
   pspDebugScreenInit();

   sceCtrlSetSamplingCycle(0);
   sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);

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

   int fd = sceIoOpen("irda0:", PSP_O_RDWR, 0);

   int q = 0;

   while (q < 2)
   {
      // check for pad info from other PSP
      int len = sceIoRead(fd, &data, 1);
      int otherPad = data << 8;
      if (len == 1)
      {
         printf("Got Data:");
         printf("%c", data);
         printf("\n\n");
         q = q + 1;
      }

   sceDisplayWaitVblankStart();

   }


   while(1)
   {
      // read pad and send it
      sceCtrlReadBufferPositive(&pad, 1);
      if (pad.Buttons & PSP_CTRL_START)
      {
         sceIoWrite(fd, &data, 1);
         printf("Sent Data:");
         printf("%c", data);
         printf("\n\n");
      }

   sceDisplayWaitVblankStart();

   }



   return 0;
}


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
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Wed Jul 20, 2005 12:24 am    Post subject: Reply with quote

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... :)
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Agoln



Joined: 08 Jun 2005
Posts: 326
Location: Fort Wayne, IN

PostPosted: Wed Jul 20, 2005 12:35 am    Post subject: Reply with quote

I'm not sure if it does this by default, but try making your controller and IRDA non-blocking.
_________________
Lego of my Ago!
Back to top
View user's profile Send private message AIM Address
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Wed Jul 20, 2005 12:43 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Arwin



Joined: 12 Jul 2005
Posts: 426

PostPosted: Wed Jul 20, 2005 12:56 am    Post subject: Reply with quote

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?repname=psp&path=%2Ftrunk%2Fpspsdk%2Fsdk%2Fsamples%2Fir%2Firda%2Fmain.c&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
Back to top
View user's profile Send private message
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Wed Jul 20, 2005 1:09 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Arwin



Joined: 12 Jul 2005
Posts: 426

PostPosted: Wed Jul 20, 2005 1:21 am    Post subject: Reply with quote

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 ;).
Back to top
View user's profile Send private message
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Thu Jul 21, 2005 12:49 am    Post subject: Reply with quote

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... :)
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group