Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code for the following youtube video tutorial
https://www.youtube.com/watch?v=O68O7yUK_9c All credit to the original youtube author, I’m just providing a source for the code.
- Loading branch information
loldi
authored and
loldi
committed
Nov 29, 2015
0 parents
commit 2501566
Showing
1 changed file
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
// | ||
// ViewController.swift | ||
// Stumble | ||
// | ||
// Created by Andrew Genualdi on 11/22/15. | ||
// Copyright © 2015 Andrew Genualdi. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import MapKit | ||
import CoreLocation | ||
import CoreMotion | ||
|
||
class ViewController: UIViewController{ | ||
|
||
//Instance Variables | ||
|
||
var currentMaxAccelX: Double = 0.0 | ||
var currentMaxAccelY: Double = 0.0 | ||
var currentMaxAccelZ: Double = 0.0 | ||
|
||
var currentMaxRotX: Double = 0.0 | ||
var currentMaxRotY: Double = 0.0 | ||
var currentMaxRotZ: Double = 0.0 | ||
|
||
var movementManager = CMMotionManager() | ||
|
||
//Outlets | ||
|
||
@IBOutlet var accX: UILabel! | ||
@IBOutlet var accY: UILabel! | ||
@IBOutlet var accZ: UILabel! | ||
@IBOutlet var maxAccX: UILabel! | ||
@IBOutlet var maxAccY: UILabel! | ||
@IBOutlet var maxAccZ: UILabel! | ||
|
||
@IBOutlet var rotX: UILabel! | ||
@IBOutlet var rotY: UILabel! | ||
@IBOutlet var rotZ: UILabel! | ||
@IBOutlet var maxRotX: UILabel! | ||
@IBOutlet var maxRotY: UILabel! | ||
@IBOutlet var maxRotZ: UILabel! | ||
|
||
|
||
@IBAction func resetMaxValues(sender: AnyObject) { | ||
|
||
|
||
currentMaxAccelX = 0 | ||
currentMaxAccelY = 0 | ||
currentMaxAccelZ = 0 | ||
|
||
currentMaxRotX = 0 | ||
currentMaxRotY = 0 | ||
currentMaxRotZ = 0 | ||
} | ||
|
||
override func viewDidLoad() { | ||
|
||
currentMaxAccelX = 0 | ||
currentMaxAccelY = 0 | ||
currentMaxAccelZ = 0 | ||
|
||
currentMaxRotX = 0 | ||
currentMaxRotY = 0 | ||
currentMaxRotZ = 0 | ||
|
||
movementManager.gyroUpdateInterval = 0.2 | ||
movementManager.accelerometerUpdateInterval = 0.2 | ||
|
||
//Start Recording Data | ||
|
||
movementManager.startAccelerometerUpdatesToQueue(NSOperationQueue.currentQueue()!) { (accelerometerData: CMAccelerometerData?, NSError) -> Void in | ||
|
||
self.outputAccData(accelerometerData!.acceleration) | ||
if(NSError != nil) { | ||
print("\(NSError)") | ||
} | ||
} | ||
|
||
movementManager.startGyroUpdatesToQueue(NSOperationQueue.currentQueue()!, withHandler: { (gyroData: CMGyroData?, NSError) -> Void in | ||
self.outputRotData(gyroData!.rotationRate) | ||
if (NSError != nil){ | ||
print("\(NSError)") | ||
} | ||
|
||
|
||
}) | ||
|
||
|
||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
|
||
} | ||
|
||
func outputAccData(acceleration: CMAcceleration){ | ||
|
||
accX?.text = "\(acceleration.x).2fg" | ||
if fabs(acceleration.x) > fabs(currentMaxAccelX) | ||
{ | ||
currentMaxAccelX = acceleration.x | ||
} | ||
|
||
accY?.text = "\(acceleration.y).2fg" | ||
if fabs(acceleration.y) > fabs(currentMaxAccelY) | ||
{ | ||
currentMaxAccelY = acceleration.y | ||
} | ||
|
||
accZ?.text = "\(acceleration.z).2fg" | ||
if fabs(acceleration.z) > fabs(currentMaxAccelZ) | ||
{ | ||
currentMaxAccelZ = acceleration.z | ||
} | ||
|
||
|
||
maxAccX?.text = "\(currentMaxAccelX).2f" | ||
maxAccY?.text = "\(currentMaxAccelY).2f" | ||
maxAccZ?.text = "\(currentMaxAccelZ).2f" | ||
|
||
|
||
} | ||
|
||
func outputRotData(rotation: CMRotationRate){ | ||
|
||
|
||
rotX?.text = "\(rotation.x).2fr/s" | ||
if fabs(rotation.x) > fabs(currentMaxRotX) | ||
{ | ||
currentMaxRotX = rotation.x | ||
} | ||
|
||
rotY?.text = "\(rotation.y).2fr/s" | ||
if fabs(rotation.y) > fabs(currentMaxRotY) | ||
{ | ||
currentMaxRotY = rotation.y | ||
} | ||
|
||
rotZ?.text = "\(rotation.z).2fr/s" | ||
if fabs(rotation.z) > fabs(currentMaxRotZ) | ||
{ | ||
currentMaxRotZ = rotation.z | ||
} | ||
|
||
|
||
|
||
|
||
maxRotX?.text = "\(currentMaxRotX).2f" | ||
maxRotY?.text = "\(currentMaxRotY).2f" | ||
maxRotZ?.text = "\(currentMaxRotZ).2f" | ||
|
||
|
||
|
||
} | ||
|
||
} |
The following supports swift 3