diff --git a/SenzorDataCollectorApp/Sensors.swift b/SenzorDataCollectorApp/Sensors.swift index e67a0a0b578cbfa6eb91d243738f97ef00f79edc..03eafa3c7af8e05a041600367f9763d49de60951 100644 --- a/SenzorDataCollectorApp/Sensors.swift +++ b/SenzorDataCollectorApp/Sensors.swift @@ -79,6 +79,7 @@ class SensorCollector: ObservableObject { func stopAllRecording(motionManager: CMMotionManager, altimeter: CMAltimeter){ + print("Sensors stopped all recording") motionManager.stopAccelerometerUpdates() motionManager.stopGyroUpdates() motionManager.stopMagnetometerUpdates() diff --git a/SenzorDataCollectorApp/ServerCommunicationManager.swift b/SenzorDataCollectorApp/ServerCommunicationManager.swift index bd804d32e667923d1e55eae71768b6afa4c5358b..39b3732fc2711b26be0c18c618663b0c4a02d292 100644 --- a/SenzorDataCollectorApp/ServerCommunicationManager.swift +++ b/SenzorDataCollectorApp/ServerCommunicationManager.swift @@ -46,6 +46,7 @@ class ServerCommunicationManager: ObservableObject { } task.resume() } + func sendMessage(type: String, filename: String="", jsonData: String = "") { guard let port = Int(portNumber), !hostName.isEmpty else { diff --git a/SenzorDataCollectorApp/StartingView.swift b/SenzorDataCollectorApp/StartingView.swift index 006c78bb1b521b8eebe8cc61f7488db40935917d..f8783c85d6567812ec87c0bfcd8187e443bea4f6 100644 --- a/SenzorDataCollectorApp/StartingView.swift +++ b/SenzorDataCollectorApp/StartingView.swift @@ -7,11 +7,6 @@ //TODO // - start - stop debugging -// - notification improve information -// - JSON sending -// - background / locked phone - widget ? - - import Foundation import SwiftUI @@ -30,6 +25,7 @@ struct StartingView: View { @State private var iterationCount = 0 @State var displayText = "" @State var first_open = true + @State private var shouldStartRecording = false //----------TIMER SETUP SETTINGS AND VARS ----------------------------------------------------- @StateObject var customTimer : CustomTimer @@ -220,22 +216,32 @@ struct StartingView: View { if customTimer.isStarted{ customTimer.updateTimer() print("Timer: \(customTimer.totalSeconds)") + +// if customTimer.totalSeconds == 2 { +// shouldStartRecording = true +// } } } +// .onReceive(Just(shouldStartRecording)) { _ in +// if shouldStartRecording { +// print("Starting measurements") +// sensor.startAllRecording(motionManager: motionManager, altimeter: altimeter) +// shouldStartRecording = false +// } +// } //----------------------------- NOTIFICAION HANDELING --------------------------------- - .alert("ALERT!!!", isPresented: $customTimer.isFinished) { - Button("Next",role: .cancel){ + .alert("\(manager.numberOfMeasurements - manager.timerIntervalValues.count >= 0 ? "\(manager.numberOfMeasurements - manager.timerIntervalValues.count)/\(manager.numberOfMeasurements)" : "Not initialised") Measurement", isPresented: $customTimer.isFinished) { + Button(manager.timerIntervalValues.count == 0 ? "End" : "Next" ,role: .cancel){ sensor.stopAllRecording(motionManager: motionManager, altimeter: altimeter) customTimer.stopTimer() saveAllToJson() setNextMeasurement() - if customTimer.totalSeconds != 0 { + if manager.timerIntervalValues.count != 0 { sensor.startAllRecording(motionManager: motionManager, altimeter: altimeter) customTimer.startTimer() } - } Button("Stop", role: .destructive){ sensor.stopAllRecording(motionManager: motionManager, altimeter: altimeter) @@ -262,7 +268,6 @@ struct StartingView: View { } func saveAllToJson(){ do { - //calculate timestamps: let now = Date() let timeInMilliseconds = Int(now.timeIntervalSince1970 * 1000) @@ -319,9 +324,7 @@ struct StartingView: View { } customTimer.refreshTimer() } - } - struct StartingView_Previews: PreviewProvider { static var previews: some View { StartingView( customTimer: CustomTimer()) diff --git a/SenzorDataCollectorApp/Timer.swift b/SenzorDataCollectorApp/Timer.swift index af68ffcd41cd5ccc63942d5212fb023a6181c982..7238249783672b49ab2ffdeb68362765284388c1 100644 --- a/SenzorDataCollectorApp/Timer.swift +++ b/SenzorDataCollectorApp/Timer.swift @@ -73,7 +73,8 @@ class CustomTimer: NSObject,ObservableObject, UNUserNotificationCenterDelegate { } } func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { - completionHandler([.sound,.banner]) + //completionHandler([.sound,.banner]) + completionHandler([.sound,.badge]) } func refreshTimer(){ timerStringValue = "\(minutes):\(seconds)"