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

Timer works, file often too large

parent 1615a738
Branches
No related tags found
No related merge requests found
......@@ -109,7 +109,6 @@ class SensorCollector: ObservableObject {
let altTimestampedTuple = (Int(Date().timeIntervalSince1970 * 1000), (x: rel_altitude, y: pressure, z: 0.0))
DispatchQueue.main.async {
// Append the sensor data to the correct MeasuringSensors instance in the activeSensorsList
if let index = self.activeSensorsList.firstIndex(where: { $0.sensorName == Sensors.alt.rawValue }) {
self.activeSensorsList[index].sensorData.append(altTimestampedTuple)
}
......
......@@ -34,8 +34,10 @@ struct StartingView: View {
//----------TIMER SETUP SETTINGS AND VARS -----------------------------------------------------
@StateObject var customTimer : CustomTimer
private let backgroundTaskIdentifier = "hu.itk.ppke.backgroundTask"
private let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
//----------MEASURMENT SETUP AND VARS ---------------------------------------------------------
@State var demostart = false
@State var sensorDetailSheetPresented = false
@State var showingFilePicker = false
@State var selectedFolder: URL?
......@@ -58,6 +60,7 @@ struct StartingView: View {
//----------------------------- DEBUG VALUE DISPAY ---------------------------------
Text("Notification list: \(manager.timerIntervalValues.map { "\($0)" }.joined(separator: ", "))").opacity(debug ? 0 : 1)
Text("Next notification in: \(customTimer.timerStringValue)").opacity(debug ? 0 : 1)
Text("\(manager.serverResponse)")
.padding().opacity(debug ? 0 : 1)
......@@ -95,9 +98,6 @@ struct StartingView: View {
)
}
}
Button("CreateDIR"){
createDirectory()
}.padding().opacity(debug ? 0 : 1)
......@@ -198,10 +198,8 @@ struct StartingView: View {
if manager.state == "Ready" {
createDirectory()
setNextMeasurement()
sensor.startAllRecording(motionManager: motionManager, altimeter: altimeter)
customTimer.startTimer()
first_open = false
demostart = true
}
} label: {
Text(manager.state != "Ready" ? "Get started" : manager.state)
......@@ -218,10 +216,10 @@ struct StartingView: View {
})
//----------------------------- TIMER REFRESH ---------------------------------
.onReceive(Timer.publish(every: 1, on: .main, in: .common).autoconnect()){
_ in
.onReceive(timer){ _ in
if customTimer.isStarted{
customTimer.updateTimer()
print("Timer: \(customTimer.totalSeconds)")
}
}
//----------------------------- NOTIFICAION HANDELING ---------------------------------
......@@ -231,9 +229,13 @@ struct StartingView: View {
sensor.stopAllRecording(motionManager: motionManager, altimeter: altimeter)
customTimer.stopTimer()
saveAllToJson()
setNextMeasurement()
sensor.startAllRecording(motionManager: motionManager, altimeter: altimeter)
customTimer.startTimer()
if customTimer.totalSeconds != 0 {
sensor.startAllRecording(motionManager: motionManager, altimeter: altimeter)
customTimer.startTimer()
}
}
Button("Stop", role: .destructive){
sensor.stopAllRecording(motionManager: motionManager, altimeter: altimeter)
......@@ -241,6 +243,21 @@ struct StartingView: View {
saveAllToJson()
}
}
//------------------ DEMO NOTIFICATION - MEASUREMENT STARTING ----------------------
.alert("Demo Alert - press start if you are ready to start!", isPresented: $demostart){
Button("Start",role: .cancel){
sensor.stopAllRecording(motionManager: motionManager, altimeter: altimeter)
customTimer.stopTimer()
setNextMeasurement()
if customTimer.totalSeconds != 0 {
sensor.startAllRecording(motionManager: motionManager, altimeter: altimeter)
customTimer.startTimer()
}
}
Button("Stop", role: .destructive){
first_open = true
}
}
}
}
func saveAllToJson(){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment