?? iphone.txt
字號:
#import "SampleApp.h"
#include <time.h>
#include <math.h>
@implementation SampleApp
- (void)acceleratedInX:(float)xx Y:(float)yy Z:(float)zz
{
// Create Status feedback string
NSString *xstring = [NSString stringWithFormat:
@"X (roll, %4.1f%%): %f\nY (pitch %4.1f%%): %f\nZ (%4.1f%%) : %f",
100.0 - (xx + 0.5) * 100.0, xx,
100.0 - (yy + 0.5) * 100.0, yy,
100.0 - (zz + 0.5) * 100.0, zz];
[textView setText:xstring];
// Revert Arrow and then rotate to new coords
[xarrow setTransform:CGAffineTransformIdentity];
float angle = atan2(yy, xx);
angle *= 180.0/3.14159;
[xarrow setRotationBy:angle];
}
- (void) applicationDidFinishLaunching: (id) unused
{
struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
rect.origin.x = rect.origin.y = 0.0f;
window = [[UIWindow alloc] initWithContentRect: rect];
mainView = [[UIView alloc] initWithFrame: rect];
textView = [[UITextView alloc] initWithFrame:
CGRectMake(0.0, 0.0, 320.0, 480.0)];
[textView setEditable:NO];
[textView setTextSize:24];
[mainView addSubview: textView];
xarrow = [[UIImageView alloc] initWithFrame:
CGRectMake(50.0, 320.0, 200.0, 50.0)];
UIImage *img = [[UIImage imageAtPath:
[[NSBundle mainBundle]
pathForResource:@"arrow"
ofType:@"png"
inDirectory:@"/"]] retain];
[xarrow setImage:img];
[textView addSubview:xarrow];
[window orderFront: self];
[window makeKey: self];
[window _setHidden: NO];
[window setContentView: mainView];
}
@end
2、http://blog.medallia.com/2007/08/iphone_accelerometer_source_co.html
Here's some code to initialize the accelerometer to run at full speed. Pass the desired sample rate (in Hz) to the initialize function. Go wild!
#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);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -