Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)saveImageToPhotoAlbum
- {
- UIImageWriteToSavedPhotosAlbum(self.takenPic, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
- }
- - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
- {
- if (error != NULL) {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"Image couldn't be saved" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
- [alert show];
- }
- else {
- NSLog(@"Saving");
- timerRunning = NO;
- // savingCompassHeading = YES;
- // checkingCompassHeading = NO;
- savingGyroOrientation = YES;
- checkingGyroOrientation = NO;
- self.timerLabel.hidden = YES;
- self.orientationOkay.hidden = YES;
- self.centerCircle.hidden = NO;
- self.savingLabel.hidden = NO;
- self.deviceStatus = [NSUserDefaults standardUserDefaults];
- CMDeviceMotion *currDeviceMotion = self.motionManager.deviceMotion;
- CMQuaternion cmQuat = currDeviceMotion.attitude.quaternion;
- Quaternion *tempQuat = [[Quaternion alloc] init];
- tempQuat = [Quaternion quaternionWithRe:cmQuat.w i:cmQuat.x j:cmQuat.y k:cmQuat.z];
- //conjugate and normalize
- self.invertedQuat = [tempQuat inverse];
- NSLog(@"Reference alpha is %f", acos(self.invertedQuat.Re));
- self.startTimerButton.hidden = NO;
- }
- }
- -(IBAction)startTimerAction:(id)sender{
- self.startTimerButton.hidden = YES;
- self.timerLabel.hidden = NO;
- self.startDate = [NSDate date];
- timerRunning = YES;
- self.clickTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/60.0 target:self selector:@selector(updateTimer:) userInfo:nil repeats:YES];
- }
- -(void)updateTimer:(NSTimer *)timer{
- // Create date from the elapsed time
- NSDate *currentDate = [NSDate date];
- NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:self.startDate];
- NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
- // Create a date formatter
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"HH:mm:ss.SSS"];
- [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
- // Format the elapsed time and set it to the label
- NSString *timeString = [dateFormatter stringFromDate:timerDate];
- self.timerLabel.text = timeString;
- CMDeviceMotion *currDeviceMotion = self.motionManager.deviceMotion;
- NSLog(@"Reference Alpha is %f",acos(self.invertedQuat.Re));
- CMQuaternion newQuat = currDeviceMotion.attitude.quaternion;
- self.currentQuat = [Quaternion quaternionWithRe:newQuat.w i:newQuat.x j:newQuat.y k:newQuat.z];
- NSLog(@"Current alpha is %f", acos(self.currentQuat.Re));
- Quaternion *delta = [[Quaternion alloc] init];
- delta = [self.invertedQuat multiply:self.currentQuat];
- float alpha = acos(delta.Re)*2.0f;
- float xdiff = asin(delta.i);
- float ydiff = asin(delta.j);
- float zdiff = asin(delta.k);
- NSLog(@"Delta Alpha is %f",alpha);
- if (fabs (alpha) < 0.50) {
- NSLog(@"Matching angle");
- }
- if (xdiff < 0.07 && xdiff > -0.07) {
- NSLog(@"xdiff in range");
- }
- if (ydiff < 0.07 && ydiff > -0.07) {
- NSLog(@"ydiff in range");
- }
- if (zdiff < 0.07 && zdiff > -0.07) {
- NSLog(@"zdiff in range");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement