|
Bogdan Timofte
authored
2 weeks ago
|
1
|
//
|
|
|
2
|
// RecordingView.swift
|
|
|
3
|
// USB Meter
|
|
|
4
|
//
|
|
|
5
|
// Created by Bogdan Timofte on 09/03/2020.
|
|
|
6
|
// Copyright © 2020 Bogdan Timofte. All rights reserved.
|
|
|
7
|
//
|
|
|
8
|
|
|
|
9
|
import SwiftUI
|
|
|
10
|
|
|
|
11
|
struct RecordingView: View {
|
|
|
12
|
|
|
Bogdan Timofte
authored
2 weeks ago
|
13
|
@Binding var visibility: Bool
|
|
Bogdan Timofte
authored
2 weeks ago
|
14
|
@EnvironmentObject private var usbMeter: Meter
|
|
|
15
|
|
|
|
16
|
var body: some View {
|
|
Bogdan Timofte
authored
2 weeks ago
|
17
|
NavigationView {
|
|
|
18
|
ScrollView {
|
|
|
19
|
VStack(spacing: 16) {
|
|
|
20
|
VStack(spacing: 6) {
|
|
|
21
|
Text("Device Recording")
|
|
|
22
|
.font(.headline)
|
|
|
23
|
Text(usbMeter.recording ? "Active" : "Idle")
|
|
|
24
|
.foregroundColor(usbMeter.recording ? .red : .secondary)
|
|
|
25
|
}
|
|
|
26
|
.frame(maxWidth: .infinity)
|
|
|
27
|
.padding()
|
|
|
28
|
.background(RoundedRectangle(cornerRadius: 16).foregroundColor(.secondary).opacity(0.1))
|
|
|
29
|
|
|
|
30
|
HStack(alignment: .top) {
|
|
|
31
|
VStack(alignment: .leading, spacing: 10) {
|
|
|
32
|
Text("Capacity")
|
|
|
33
|
Text("Energy")
|
|
|
34
|
Text("Duration")
|
|
|
35
|
Text("Start Threshold")
|
|
|
36
|
}
|
|
|
37
|
Spacer()
|
|
|
38
|
VStack(alignment: .trailing, spacing: 10) {
|
|
|
39
|
Text("\(usbMeter.recordedAH.format(decimalDigits: 3)) Ah")
|
|
|
40
|
Text("\(usbMeter.recordedWH.format(decimalDigits: 3)) Wh")
|
|
|
41
|
Text(usbMeter.recordingDurationDescription)
|
|
|
42
|
if usbMeter.supportsRecordingThreshold {
|
|
|
43
|
Text("\(usbMeter.recordingTreshold.format(decimalDigits: 2)) A")
|
|
|
44
|
} else {
|
|
|
45
|
Text("Read-only")
|
|
|
46
|
}
|
|
|
47
|
}
|
|
|
48
|
}
|
|
|
49
|
.padding()
|
|
|
50
|
.background(RoundedRectangle(cornerRadius: 16).foregroundColor(.secondary).opacity(0.1))
|
|
|
51
|
|
|
Bogdan Timofte
authored
2 weeks ago
|
52
|
if usbMeter.supportsRecordingThreshold {
|
|
Bogdan Timofte
authored
2 weeks ago
|
53
|
VStack(alignment: .leading, spacing: 10) {
|
|
|
54
|
Text("Start Threshold")
|
|
|
55
|
.fontWeight(.semibold)
|
|
Bogdan Timofte
authored
2 weeks ago
|
56
|
Slider(value: $usbMeter.recordingTreshold, in: 0...0.30, step: 0.01)
|
|
Bogdan Timofte
authored
2 weeks ago
|
57
|
if let hint = usbMeter.recordingThresholdHint {
|
|
|
58
|
Text(hint)
|
|
|
59
|
.font(.footnote)
|
|
|
60
|
.foregroundColor(.secondary)
|
|
|
61
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
62
|
}
|
|
|
63
|
.padding()
|
|
Bogdan Timofte
authored
2 weeks ago
|
64
|
.background(RoundedRectangle(cornerRadius: 16).foregroundColor(.secondary).opacity(0.1))
|
|
Bogdan Timofte
authored
2 weeks ago
|
65
|
} else {
|
|
Bogdan Timofte
authored
2 weeks ago
|
66
|
Text("This model reports recording totals, but the app does not expose remote threshold control for it.")
|
|
|
67
|
.font(.footnote)
|
|
|
68
|
.foregroundColor(.secondary)
|
|
|
69
|
.multilineTextAlignment(.center)
|
|
|
70
|
.padding()
|
|
|
71
|
.background(RoundedRectangle(cornerRadius: 16).foregroundColor(.secondary).opacity(0.1))
|
|
Bogdan Timofte
authored
2 weeks ago
|
72
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
73
|
}
|
|
|
74
|
.padding()
|
|
Bogdan Timofte
authored
2 weeks ago
|
75
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
76
|
.navigationBarTitle("Device Recording", displayMode: .inline)
|
|
|
77
|
.navigationBarItems(trailing: Button("Done") { visibility.toggle() })
|
|
Bogdan Timofte
authored
2 weeks ago
|
78
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
79
|
.navigationViewStyle(StackNavigationViewStyle())
|
|
Bogdan Timofte
authored
2 weeks ago
|
80
|
}
|
|
|
81
|
}
|
|
|
82
|
|
|
|
83
|
struct RecordingView_Previews: PreviewProvider {
|
|
|
84
|
static var previews: some View {
|
|
Bogdan Timofte
authored
2 weeks ago
|
85
|
RecordingView(visibility: .constant(true))
|
|
Bogdan Timofte
authored
2 weeks ago
|
86
|
}
|
|
|
87
|
}
|