Newer Older
66 lines | 2.618kb
Bogdan Timofte authored 2 weeks ago
1
//
2
//  LiveView.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 LiveView: View {
12

            
13
    @EnvironmentObject private var meter: Meter
14

            
15
    var body: some View {
16
        VStack {
17
            Text("Live Data")
18
                .font(.headline)
19
            HStack {
20
                VStack (alignment: .leading) {
21
                    Text("Voltage:")
22
                    Text("Current:")
23
                    Text("Power:")
24
                    Text("Load")
25
                    Text("Temperature:")
Bogdan Timofte authored 2 weeks ago
26
                    if meter.supportsFahrenheit {
27
                        Text("")
28
                    }
Bogdan Timofte authored 2 weeks ago
29
                    Text("USB Data+:")
30
                    Text("USB Data-:")
Bogdan Timofte authored 2 weeks ago
31
                    if meter.supportsChargerDetection {
32
                        Text("Charger:")
33
                    }
Bogdan Timofte authored 2 weeks ago
34
                }
35
                VStack (alignment: .trailing) {
36
                    HStack {
37
                        Text("\(meter.measurements.voltage.context.minValue.format(decimalDigits: 3))V")
38
                        Text("\(meter.voltage.format(decimalDigits: 3))V")
39
                        Text("\(meter.measurements.voltage.context.maxValue.format(decimalDigits: 3))V")
40
                    }
41
                    HStack {
42
                        Text("\(meter.measurements.current.context.minValue.format(decimalDigits: 3))A")
43
                        Text("\(meter.current.format(decimalDigits: 3))A")
44
                        Text("\(meter.measurements.current.context.maxValue.format(decimalDigits: 3))A")
45
                    }
46
                    HStack {
47
                        Text("\(meter.measurements.power.context.minValue.format(decimalDigits: 3))W")
48
                        Text("\(meter.power.format(decimalDigits: 3))W")
49
                        Text("\(meter.measurements.power.context.maxValue.format(decimalDigits: 3))W")
50
                    }
51
                    Text("\(meter.loadResistance.format(decimalDigits: 1))Ω")
52
                    Text("\(meter.temperatureCelsius)℃")
Bogdan Timofte authored 2 weeks ago
53
                    if meter.supportsFahrenheit {
54
                        Text("\(meter.temperatureFahrenheit)℉")
55
                    }
Bogdan Timofte authored 2 weeks ago
56
                    Text("\(meter.usbPlusVoltage.format(decimalDigits: 2))V")
57
                    Text("\(meter.usbMinusVoltage.format(decimalDigits: 2))V")
Bogdan Timofte authored 2 weeks ago
58
                    if meter.supportsChargerDetection {
Bogdan Timofte authored 2 weeks ago
59
                        Text(meter.chargerTypeDescription)
Bogdan Timofte authored 2 weeks ago
60
                    }
Bogdan Timofte authored 2 weeks ago
61
                }
62
            }
63
            .font(.footnote)
64
        }
65
    }
66
}