add missing bridge templates

This commit is contained in:
Mathieu Virbel 2014-11-24 02:56:09 +01:00
parent 2f8d7c0c26
commit eb12e12491
2 changed files with 85 additions and 0 deletions

21
tools/templates/bridge.h Normal file
View file

@ -0,0 +1,21 @@
#import <Foundation/Foundation.h>
#import <CoreMotion/CoreMotion.h>
@interface bridge : NSObject {
NSOperationQueue *queue;
}
@property (strong, nonatomic) CMMotionManager *motionManager;
@property (nonatomic) double ac_x;
@property (nonatomic) double ac_y;
@property (nonatomic) double ac_z;
@property (nonatomic) double gy_x;
@property (nonatomic) double gy_y;
@property (nonatomic) double gy_z;
@property (nonatomic) double mg_x;
@property (nonatomic) double mg_y;
@property (nonatomic) double mg_z;
@end

64
tools/templates/bridge.m Normal file
View file

@ -0,0 +1,64 @@
#import "bridge.h"
@implementation bridge
- (id) init {
if(self = [super init]) {
self.motionManager = [[CMMotionManager alloc] init];
queue = [[NSOperationQueue alloc] init];
}
return self;
}
- (void)startAccelerometer {
if ([self.motionManager isAccelerometerAvailable] == YES) {
[self.motionManager startAccelerometerUpdatesToQueue:queue withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
self.ac_x = accelerometerData.acceleration.x;
self.ac_y = accelerometerData.acceleration.y;
self.ac_z = accelerometerData.acceleration.z;
}];
}
}
- (void)startGyroscope {
if ([self.motionManager isGyroAvailable] == YES) {
[self.motionManager startGyroUpdatesToQueue:queue withHandler:^(CMGyroData *gyroData, NSError *error) {
self.gy_x = gyroData.rotationRate.x;
self.gy_y = gyroData.rotationRate.y;
self.gy_z = gyroData.rotationRate.z;
}];
}
}
- (void)startMagnetometer {
if (self.motionManager.magnetometerAvailable) {
[self.motionManager startMagnetometerUpdatesToQueue:queue withHandler:^(CMMagnetometerData *magnetometerData, NSError *error) {
self.mg_x = magnetometerData.magneticField.x;
self.mg_y = magnetometerData.magneticField.y;
self.mg_z = magnetometerData.magneticField.z;
}];
}
}
- (void) stopAccelerometer {
[self.motionManager stopAccelerometerUpdates];
}
- (void) stopGyroscope {
[self.motionManager stopGyroUpdates];
}
- (void) stopMagnetometer {
[self.motionManager stopMagnetometerUpdates];
}
- (void) dealloc {
[self.motionManager release];
[queue release];
[super dealloc];
}
@end