From 5b0cf46ab27c21b1773b984aacd7d6869bdb296a Mon Sep 17 00:00:00 2001 From: miklosimate <megykereku@gmail.com> Date: Tue, 26 Mar 2024 22:42:14 +0100 Subject: [PATCH] Little cleanup needed and ready for testing --- SenzorDataCollectorApp/Sensors.swift | 1 + .../ServerCommunicationManager.swift | 1 + SenzorDataCollectorApp/StartingView.swift | 27 ++++++++++--------- SenzorDataCollectorApp/Timer.swift | 3 ++- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/SenzorDataCollectorApp/Sensors.swift b/SenzorDataCollectorApp/Sensors.swift index e67a0a0..03eafa3 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 bd804d3..39b3732 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 006c78b..f8783c8 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 af68ffc..7238249 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)" -- GitLab