|
Bogdan Timofte
authored
2 weeks ago
|
1
|
//
|
|
Bogdan Timofte
authored
a week ago
|
2
|
// MeasurementSeriesSampleView.swift
|
|
Bogdan Timofte
authored
2 weeks ago
|
3
|
// USB Meter
|
|
|
4
|
//
|
|
|
5
|
// Created by Bogdan Timofte on 13/04/2020.
|
|
|
6
|
// Copyright © 2020 Bogdan Timofte. All rights reserved.
|
|
|
7
|
//
|
|
|
8
|
|
|
|
9
|
import SwiftUI
|
|
|
10
|
|
|
Bogdan Timofte
authored
a week ago
|
11
|
struct MeasurementSeriesSampleView: View {
|
|
Bogdan Timofte
authored
2 weeks ago
|
12
|
|
|
|
13
|
var power: Measurements.Measurement.Point
|
|
|
14
|
var voltage: Measurements.Measurement.Point
|
|
|
15
|
var current: Measurements.Measurement.Point
|
|
Bogdan Timofte
authored
17 hours ago
|
16
|
var energy: Measurements.Measurement.Point?
|
|
Bogdan Timofte
authored
2 weeks ago
|
17
|
|
|
|
18
|
@State var showDetail: Bool = false
|
|
|
19
|
|
|
|
20
|
var body: some View {
|
|
Bogdan Timofte
authored
2 weeks ago
|
21
|
VStack(alignment: .leading, spacing: 12) {
|
|
|
22
|
HStack(spacing: 12) {
|
|
|
23
|
Image(systemName: "waveform.path.ecg.rectangle.fill")
|
|
|
24
|
.foregroundColor(.blue)
|
|
|
25
|
.frame(width: 36, height: 36)
|
|
|
26
|
.background(Circle().fill(Color.blue.opacity(0.16)))
|
|
|
27
|
VStack(alignment: .leading, spacing: 3) {
|
|
|
28
|
Text(voltage.timestamp.format(as: "yyyy-MM-dd HH:mm:ss"))
|
|
|
29
|
.font(.subheadline.weight(.semibold))
|
|
|
30
|
Text("Captured sample")
|
|
|
31
|
.font(.caption)
|
|
|
32
|
.foregroundColor(.secondary)
|
|
|
33
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
34
|
Spacer()
|
|
|
35
|
Button(action: {
|
|
Bogdan Timofte
authored
2 weeks ago
|
36
|
showDetail.toggle()
|
|
Bogdan Timofte
authored
2 weeks ago
|
37
|
}) {
|
|
Bogdan Timofte
authored
2 weeks ago
|
38
|
Image(systemName: "chevron.right.circle.fill")
|
|
Bogdan Timofte
authored
2 weeks ago
|
39
|
.imageScale(.large)
|
|
Bogdan Timofte
authored
2 weeks ago
|
40
|
.foregroundColor(.secondary)
|
|
Bogdan Timofte
authored
2 weeks ago
|
41
|
.rotationEffect(.degrees(showDetail ? 90 : 0))
|
|
Bogdan Timofte
authored
2 weeks ago
|
42
|
.animation(.easeInOut(duration: 0.25), value: showDetail)
|
|
Bogdan Timofte
authored
2 weeks ago
|
43
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
44
|
.buttonStyle(.plain)
|
|
Bogdan Timofte
authored
2 weeks ago
|
45
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
46
|
|
|
Bogdan Timofte
authored
2 weeks ago
|
47
|
if showDetail {
|
|
Bogdan Timofte
authored
2 weeks ago
|
48
|
VStack(spacing: 10) {
|
|
|
49
|
detailRow(title: "Power", value: "\(power.value.format(fractionDigits: 4)) W")
|
|
|
50
|
detailRow(title: "Voltage", value: "\(voltage.value.format(fractionDigits: 4)) V")
|
|
|
51
|
detailRow(title: "Current", value: "\(current.value.format(fractionDigits: 4)) A")
|
|
Bogdan Timofte
authored
17 hours ago
|
52
|
if let energy {
|
|
|
53
|
detailRow(title: "Energy", value: "\(energy.value.format(fractionDigits: 4)) Wh")
|
|
|
54
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
55
|
}
|
|
|
56
|
}
|
|
|
57
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
58
|
.padding(16)
|
|
|
59
|
.meterCard(tint: .blue, fillOpacity: 0.14, strokeOpacity: 0.20, cornerRadius: 18)
|
|
|
60
|
}
|
|
|
61
|
|
|
|
62
|
private func detailRow(title: String, value: String) -> some View {
|
|
|
63
|
HStack {
|
|
|
64
|
Text(title)
|
|
|
65
|
.foregroundColor(.secondary)
|
|
|
66
|
Spacer()
|
|
|
67
|
Text(value)
|
|
|
68
|
.fontWeight(.semibold)
|
|
|
69
|
.monospacedDigit()
|
|
|
70
|
}
|
|
|
71
|
.font(.footnote)
|
|
Bogdan Timofte
authored
2 weeks ago
|
72
|
}
|
|
|
73
|
}
|