Permalink
Browse files

added core motion example

  • Loading branch information...
1 parent f8d7600 commit d1865b3289a3210a657589d4682b92e866d70e37 @mattneub committed Feb 11, 2012
@@ -0,0 +1,285 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 46;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ A4A16B6E14E5B65C00360956 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A4A16B6D14E5B65C00360956 /* UIKit.framework */; };
+ A4A16B7014E5B65C00360956 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A4A16B6F14E5B65C00360956 /* Foundation.framework */; };
+ A4A16B7214E5B65C00360956 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A4A16B7114E5B65C00360956 /* CoreGraphics.framework */; };
+ A4A16B7814E5B65C00360956 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = A4A16B7614E5B65C00360956 /* InfoPlist.strings */; };
+ A4A16B7A14E5B65C00360956 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = A4A16B7914E5B65C00360956 /* main.m */; };
+ A4A16B7E14E5B65C00360956 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = A4A16B7D14E5B65C00360956 /* AppDelegate.m */; };
+ A4A16B8114E5B65C00360956 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A4A16B8014E5B65C00360956 /* ViewController.m */; };
+ A4A16B8414E5B65C00360956 /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A4A16B8214E5B65C00360956 /* ViewController.xib */; };
+ A4A16B8F14E5B92000360956 /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A4A16B8E14E5B92000360956 /* CoreMotion.framework */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+ A4A16B6914E5B65C00360956 /* p726gyro.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = p726gyro.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ A4A16B6D14E5B65C00360956 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
+ A4A16B6F14E5B65C00360956 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+ A4A16B7114E5B65C00360956 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
+ A4A16B7514E5B65C00360956 /* p726gyro-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "p726gyro-Info.plist"; sourceTree = "<group>"; };
+ A4A16B7714E5B65C00360956 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+ A4A16B7914E5B65C00360956 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ A4A16B7B14E5B65C00360956 /* p726gyro-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "p726gyro-Prefix.pch"; sourceTree = "<group>"; };
+ A4A16B7C14E5B65C00360956 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
+ A4A16B7D14E5B65C00360956 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
+ A4A16B7F14E5B65C00360956 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
+ A4A16B8014E5B65C00360956 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
+ A4A16B8314E5B65C00360956 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController.xib; sourceTree = "<group>"; };
+ A4A16B8E14E5B92000360956 /* CoreMotion.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMotion.framework; path = System/Library/Frameworks/CoreMotion.framework; sourceTree = SDKROOT; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ A4A16B6614E5B65C00360956 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ A4A16B8F14E5B92000360956 /* CoreMotion.framework in Frameworks */,
+ A4A16B6E14E5B65C00360956 /* UIKit.framework in Frameworks */,
+ A4A16B7014E5B65C00360956 /* Foundation.framework in Frameworks */,
+ A4A16B7214E5B65C00360956 /* CoreGraphics.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ A4A16B5E14E5B65C00360956 = {
+ isa = PBXGroup;
+ children = (
+ A4A16B8E14E5B92000360956 /* CoreMotion.framework */,
+ A4A16B7314E5B65C00360956 /* p726gyro */,
+ A4A16B6C14E5B65C00360956 /* Frameworks */,
+ A4A16B6A14E5B65C00360956 /* Products */,
+ );
+ sourceTree = "<group>";
+ };
+ A4A16B6A14E5B65C00360956 /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ A4A16B6914E5B65C00360956 /* p726gyro.app */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ A4A16B6C14E5B65C00360956 /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ A4A16B6D14E5B65C00360956 /* UIKit.framework */,
+ A4A16B6F14E5B65C00360956 /* Foundation.framework */,
+ A4A16B7114E5B65C00360956 /* CoreGraphics.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
+ A4A16B7314E5B65C00360956 /* p726gyro */ = {
+ isa = PBXGroup;
+ children = (
+ A4A16B7C14E5B65C00360956 /* AppDelegate.h */,
+ A4A16B7D14E5B65C00360956 /* AppDelegate.m */,
+ A4A16B7F14E5B65C00360956 /* ViewController.h */,
+ A4A16B8014E5B65C00360956 /* ViewController.m */,
+ A4A16B8214E5B65C00360956 /* ViewController.xib */,
+ A4A16B7414E5B65C00360956 /* Supporting Files */,
+ );
+ path = p726gyro;
+ sourceTree = "<group>";
+ };
+ A4A16B7414E5B65C00360956 /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ A4A16B7514E5B65C00360956 /* p726gyro-Info.plist */,
+ A4A16B7614E5B65C00360956 /* InfoPlist.strings */,
+ A4A16B7914E5B65C00360956 /* main.m */,
+ A4A16B7B14E5B65C00360956 /* p726gyro-Prefix.pch */,
+ );
+ name = "Supporting Files";
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ A4A16B6814E5B65C00360956 /* p726gyro */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = A4A16B8714E5B65C00360956 /* Build configuration list for PBXNativeTarget "p726gyro" */;
+ buildPhases = (
+ A4A16B6514E5B65C00360956 /* Sources */,
+ A4A16B6614E5B65C00360956 /* Frameworks */,
+ A4A16B6714E5B65C00360956 /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = p726gyro;
+ productName = p726gyro;
+ productReference = A4A16B6914E5B65C00360956 /* p726gyro.app */;
+ productType = "com.apple.product-type.application";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ A4A16B6014E5B65C00360956 /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0420;
+ };
+ buildConfigurationList = A4A16B6314E5B65C00360956 /* Build configuration list for PBXProject "p726gyro" */;
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ );
+ mainGroup = A4A16B5E14E5B65C00360956;
+ productRefGroup = A4A16B6A14E5B65C00360956 /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ A4A16B6814E5B65C00360956 /* p726gyro */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ A4A16B6714E5B65C00360956 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ A4A16B7814E5B65C00360956 /* InfoPlist.strings in Resources */,
+ A4A16B8414E5B65C00360956 /* ViewController.xib in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ A4A16B6514E5B65C00360956 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ A4A16B7A14E5B65C00360956 /* main.m in Sources */,
+ A4A16B7E14E5B65C00360956 /* AppDelegate.m in Sources */,
+ A4A16B8114E5B65C00360956 /* ViewController.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+ A4A16B7614E5B65C00360956 /* InfoPlist.strings */ = {
+ isa = PBXVariantGroup;
+ children = (
+ A4A16B7714E5B65C00360956 /* en */,
+ );
+ name = InfoPlist.strings;
+ sourceTree = "<group>";
+ };
+ A4A16B8214E5B65C00360956 /* ViewController.xib */ = {
+ isa = PBXVariantGroup;
+ children = (
+ A4A16B8314E5B65C00360956 /* en */,
+ );
+ name = ViewController.xib;
+ sourceTree = "<group>";
+ };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+ A4A16B8514E5B65C00360956 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ CLANG_ENABLE_OBJC_ARC = YES;
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ COPY_PHASE_STRIP = NO;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 5.0;
+ SDKROOT = iphoneos;
+ };
+ name = Debug;
+ };
+ A4A16B8614E5B65C00360956 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ CLANG_ENABLE_OBJC_ARC = YES;
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ COPY_PHASE_STRIP = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 5.0;
+ OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
+ SDKROOT = iphoneos;
+ VALIDATE_PRODUCT = YES;
+ };
+ name = Release;
+ };
+ A4A16B8814E5B65C00360956 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "p726gyro/p726gyro-Prefix.pch";
+ INFOPLIST_FILE = "p726gyro/p726gyro-Info.plist";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ WRAPPER_EXTENSION = app;
+ };
+ name = Debug;
+ };
+ A4A16B8914E5B65C00360956 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "p726gyro/p726gyro-Prefix.pch";
+ INFOPLIST_FILE = "p726gyro/p726gyro-Info.plist";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ WRAPPER_EXTENSION = app;
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ A4A16B6314E5B65C00360956 /* Build configuration list for PBXProject "p726gyro" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ A4A16B8514E5B65C00360956 /* Debug */,
+ A4A16B8614E5B65C00360956 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ A4A16B8714E5B65C00360956 /* Build configuration list for PBXNativeTarget "p726gyro" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ A4A16B8814E5B65C00360956 /* Debug */,
+ A4A16B8914E5B65C00360956 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = A4A16B6014E5B65C00360956 /* Project object */;
+}
@@ -0,0 +1,12 @@
+
+#import <UIKit/UIKit.h>
+
+@class ViewController;
+
+@interface AppDelegate : UIResponder <UIApplicationDelegate>
+
+@property (strong, nonatomic) UIWindow *window;
+
+@property (strong, nonatomic) ViewController *viewController;
+
+@end
@@ -0,0 +1,23 @@
+
+
+#import "AppDelegate.h"
+
+#import "ViewController.h"
+
+@implementation AppDelegate
+
+@synthesize window = _window;
+@synthesize viewController = _viewController;
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ // Override point for customization after application launch.
+ self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
+ self.window.rootViewController = self.viewController;
+ [self.window makeKeyAndVisible];
+ return YES;
+}
+
+
+@end
@@ -0,0 +1,7 @@
+
+
+#import <UIKit/UIKit.h>
+
+@interface ViewController : UIViewController
+
+@end
@@ -0,0 +1,54 @@
+
+
+#import "ViewController.h"
+#import <CoreMotion/CoreMotion.h>
+
+@interface ViewController ()
+@property (nonatomic, strong) CMMotionManager* motman;
+@property (nonatomic, strong) NSTimer* timer;
+@end
+
+
+@implementation ViewController
+@synthesize motman, timer;
+
+- (IBAction)doButton:(id)sender {
+ self.motman = [CMMotionManager new];
+ if (!motman.deviceMotionAvailable) {
+ NSLog(@"oh well");
+ return;
+ }
+ CMAttitudeReferenceFrame f = CMAttitudeReferenceFrameXMagneticNorthZVertical;
+ if (([CMMotionManager availableAttitudeReferenceFrames] & f) == 0) {
+ NSLog(@"darn");
+ return;
+ }
+ self.motman.showsDeviceMovementDisplay = YES;
+ self.motman.deviceMotionUpdateInterval = 1.0 / 30.0;
+ [self.motman startDeviceMotionUpdatesUsingReferenceFrame:f];
+ NSTimeInterval t = self.motman.accelerometerUpdateInterval * 10;
+ self.timer = [NSTimer scheduledTimerWithTimeInterval:t target:self selector:@selector(pollAttitude:) userInfo:nil repeats:YES];
+}
+
+- (void) viewWillDisappear:(BOOL)animated {
+ [super viewWillDisappear:animated];
+ [self.timer invalidate];
+ self.timer = nil;
+ [self.motman stopDeviceMotionUpdates];
+}
+
+- (void) pollAttitude: (id) dummy {
+ CMDeviceMotion* mot = self.motman.deviceMotion;
+ if (mot.magneticField.accuracy <= CMMagneticFieldCalibrationAccuracyLow)
+ return; // not ready yet
+ CMAttitude* att = mot.attitude;
+ CGFloat to_deg = 180.0 / M_PI;
+ NSLog(@"%f %f %f", att.pitch * to_deg, att.roll * to_deg, att.yaw * to_deg);
+ CMAcceleration g = mot.gravity;
+ NSLog(@"pitch is tilted %@", g.z > 0 ? @"forward" : @"back");
+}
+
+
+
+
+@end
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+
Oops, something went wrong.

0 comments on commit d1865b3

Please sign in to comment.