| 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:")
|
|
| 26 |
if meter.supportsFahrenheit {
|
|
| 27 |
Text("")
|
|
| 28 |
} |
|
| 29 |
Text("USB Data+:")
|
|
| 30 |
Text("USB Data-:")
|
|
| 31 |
if meter.supportsChargerDetection {
|
|
| 32 |
Text("Charger:")
|
|
| 33 |
} |
|
| 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)℃")
|
|
| 53 |
if meter.supportsFahrenheit {
|
|
| 54 |
Text("\(meter.temperatureFahrenheit)℉")
|
|
| 55 |
} |
|
| 56 |
Text("\(meter.usbPlusVoltage.format(decimalDigits: 2))V")
|
|
| 57 |
Text("\(meter.usbMinusVoltage.format(decimalDigits: 2))V")
|
|
| 58 |
if meter.supportsChargerDetection {
|
|
| 59 |
Text(meter.chargerTypeDescription) |
|
| 60 |
} |
|
| 61 |
} |
|
| 62 |
} |
|
| 63 |
.font(.footnote) |
|
| 64 |
} |
|
| 65 |
} |
|
| 66 |
} |