LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-19-2007, 02:37 PM   #1
kristof_v
Member
 
Registered: Feb 2006
Location: Belgium
Distribution: Debian
Posts: 84

Rep: Reputation: 15
C: compile error


Hi, I grabbed this code from http://wiki.debian.org/MacBook#head-...433b04704a07f1 to test the remote control of my macbook in Debian.

Code:
/*BINFMTC:  -lusb -L /usr/X11R6/lib -lXt -lXtst

references:
http://www.madingley.org/macmini/kernel/ir.patch
http://www.gniibe.org/software/hub-ctrl.c

Copyright (c) 2006 Junichi Uekawa.

 */

#include <stdio.h>
#include <stdlib.h>
#include <usb.h>
#include <errno.h>
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>

#define USB_VENDOR_ID_APPLE   0x05ac
#define USB_DEVICE_ID_APPLE_IR  0x8240
#define USB_ENDPOINT  0x83

/*
MacBook

key pressed: 25 87 ee 44 2  menu
key pressed: 25 87 ee 44 4  >||
key pressed: 25 87 ee 44 7  >>
key pressed: 25 87 ee 44 8  <<
key pressed: 25 87 ee 44 b  +
key pressed: 25 87 ee 44 d  -
key pressed: 26 0 0 0 0  repeat
key pressed: 25 87 e0 44 6  ???

4th byte looks random.

 */

int keymap[8]={
  0,            /* reserved */
  97,            /* home */
  105,             /* next */
  105,            /* pgdn */
  99,             /* pgup */
  99,            /* pgup */
  105            /* pgdn */
};

void process_device(usb_dev_handle* uh)
{
  const int timeout=1000;   /* msec */
  const int size=32;
  char buf[size+1];
  int n;
  Display *display=XOpenDisplay(NULL);

  if(!display)
    {
      fprintf(stderr, "Cannot open display\n");
      return;
    }


  usb_detach_kernel_driver_np(uh,0);
 
  printf("claim: %p, %i\n", uh, (usb_claim_interface(uh,0)));
 
  while (1)
    {
      if((n=usb_interrupt_read(uh, USB_ENDPOINT, buf, size, timeout))>0)
   {
     int i;   
     printf("key pressed: ");
     for (i=0; i<n; ++i)
       printf("%x ", (int)(unsigned char)buf[i]);
     printf("\n");
     if ((buf[0]==(char)0x25)&&
         (buf[1]==(char)0x87)&&
         (buf[2]==(char)0xee))
       //(buf[3]==44) 4th byte is probably random.
       {
         printf("ack: \n");
         XTestFakeKeyEvent(display,
            keymap[buf[4]%16 >> 1],
            1,
            0);
         XSync(display, 0);
         sched_yield();
        
         XTestFakeKeyEvent(display,
            keymap[buf[4]%16 >> 1],
            0,
            0);
         XSync(display, 0);
         sched_yield();
       }
   }
      //printf("n=%i\n", n);
    }
  usb_close(uh);
}

int main(int ac, char** av)
{
  struct usb_bus* bus;
  struct usb_device* dev;
 
  usb_init ();
  usb_find_busses ();
  usb_find_devices ();

  for(bus=usb_get_busses(); bus; bus=bus->next)
    {
      for(dev=bus->devices; dev; dev=dev->next)
   {
     if((dev->descriptor.idVendor == USB_VENDOR_ID_APPLE) &&
        (dev->descriptor.idProduct == USB_DEVICE_ID_APPLE_IR))
       {
         printf("bus %s, dev %i\n",
           bus->dirname,
           dev->devnum);
         process_device(usb_open(dev));
       }
    
   }
    }
  return 0;
}
however when I try to compile it with gcc macbook-ir.c, it gives the following errors:

Code:
gcc macbook-ir.c
macbook-ir.c:48: error: expected ‘)’ before ‘*’ token
macbook-ir.c: In function ‘main’:
macbook-ir.c:111: warning: assignment makes pointer from integer without a cast
macbook-ir.c:111: error: dereferencing pointer to incomplete type
macbook-ir.c:113: error: dereferencing pointer to incomplete type
macbook-ir.c:113: error: dereferencing pointer to incomplete type
macbook-ir.c:115: error: dereferencing pointer to incomplete type
macbook-ir.c:116: error: dereferencing pointer to incomplete type
macbook-ir.c:119: error: dereferencing pointer to incomplete type
macbook-ir.c:120: error: dereferencing pointer to incomplete type
any ideas???

grtz
 
Old 04-19-2007, 03:29 PM   #2
kernel_geek
Member
 
Registered: Jan 2007
Location: UK
Distribution: Ubuntu/Arch
Posts: 161

Rep: Reputation: 30
Your missing a bracket somewhere
 
Old 04-19-2007, 03:37 PM   #3
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
My C is rusty, but would this not require the struct keyword?
Code:
void process_device(usb_dev_handle* uh)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile madwifi, ... compile error , how can i do. ERBRMN Linux - Networking 3 03-08-2006 07:56 PM
Compile error B0mb Mandriva 3 11-26-2004 08:21 AM
compile error with 2.6.5 jamaas Linux - Newbie 6 04-17-2004 01:11 AM
compile error: #error unknown processor family kmack2001 Linux - Newbie 0 02-14-2004 11:52 AM
Alsa compile error, and a WINE error scheidel21 Linux - Software 1 12-08-2003 08:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration