Skip to content
Snippets Groups Projects
Commit 5b0cf46a authored by miklosimate's avatar miklosimate
Browse files

Little cleanup needed and ready for testing

parent c76d6b3f
Branches
No related tags found
No related merge requests found
......@@ -79,6 +79,7 @@ class SensorCollector: ObservableObject {
func stopAllRecording(motionManager: CMMotionManager, altimeter: CMAltimeter){
print("Sensors stopped all recording")
motionManager.stopAccelerometerUpdates()
motionManager.stopGyroUpdates()
motionManager.stopMagnetometerUpdates()
......
......@@ -47,6 +47,7 @@ class ServerCommunicationManager: ObservableObject {
task.resume()
}
func sendMessage(type: String, filename: String="", jsonData: String = "") {
guard let port = Int(portNumber), !hostName.isEmpty else {
serverResponse = "Invalid Port Number or Host"
......
......@@ -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())
......
......@@ -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)"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment