Sha256: 8854c05942ad88256d30cba90dd02858e437d7c2cd3543f23abaacdd2a9d45bd
Contents?: true
Size: 1.77 KB
Versions: 17
Compression:
Stored size: 1.77 KB
Contents
#import "SensorFactory.h" #import "Sensor.h" #import "SensorSingleton.h" #import <CoreMotion/CoreMotion.h> static BOOL ourIsAccelerometerAvailability = NO; static BOOL ourIsMagnetometerAvailability = NO; @interface SensorAvailabilityProcessor: NSObject { } -(void) initAvailabilityCommand; -(void) initAvailability; @end @implementation SensorAvailabilityProcessor -(void) initAvailabilityCommand { CMMotionManager* motionManager = [[CMMotionManager alloc] init]; ourIsAccelerometerAvailability = motionManager.accelerometerAvailable; ourIsMagnetometerAvailability = motionManager.deviceMotionAvailable && ([CMMotionManager availableAttitudeReferenceFrames] & CMAttitudeReferenceFrameXArbitraryCorrectedZVertical); [motionManager release]; } -(void) initAvailability { [self performSelectorOnMainThread:@selector(initAvailabilityCommand) withObject:nil waitUntilDone:YES]; } @end @implementation SensorFactory -(id<ISensor>)createSensorByID:(NSString*)ID { Sensor* obj = nil; if ([SENSOR_TYPE_ACCELEROMETER isEqualToString:ID] && [SensorFactory isAccelerometerSupported]) { obj = [[AccelerometerSensor alloc] init]; } else if ([SENSOR_TYPE_MAGNETOMETER isEqualToString:ID] && [SensorFactory isMagnetometerSupported]) { obj = [[MagnetometerSensor alloc] init]; } else { //obj = [[Sensor alloc] init]; } if (obj != nil) { [obj setProperty:@"ID" propertyValue:ID methodResult:nil]; } return obj; } +(void) initAvailability { SensorAvailabilityProcessor* proc = [[SensorAvailabilityProcessor alloc] init]; [proc initAvailability]; } +(BOOL) isAccelerometerSupported { return ourIsAccelerometerAvailability; } +(BOOL) isMagnetometerSupported { return ourIsMagnetometerAvailability; } @end
Version data entries
17 entries across 17 versions & 2 rubygems