diff --git a/RNMotionManager/Accelerometer.m b/RNMotionManager/Accelerometer.m index 89646fd..e2f4d77 100644 --- a/RNMotionManager/Accelerometer.m +++ b/RNMotionManager/Accelerometer.m @@ -15,91 +15,91 @@ @implementation Accelerometer RCT_EXPORT_MODULE(); - (id) init { - self = [super init]; - NSLog(@"Accelerometer"); - - if (self) { - self->_motionManager = [[CMMotionManager alloc] init]; - //Accelerometer - if([self->_motionManager isAccelerometerAvailable]) - { - NSLog(@"Accelerometer available"); - /* Start the accelerometer if it is not active already */ - if([self->_motionManager isAccelerometerActive] == NO) - { - NSLog(@"Accelerometer active"); - } else { - NSLog(@"Accelerometer not active"); - } - } - else - { - NSLog(@"Accelerometer not Available!"); + self = [super init]; + // NSLog(@"Accelerometer"); + + if (self) { + self->_motionManager = [[CMMotionManager alloc] init]; + //Accelerometer + if([self->_motionManager isAccelerometerAvailable]) + { + // NSLog(@"Accelerometer available"); + /* Start the accelerometer if it is not active already */ + if([self->_motionManager isAccelerometerActive] == NO) + { + // NSLog(@"Accelerometer active"); + } else { + // NSLog(@"Accelerometer not active"); + } + } + else + { + // NSLog(@"Accelerometer not Available!"); + } } - } - return self; + return self; } RCT_EXPORT_METHOD(setAccelerometerUpdateInterval:(double) interval) { - NSLog(@"setAccelerometerUpdateInterval: %f", interval); - - [self->_motionManager setAccelerometerUpdateInterval:interval]; + // NSLog(@"setAccelerometerUpdateInterval: %f", interval); + + [self->_motionManager setAccelerometerUpdateInterval:interval]; } RCT_EXPORT_METHOD(getAccelerometerUpdateInterval:(RCTResponseSenderBlock) cb) { - double interval = self->_motionManager.accelerometerUpdateInterval; - NSLog(@"getAccelerometerUpdateInterval: %f", interval); - cb(@[[NSNull null], [NSNumber numberWithDouble:interval]]); + double interval = self->_motionManager.accelerometerUpdateInterval; + // NSLog(@"getAccelerometerUpdateInterval: %f", interval); + cb(@[[NSNull null], [NSNumber numberWithDouble:interval]]); } RCT_EXPORT_METHOD(getAccelerometerData:(RCTResponseSenderBlock) cb) { - double x = self->_motionManager.accelerometerData.acceleration.x; - double y = self->_motionManager.accelerometerData.acceleration.y; - double z = self->_motionManager.accelerometerData.acceleration.z; - double timestamp = self->_motionManager.accelerometerData.timestamp; - - NSLog(@"getAccelerometerData: %f, %f, %f, %f", x, y, z, timestamp); - - cb(@[[NSNull null], @{ - @"acceleration": @{ - @"x" : [NSNumber numberWithDouble:x], - @"y" : [NSNumber numberWithDouble:y], - @"z" : [NSNumber numberWithDouble:z], - @"timestamp" : [NSNumber numberWithDouble:timestamp] - } - }] - ); + double x = self->_motionManager.accelerometerData.acceleration.x; + double y = self->_motionManager.accelerometerData.acceleration.y; + double z = self->_motionManager.accelerometerData.acceleration.z; + double timestamp = self->_motionManager.accelerometerData.timestamp; + + // NSLog(@"getAccelerometerData: %f, %f, %f, %f", x, y, z, timestamp); + + cb(@[[NSNull null], @{ + @"acceleration": @{ + @"x" : [NSNumber numberWithDouble:x], + @"y" : [NSNumber numberWithDouble:y], + @"z" : [NSNumber numberWithDouble:z], + @"timestamp" : [NSNumber numberWithDouble:timestamp] + } + }] + ); } RCT_EXPORT_METHOD(startAccelerometerUpdates) { - NSLog(@"startAccelerometerUpdates"); - [self->_motionManager startAccelerometerUpdates]; - - /* Receive the ccelerometer data on this block */ - [self->_motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue mainQueue] - withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) - { - double x = accelerometerData.acceleration.x; - double y = accelerometerData.acceleration.y; - double z = accelerometerData.acceleration.z; - double timestamp = accelerometerData.timestamp; - NSLog(@"startAccelerometerUpdates: %f, %f, %f, %f", x, y, z, timestamp); - - [self.bridge.eventDispatcher sendDeviceEventWithName:@"AccelerationData" body:@{ - @"acceleration": @{ - @"x" : [NSNumber numberWithDouble:x], - @"y" : [NSNumber numberWithDouble:y], - @"z" : [NSNumber numberWithDouble:z], - @"timestamp" : [NSNumber numberWithDouble:timestamp] - } - }]; - }]; - + // NSLog(@"startAccelerometerUpdates"); + [self->_motionManager startAccelerometerUpdates]; + + /* Receive the ccelerometer data on this block */ + [self->_motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue mainQueue] + withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) + { + double x = accelerometerData.acceleration.x; + double y = accelerometerData.acceleration.y; + double z = accelerometerData.acceleration.z; + double timestamp = accelerometerData.timestamp; + + [self.bridge.eventDispatcher sendDeviceEventWithName:@"AccelerationData" body:@{ + @"acceleration": @{ + @"x" : [NSNumber numberWithDouble:x], + @"y" : [NSNumber numberWithDouble:y], + @"z" : [NSNumber numberWithDouble:z], + @"timestamp" : [NSNumber numberWithDouble:timestamp] + } + }]; + }]; + } RCT_EXPORT_METHOD(stopAccelerometerUpdates) { - NSLog(@"stopAccelerometerUpdates"); - [self->_motionManager stopAccelerometerUpdates]; + // NSLog(@"stopAccelerometerUpdates"); + [self->_motionManager stopAccelerometerUpdates]; } @end + diff --git a/RNMotionManager/Gyroscope.m b/RNMotionManager/Gyroscope.m index 7d85505..909de0a 100644 --- a/RNMotionManager/Gyroscope.m +++ b/RNMotionManager/Gyroscope.m @@ -16,39 +16,39 @@ @implementation Gyroscope - (id) init { self = [super init]; - NSLog(@"Gyroscope"); - + //NSLog(@"Gyroscope"); + if (self) { self->_motionManager = [[CMMotionManager alloc] init]; //Gyroscope if([self->_motionManager isGyroAvailable]) { - NSLog(@"Gyroscope available"); + //NSLog(@"Gyroscope available"); /* Start the gyroscope if it is not active already */ if([self->_motionManager isGyroActive] == NO) { - NSLog(@"Gyroscope active"); + //NSLog(@"Gyroscope active"); } else { - NSLog(@"Gyroscope not active"); + //NSLog(@"Gyroscope not active"); } } else { - NSLog(@"Gyroscope not Available!"); + //NSLog(@"Gyroscope not Available!"); } } return self; } RCT_EXPORT_METHOD(setGyroUpdateInterval:(double) interval) { - NSLog(@"setGyroUpdateInterval: %f", interval); - + //NSLog(@"setGyroUpdateInterval: %f", interval); + [self->_motionManager setGyroUpdateInterval:interval]; } RCT_EXPORT_METHOD(getGyroUpdateInterval:(RCTResponseSenderBlock) cb) { double interval = self->_motionManager.gyroUpdateInterval; - NSLog(@"getGyroUpdateInterval: %f", interval); + //NSLog(@"getGyroUpdateInterval: %f", interval); cb(@[[NSNull null], [NSNumber numberWithDouble:interval]]); } @@ -57,9 +57,7 @@ - (id) init { double y = self->_motionManager.gyroData.rotationRate.y; double z = self->_motionManager.gyroData.rotationRate.z; double timestamp = self->_motionManager.gyroData.timestamp; - - NSLog(@"getGyroData: %f, %f, %f, %f", x, y, z, timestamp); - + cb(@[[NSNull null], @{ @"rotationRate": @{ @"x" : [NSNumber numberWithDouble:x], @@ -72,9 +70,9 @@ - (id) init { } RCT_EXPORT_METHOD(startGyroUpdates) { - NSLog(@"startGyroUpdates"); + //NSLog(@"startGyroUpdates"); [self->_motionManager startGyroUpdates]; - + /* Receive the gyroscope data on this block */ [self->_motionManager startGyroUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMGyroData *gyroData, NSError *error) @@ -83,8 +81,7 @@ - (id) init { double y = gyroData.rotationRate.y; double z = gyroData.rotationRate.z; double timestamp = gyroData.timestamp; - NSLog(@"startGyroUpdates: %f, %f, %f, %f", x, y, z, timestamp); - + [self.bridge.eventDispatcher sendDeviceEventWithName:@"GyroData" body:@{ @"rotationRate": @{ @"x" : [NSNumber numberWithDouble:x], @@ -94,12 +91,13 @@ - (id) init { } }]; }]; - + } RCT_EXPORT_METHOD(stopGyroUpdates) { - NSLog(@"stopGyroUpdates"); + //NSLog(@"stopGyroUpdates"); [self->_motionManager stopGyroUpdates]; } @end + diff --git a/RNMotionManager/Magnetometer.m b/RNMotionManager/Magnetometer.m index 69393f6..2dbf50b 100644 --- a/RNMotionManager/Magnetometer.m +++ b/RNMotionManager/Magnetometer.m @@ -15,91 +15,92 @@ @implementation Magnetometer RCT_EXPORT_MODULE(); - (id) init { - self = [super init]; - NSLog(@"Magnetometer"); - - if (self) { - self->_motionManager = [[CMMotionManager alloc] init]; - //Magnetometer - if([self->_motionManager isMagnetometerAvailable]) - { - NSLog(@"Magnetometer available"); - /* Start the Magnetometer if it is not active already */ - if([self->_motionManager isMagnetometerActive] == NO) - { - NSLog(@"Magnetometer active"); - } else { - NSLog(@"Magnetometer not active"); - } - } - else - { - NSLog(@"Magnetometer not Available!"); + self = [super init]; + //NSLog(@"Magnetometer"); + + if (self) { + self->_motionManager = [[CMMotionManager alloc] init]; + //Magnetometer + if([self->_motionManager isMagnetometerAvailable]) + { + //NSLog(@"Magnetometer available"); + /* Start the Magnetometer if it is not active already */ + if([self->_motionManager isMagnetometerActive] == NO) + { + //NSLog(@"Magnetometer active"); + } else { + //NSLog(@"Magnetometer not active"); + } + } + else + { + //NSLog(@"Magnetometer not Available!"); + } } - } - return self; + return self; } RCT_EXPORT_METHOD(setMagnetometerUpdateInterval:(double) interval) { - NSLog(@"setMagnetometerUpdateInterval: %f", interval); - - [self->_motionManager setMagnetometerUpdateInterval:interval]; + //NSLog(@"setMagnetometerUpdateInterval: %f", interval); + + [self->_motionManager setMagnetometerUpdateInterval:interval]; } RCT_EXPORT_METHOD(getMagnetometerUpdateInterval:(RCTResponseSenderBlock) cb) { - double interval = self->_motionManager.magnetometerUpdateInterval; - NSLog(@"getMagnetometerUpdateInterval: %f", interval); - cb(@[[NSNull null], [NSNumber numberWithDouble:interval]]); + double interval = self->_motionManager.magnetometerUpdateInterval; + //NSLog(@"getMagnetometerUpdateInterval: %f", interval); + cb(@[[NSNull null], [NSNumber numberWithDouble:interval]]); } RCT_EXPORT_METHOD(getMagnetometerData:(RCTResponseSenderBlock) cb) { - double x = self->_motionManager.magnetometerData.magneticField.x; - double y = self->_motionManager.magnetometerData.magneticField.y; - double z = self->_motionManager.magnetometerData.magneticField.z; - double timestamp = self->_motionManager.magnetometerData.timestamp; - - NSLog(@"getMagnetometerData: %f, %f, %f, %f", x, y, z, timestamp); - - cb(@[[NSNull null], @{ - @"magneticField": @{ - @"x" : [NSNumber numberWithDouble:x], - @"y" : [NSNumber numberWithDouble:y], - @"z" : [NSNumber numberWithDouble:z], - @"timestamp" : [NSNumber numberWithDouble:timestamp] - } - }] - ); + double x = self->_motionManager.magnetometerData.magneticField.x; + double y = self->_motionManager.magnetometerData.magneticField.y; + double z = self->_motionManager.magnetometerData.magneticField.z; + double timestamp = self->_motionManager.magnetometerData.timestamp; + + //NSLog(@"getMagnetometerData: %f, %f, %f, %f", x, y, z, timestamp); + + cb(@[[NSNull null], @{ + @"magneticField": @{ + @"x" : [NSNumber numberWithDouble:x], + @"y" : [NSNumber numberWithDouble:y], + @"z" : [NSNumber numberWithDouble:z], + @"timestamp" : [NSNumber numberWithDouble:timestamp] + } + }] + ); } RCT_EXPORT_METHOD(startMagnetometerUpdates) { - NSLog(@"startMagnetometerUpdates"); - [self->_motionManager startMagnetometerUpdates]; - - /* Receive the ccelerometer data on this block */ - [self->_motionManager startMagnetometerUpdatesToQueue:[NSOperationQueue mainQueue] - withHandler:^(CMMagnetometerData *magnetometerData, NSError *error) - { - double x = magnetometerData.magneticField.x; - double y = magnetometerData.magneticField.y; - double z = magnetometerData.magneticField.z; - double timestamp = magnetometerData.timestamp; - NSLog(@"startMagnetometerUpdates: %f, %f, %f, %f", x, y, z, timestamp); - - [self.bridge.eventDispatcher sendDeviceEventWithName:@"MagnetometerData" body:@{ - @"magneticField": @{ - @"x" : [NSNumber numberWithDouble:x], - @"y" : [NSNumber numberWithDouble:y], - @"z" : [NSNumber numberWithDouble:z], - @"timestamp" : [NSNumber numberWithDouble:timestamp] - } - }]; - }]; - + //NSLog(@"startMagnetometerUpdates"); + [self->_motionManager startMagnetometerUpdates]; + + /* Receive the ccelerometer data on this block */ + [self->_motionManager startMagnetometerUpdatesToQueue:[NSOperationQueue mainQueue] + withHandler:^(CMMagnetometerData *magnetometerData, NSError *error) + { + double x = magnetometerData.magneticField.x; + double y = magnetometerData.magneticField.y; + double z = magnetometerData.magneticField.z; + double timestamp = magnetometerData.timestamp; + //NSLog(@"startMagnetometerUpdates: %f, %f, %f, %f", x, y, z, timestamp); + + [self.bridge.eventDispatcher sendDeviceEventWithName:@"MagnetometerData" body:@{ + @"magneticField": @{ + @"x" : [NSNumber numberWithDouble:x], + @"y" : [NSNumber numberWithDouble:y], + @"z" : [NSNumber numberWithDouble:z], + @"timestamp" : [NSNumber numberWithDouble:timestamp] + } + }]; + }]; + } RCT_EXPORT_METHOD(stopMagnetometerUpdates) { - NSLog(@"stopMagnetometerUpdates"); - [self->_motionManager stopMagnetometerUpdates]; + //NSLog(@"stopMagnetometerUpdates"); + [self->_motionManager stopMagnetometerUpdates]; } @end +