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

Version Path
rhodes-7.6.0 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m
rhodes-7.5.1 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m
rhodes-7.4.1 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m
rhodes-7.1.17 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m
rhodes-6.2.0 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m
rhodes-6.0.11 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m
rhodes-5.5.18 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m
rhodes-5.5.17 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m
rhodes-5.5.15 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m
rhodes-5.5.0.22 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m
rhodes-5.5.2 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m
rhodes-5.5.0.7 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m
rhodes-5.5.0.3 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m
rhodes-5.5.0 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m
tauplatform-1.0.3 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m
tauplatform-1.0.2 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m
tauplatform-1.0.1 lib/commonAPI/sensor/ext/platform/iphone/impl/SensorFactory.m