The ModMyTM Family of Sites:
ModMyMotoModMyiModMyGphone




 
 
Register or Connect with Facebook

Discuss AppStore Apps | Browse / Search Cydia | MMi Cydia Stats




  Apple Forums & iPhone Forums, Mods, Hacks, News, Themes, Downloads, and more! | ModMyi.com > 3rd Party Apps For iPhone | iPod Touch > Native iPhone / iPod Touch App Discussion
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 08-28-2007, 11:23 PM
Green Apple
 
Join Date: Jul 2007
Posts: 74
Thanks: 1
Thanked 5 Times in 5 Posts
News - iPhone accelerometer source code released

The iPhone has a built-in LIS302DL, a tiny 3-axis accelerometer and someone has figured out how to take advantage of this natively. For more information and to see a youtube video of some native apps taking advantage of this go here:

http://blog.medallia.com/

For developers interested in the source look below. This is all thanks to Erling Ellingsen from medallia blog. Link posted above.

Code:

#include
#include


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(s ys, 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);
}
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #2  
Old 08-28-2007, 11:53 PM
iPhone? More like MyPhone
 
Join Date: Jul 2007
Device + Firmware: iPhone 3GS 32GB White
Operating System: Win XP, MAC OS X
Posts: 141
Thanks: 14
Thanked 7 Times in 7 Posts
Send a message via AIM to bluaeon Send a message via Yahoo to bluaeon

so what kind of program can we use?
where is this file located at?
i want some kind of source code on how to create your own using this hack... ie... motion sensor alarm when you lay it down and it goes off when its moved... something like that
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #3  
Old 08-29-2007, 12:08 AM
What's Jailbreak?
 
Join Date: Jul 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

anyone got the .apps for those accelerometer apps he was playing on it?
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #4  
Old 04-24-2008, 03:05 PM
What's Jailbreak?
 
Join Date: Mar 2008
Device + Firmware: 3.0 iPhone 2G
Operating System: Windows XP
Location: California
Posts: 24
Thanks: 4
Thanked 3 Times in 2 Posts
Send a message via AIM to mikeyman70

so if i add that code to a program on my phone already
say, SMS, would it make the program rotate with the phone?

or is that a completely different code?
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #5  
Old 04-24-2008, 03:08 PM
drunknbass's Avatar
the kanye west of programming
 
Join Date: Jul 2007
Posts: 382
Thanks: 0
Thanked 47 Times in 38 Posts

um, that was almost a year old?
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #6  
Old 04-24-2008, 04:15 PM
Green Apple
 
Join Date: Nov 2007
Device + Firmware: Iphone. 1.1.4. Jailbroken. Unlocked.
Posts: 84
Thanks: 11
Thanked 2 Times in 2 Posts

Quote:
Originally Posted by mikeyman70 View Post
so if i add that code to a program on my phone already
say, SMS, would it make the program rotate with the phone?

or is that a completely different code?
Not going to happen.
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
Reply

  Apple Forums & iPhone Forums, Mods, Hacks, News, Themes, Downloads, and more! | ModMyi.com > 3rd Party Apps For iPhone | iPod Touch > Native iPhone / iPod Touch App Discussion

Thread Tools
Display Modes

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 On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



Go to Top
ModMyI

All times are GMT -6. The time now is 01:50 PM. Powered by vBulletin® Version 3.8.4
If you need Dedicated Server Hosting, you should check out SingleHop. | Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.0 Copyright © 2007-09 by ModMy, LLC. All rights reserved.

iPhone News / iPhone Forums / Apple News / Apple Forums / RSS / Contact Us / / Top