|
Bogdan Timofte
authored
2 weeks ago
|
1
|
//
|
|
|
2
|
// MeterComunicationView.swift
|
|
|
3
|
// USB Meter
|
|
|
4
|
//
|
|
|
5
|
// Created by Bogdan Timofte on 05/05/2020.
|
|
|
6
|
// Copyright © 2020 Bogdan Timofte. All rights reserved.
|
|
|
7
|
//
|
|
|
8
|
|
|
|
9
|
import SwiftUI
|
|
|
10
|
|
|
|
11
|
struct MeterRowView: View {
|
|
|
12
|
|
|
|
13
|
@EnvironmentObject private var meter: Meter
|
|
|
14
|
|
|
|
15
|
var body: some View {
|
|
Bogdan Timofte
authored
2 weeks ago
|
16
|
HStack(spacing: 14) {
|
|
|
17
|
Image(systemName: "sensor.tag.radiowaves.forward.fill")
|
|
|
18
|
.font(.system(size: 18, weight: .semibold))
|
|
Bogdan Timofte
authored
2 weeks ago
|
19
|
.foregroundColor(meter.color)
|
|
Bogdan Timofte
authored
2 weeks ago
|
20
|
.frame(width: 42, height: 42)
|
|
|
21
|
.background(
|
|
|
22
|
Circle()
|
|
Bogdan Timofte
authored
2 weeks ago
|
23
|
.fill(meter.color.opacity(0.18))
|
|
Bogdan Timofte
authored
2 weeks ago
|
24
|
)
|
|
Bogdan Timofte
authored
2 weeks ago
|
25
|
.overlay(alignment: .bottomTrailing) {
|
|
|
26
|
Circle()
|
|
|
27
|
.fill(connectivityTint)
|
|
|
28
|
.frame(width: 12, height: 12)
|
|
|
29
|
.overlay(
|
|
|
30
|
Circle()
|
|
|
31
|
.stroke(Color(uiColor: .systemBackground), lineWidth: 2)
|
|
|
32
|
)
|
|
|
33
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
34
|
|
|
|
35
|
VStack(alignment: .leading, spacing: 4) {
|
|
|
36
|
Text(meter.name)
|
|
|
37
|
.font(.headline)
|
|
|
38
|
Text(meter.deviceModelSummary)
|
|
|
39
|
.font(.caption)
|
|
|
40
|
.foregroundColor(.secondary)
|
|
|
41
|
}
|
|
|
42
|
|
|
|
43
|
Spacer()
|
|
|
44
|
|
|
|
45
|
VStack(alignment: .trailing, spacing: 4) {
|
|
Bogdan Timofte
authored
2 weeks ago
|
46
|
HStack(spacing: 6) {
|
|
|
47
|
Circle()
|
|
|
48
|
.fill(connectivityTint)
|
|
|
49
|
.frame(width: 8, height: 8)
|
|
|
50
|
Text(statusText)
|
|
|
51
|
.font(.caption.weight(.semibold))
|
|
|
52
|
.foregroundColor(.secondary)
|
|
|
53
|
}
|
|
|
54
|
.padding(.horizontal, 10)
|
|
|
55
|
.padding(.vertical, 6)
|
|
|
56
|
.background(
|
|
|
57
|
Capsule(style: .continuous)
|
|
|
58
|
.fill(connectivityTint.opacity(0.12))
|
|
|
59
|
)
|
|
|
60
|
.overlay(
|
|
|
61
|
Capsule(style: .continuous)
|
|
|
62
|
.stroke(connectivityTint.opacity(0.22), lineWidth: 1)
|
|
|
63
|
)
|
|
Bogdan Timofte
authored
2 weeks ago
|
64
|
Text(meter.btSerial.macAddress.description)
|
|
|
65
|
.font(.caption2)
|
|
|
66
|
.foregroundColor(.secondary)
|
|
|
67
|
}
|
|
|
68
|
}
|
|
|
69
|
.padding(14)
|
|
|
70
|
.meterCard(
|
|
Bogdan Timofte
authored
2 weeks ago
|
71
|
tint: meter.color,
|
|
Bogdan Timofte
authored
2 weeks ago
|
72
|
fillOpacity: 0.16,
|
|
|
73
|
strokeOpacity: 0.22,
|
|
|
74
|
cornerRadius: 18
|
|
|
75
|
)
|
|
|
76
|
}
|
|
|
77
|
|
|
Bogdan Timofte
authored
2 weeks ago
|
78
|
private var connectivityTint: Color {
|
|
|
79
|
Meter.operationalColor(for: meter.operationalState)
|
|
|
80
|
}
|
|
|
81
|
|
|
Bogdan Timofte
authored
2 weeks ago
|
82
|
private var statusText: String {
|
|
|
83
|
switch meter.operationalState {
|
|
|
84
|
case .notPresent:
|
|
|
85
|
return "Missing"
|
|
|
86
|
case .peripheralNotConnected:
|
|
|
87
|
return "Available"
|
|
|
88
|
case .peripheralConnectionPending:
|
|
|
89
|
return "Connecting"
|
|
|
90
|
case .peripheralConnected:
|
|
|
91
|
return "Linked"
|
|
|
92
|
case .peripheralReady:
|
|
|
93
|
return "Ready"
|
|
|
94
|
case .comunicating:
|
|
|
95
|
return "Syncing"
|
|
|
96
|
case .dataIsAvailable:
|
|
|
97
|
return "Live"
|
|
Bogdan Timofte
authored
2 weeks ago
|
98
|
}
|
|
|
99
|
}
|
|
|
100
|
}
|