xboxscene.org forums

Author Topic: (linux) Using The Ir Remote To Control Vlc  (Read 804 times)

Icekiller2k6

  • Archived User
  • Full Member
  • *
  • Posts: 150
(linux) Using The Ir Remote To Control Vlc
« on: June 05, 2008, 10:32:00 AM »

Seeing as nobody did anything with my proof of concept code...

I made it myself..

You are now able to use the IR remote to control VLC, totem etc.. well anything really.

As long as it's the main window (selected window).
CODE

/*
* Example code of how to use the build in IR of the xbox 360
* Code rewritten based on tmbinc's smc.c
* free to use under GPL
*
* Last modified: 5 June 2008 by Roeland Kindt (IceKiller, capital K!;p) & Frederik Van Bogaert (Cyberfreek @ IRC)
*/
#include
#include
#include
#include
#include
#include
#include

#define SMC_FILENAME "/dev/smc"
#define NUM_WAIT 1 //change this to higher if you want the response time to go down
#define RESPONSE_TIME 0.1 // this is ignored by default


int smc_fd;
int cntwait=0;

/* function to kill the app if it doesnt respond */
void terminate (int param)
{
  printf ("IR receiving program has been disabled...\n");
  exit(1);
}

/* function to wait before retrieving IR code NOT USED BY DEFAULT*/
void wait ( double seconds )
{

  unsigned char msgtmp[16];
  clock_t endwait;
  endwait = clock () + seconds * CLOCKS_PER_SEC;

  while (clock() < endwait);
/* we need to read the device twice so we can clean the memory of previous instructions */
  read(smc_fd, msgtmp, 16);
  read(smc_fd, msgtmp, 16);

}

/* main function... duh */
int main(int argc, char **argv)
{
  int i;
  unsigned char msg[16];
  int option_index = 0, c;
  int first = 1;
  int valueread;
/* this code is in case you cant pkill it.. the bastard*/
  void (*prev_fn)(int);

  prev_fn = signal (SIGINT,terminate);
  if (prev_fn==SIG_IGN) signal (SIGINT,SIG_IGN);

/* end own pkill pwnage code */

    /* try open SMC. if this doesn't work, bail out. */
  smc_fd = open(SMC_FILENAME, O_RDONLY);
  if (smc_fd < 0)
  {
    perror(SMC_FILENAME);
    return 1;
  }

  while (1)
  {
    msg[0] = 0x00;
    read(smc_fd, msg, 16);
    read(smc_fd, msg, 16);
   /* prepare message */
    memset(msg, 0, 16);


    
    if (msg[0] < 0x80)
    {
     while (1)
      {
    msg[0] = 0x00;
    if(cntwait==0){    
            if (read(smc_fd, msg, 16) != 16)
              perror("read");
    }else{
        cntwait--;
        read(smc_fd, msg, 16);
        msg[0] = 0x00;
    }
    
    valueread=msg[3];

        if(msg[0]!=0x00){
        cntwait=NUM_WAIT;
        
        
        switch(valueread){
        case 0x26:
            //printf("Button Y");
        break;
        case 0x25:
            //printf("Button B");
        break;
        case 0x24:
            //printf("DVD menu");
        break;
        case 0x23:
            //printf("Back");
            system("xte \"key BackSpace\"");
        break;
        case 0x22:
            //printf("OK");
            system("xte \"key Return\"");
        break;
        case 0x21:
            //printf("Button Right");
            system("xte \"key Right\"");
        break;
        case 0x20:
            //printf("Button Left");
            system("xte \"key Left\"");
        break;
        case 0x19:
            //printf("Stop button");
            system("xte \"key s\"");
        break;
        case 0x18:
            //printf("Pause button");
            system("xte \"key space\"");
        break;
        case 0x17:
            //printf("Rec button");
        break;
        case 0x16:
            //printf(">");
            system("xte \"key space\"");
        break;
        case 0x15:
            //printf("<<");
            system("xte \"key Left\"");
        break;
        case 0x14:
            //printf(">>");
            system("xte \"key Right\"");
        break;
        case 0x13:
            //printf("Button X");
        break;
        case 0x12:
            //printf("Button A");
        break;
        case 0x11:
            //printf("Volume down");
            system("xte \"keydown \"Control_R\"\"");
            system("xte \"key Down\"");
            system("xte \"keyup \"Control_R\"\"");

        break;
        case 0x10:
            //printf("Volume up");
            system("xte \"keydown \"Control_R\"\"");
            system("xte \"key Up\"");
            system("xte \"keyup \"Control_R\"\"");
        break;
        case 0x09:
            //printf("Button 9");
            system("xte \"key 9\"");
        break;
        case 0x08:
            //printf("Button 8");
            system("xte \"key 8\"");
        break;
        case 0x07:
            //printf("Button 7");
            system("xte \"key 7\"");
        break;
        case 0x06:
            //printf("Button 6");
            system("xte \"key 6\"");
        break;
        case 0x05:
            //printf("Button 5");
            system("xte \"key 5\"");
        break;
        case 0x04:
            //printf("Button 4");
            system("xte \"key 4\"");
        break;
        case 0x03:
            //printf("Button 3");
            system("xte \"key 3\"");
        break;
        case 0x02:
            //printf("Button 2");
            system("xte \"key 2\"");
        break;
        case 0x01:
            //printf("Button 1");
            system("xte \"key 1\"");
        break;
        case 0x00:
            //printf("Button 0");
            system("xte \"key 0\"");
        break;
        case 0x1a:
            //printf(">|");
        break;
        case 0x1b:
            //printf("<");
        break;
        case 0x1c:
            //printf("Undo");
            system("xte \"keydown \"Control_R\"\"");
            system("xte \"key q\"");
            system("xte \"keyup \"Control_R\"\"");
        break;
        case 0x1d:
            //printf("100 on remote");
        break;
        case 0x1e:
            //printf("Button up");
            system("xte \"key Up\"");
        break;
        case 0x1f:
            //printf("Button down");
            system("xte \"key Down\"");
        break;
        case 0x0a:
            //printf("Clear");
            read(smc_fd, msg, 32);
            exit(0);
        break;
        case 0x0b:
            //printf("ENTER");
        break;
        case 0x0c:
            //printf("Unknown 2");
        break;
        case 0x0d:
            //printf("WMS");
        break;
        case 0x0e:
            //printf("Mute");
            system("xte \"key m\"");
        break;
        case 0x0f:
            //printf("Info");
        break;
        case 0x4f:
            //printf("Display");
            system("xte \"key f\"");
        break;
        case 0x51:
            //printf("Title");
        break;
        case 0x64:
            //printf("Guide");
        break;
        case 0x68:
            //printf("Button X");
        break;
        case 0x66:
            //printf("Button A");
        break;
        }
}
        /* wait function is just if you really really want to slow it down.
      only use it if the NUM_WAIT isnt doing it for you.
    */
    //wait(RESPONSE_TIME);
      }
    }

  }

}



extra info on:
http://www.free60.or...ki/Media_Remote

Feel free to edit and use it and whatever.. just don't steal it and pretend you made it.


The point of this code is to make it possible to integrate it in a 'mediacenter' software if any is ever dev'ed..
Logged