+ Reply
Results 1 to 3 of 3

Your favorite Apple, iPhone, iPad, iOS, Jailbreak, and Cydia site.


Thread: Accelerometer Code released

is a discussion within the

3rd Party Apps Requests

forums, a part of the

3rd Party Apps For iPhone | iPod Touch

section;
Code: #include <IOKit/IOKitLib.h> #include <CoreFoundation/CoreFoundation.h> typedef struct {} *IOHIDEventSystemRef; typedef struct {} *IOHIDEventRef; float IOHIDEventGetFloatValue(IOHIDEventRef ref, int param); void handleHIDEvent(int a, int b, int c, IOHIDEventRef ptr) { int type
...
  1. #1
    Owner / Founder - ModMyi
    aka cash7c3
    Cody Overcash's Avatar
    Join Date
    May 2007
    Location
    Denver, CO
    Posts
    11,893
    Thanks
    340
    Thanked 15,271 Times in 652 Posts

    Default Accelerometer Code released
    Code:
    #include <IOKit/IOKitLib.h>
    #include <CoreFoundation/CoreFoundation.h>
    
    
    
    typedef struct {} *IOHIDEventSystemRef;
    
    typedef struct {} *IOHIDEventRef;
    
    float IOHIDEventGetFloatValue(IOHIDEventRef ref, int param);
    
    
    void handleHIDEvent(int a, int b, int c, IOHIDEventRef ptr) {
    
      int type = IOHIDEventGetType(ptr);
    
      if (type == 12) {
    
        float x,y,z;
    
        x = IOHIDEventGetFloatValue(ptr, 0xc0000);
    
        y = IOHIDEventGetFloatValue(ptr, 0xc0001);
    
        z = IOHIDEventGetFloatValue(ptr, 0xc0002);
    
        // do whatever you need to do with the gravity
    
        ballSetAccel(x, y);
    
      }
    
    
    }
    
    	  
    
    #define expect(x) if(!x) { printf("failed: %s\n", #x);  return; }
    
    
    void initialize(int hz) {
    
      mach_port_t master;
    
      expect(0 == IOMasterPort(MACH_PORT_NULL, &master));
    
    
      int page = 0xff00, usage = 3;
    
    
      CFNumberRef nums[2];
    
      CFStringRef keys[2];
    
      keys[0] = CFStringCreateWithCString(0, "PrimaryUsagePage", 0);
    
      keys[1] = CFStringCreateWithCString(0, "PrimaryUsage", 0);
    
      nums[0] = CFNumberCreate(0, kCFNumberSInt32Type, &page);
    
      nums[1] = CFNumberCreate(0, kCFNumberSInt32Type, &usage);
    
      CFDictionaryRef dict = CFDictionaryCreate(0, (const void**)keys, (const void**)nums, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    
      expect(dict);
    
    
      IOHIDEventSystemRef sys = (IOHIDEventSystemRef) IOHIDEventSystemCreate(0);
    
      expect(sys);
    
    
      CFArrayRef srvs = (CFArrayRef)IOHIDEventSystemCopyMatchingServices(sys, dict, 0, 0, 0);
    
      expect(CFArrayGetCount(srvs)==1);
    
    
      io_registry_entry_t serv = (io_registry_entry_t)CFArrayGetValueAtIndex(srvs, 0);
    
      expect(serv);
    
    
      CFStringRef cs = CFStringCreateWithCString(0, "ReportInterval", 0);
    
      int rv = 1000000/hz;
    
      CFNumberRef cn = CFNumberCreate(0, kCFNumberSInt32Type, &rv);
    
    
      int res = IOHIDServiceSetProperty(serv, cs, cn);
    
      expect(res == 1);
    
    
      res = IOHIDEventSystemOpen(sys, handleHIDEvent, 0, 0);
    
      expect(res == 0);
    
    }


    Source:
    http://blog.medallia.com/2007/08/iph...source_co.html

  2. #2
    iPhone? More like MyPhone
    Join Date
    Aug 2007
    Location
    Iphone, Iphone.
    Posts
    225
    Thanks
    1
    Thanked 7 Times in 5 Posts

    old news

  3. #3
    iPhone? More like MyPhone
    Join Date
    Aug 2007
    Posts
    127
    Thanks
    2
    Thanked 6 Times in 6 Posts

    yes kinda old news, but the only application out there, really doesnt run well... if anybody can take this code, and make the maze that the guy made.. think of the possibilities, the games, the applications.. with the flick of the wrist, you can scroll through something... .. plz keep bumpin this to the top
    http://blog.medallia.com/2007/08/fun...ccelerome.html
    oh yeah and its accelerometer.. not accelerator but yeah bump baby bump...


    EDIT:
    Ok so nobody ever really posted back, but hey its being recognized.. i was on the channel earlier when sadun was finishing up here sensors and butterfly game.. and woot there on installer already..
    Last edited by kriffer; 09-09-2007 at 09:08 PM.

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