Manos Chorianopoulos

telematics registerSensor fix

......@@ -7,7 +7,7 @@
<key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
</dict>
</dict>
......
......@@ -7,7 +7,7 @@
<key>SwiftWarplyFramework.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
</dict>
</dict>
......
......@@ -14,6 +14,8 @@ import CoreMotion
// MARK: Constants and Properties
private var mIsTripStarted = false
private var hasLocationPermissions = false
private var isFirstLoad = true
private var mAccelerationTimestamps = [[String: Any]]()
private var locationManager: CLLocationManager!
private var motionManager: CMMotionManager!
......@@ -68,6 +70,8 @@ import CoreMotion
accelerationLimitTextField.delegate = self
sampleTimeTextField.delegate = self
hasLocationPermissions = authorizationStatusIsGranted(status: CLLocationManager.authorizationStatus())
orientationCountLabel.text = "0"
touchCountLabel.text = "0"
recordsSavedLabel.text = "0"
......@@ -99,7 +103,7 @@ import CoreMotion
public override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if (self.mIsTripStarted == true) {
self.stopTrip()
}
......@@ -234,7 +238,7 @@ import CoreMotion
}
private func processAccelerometerData(_ accelerationData: CMAccelerometerData) {
// print("=== accelerationData: ",accelerationData)
// print("=== accelerationData: ",accelerationData)
// sensorDataLabel.text = "\(accelerationData.acceleration.x), \(accelerationData.acceleration.y), \(accelerationData.acceleration.z)"
......@@ -260,7 +264,7 @@ import CoreMotion
// TODO: CHECK mayby this is correct
// accelerationLabel.text = String(format: "%.1f m/s^2", acceleration)
// print("=== acceleration: ",acceleration)
// print("=== acceleration: ",acceleration)
// If acceleration is below the stop threshold, assume we are in a stop
// if acceleration < STOP_THRESHOLD {
......@@ -270,7 +274,7 @@ import CoreMotion
velocity = acceleration * time
// }
// print("=== velocity: ",velocity)
// print("=== velocity: ",velocity)
// Convert velocity to km/h
mAcceleration = velocity // Convert to km/h
......@@ -400,7 +404,7 @@ import CoreMotion
self?.mAccelerationTimestamps.append(jsonObject)
// print("=== self?.mAccelerationTimestamps: ", self?.mAccelerationTimestamps)
// print("=== self?.mAccelerationTimestamps: ", self?.mAccelerationTimestamps)
}
}
timerTel!.resume()
......@@ -449,9 +453,14 @@ import CoreMotion
}
func onAuthorizationStatusIsGranted() {
// print("=== onAuthorizationStatusIsGranted === ")
// print("=== onAuthorizationStatusIsGranted === ")
locationManager.startUpdatingLocation();
registerSensor()
// registerSensor()
if (!isFirstLoad || (isFirstLoad && !hasLocationPermissions)) {
registerSensor()
}
hasLocationPermissions = true
isFirstLoad = false
}
func onAuthorizationStatusIsDenied() {
......@@ -459,7 +468,7 @@ import CoreMotion
}
public func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
// print("=== locationManager didChangeAuthorization: ",status)
// print("=== locationManager didChangeAuthorization: ",status)
if (authorizationStatusIsDenied(status: status)) {
onAuthorizationStatusIsDenied();
......@@ -471,8 +480,8 @@ import CoreMotion
public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.last {
// print("=== locationManager didUpdateLocations latitude: ",location.coordinate.latitude)
// print("=== locationManager didUpdateLocations longitude: ",location.coordinate.longitude)
// print("=== locationManager didUpdateLocations latitude: ",location.coordinate.latitude)
// print("=== locationManager didUpdateLocations longitude: ",location.coordinate.longitude)
if mLatitude != 0 && mLongitude != 0 {
mSpeed = calculateSpeed(lat1: mLatitude, lon1: mLongitude, lat2: location.coordinate.latitude, lon2: location.coordinate.longitude, timeDifferenceInSeconds: LOCATION_UPDATE_INTERVAL / 1000)
......