mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
* Add SwiftUI previews for simple helper views Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Add previews for action buttons, ChannelForm, MetricsColumnDetail, and DeviceOnboarding Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Add previews for config views, log views, AppLog, Firmware, AppData, and UserConfig Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Add preview for PositionConfig Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Fix formatting bugs in #Preview blocks: restore missing .environmentObject/.environment modifiers and add proper tab indentation Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/7eeb7a54-7928-466f-8e39-b00d0012a09d Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Linting fixes --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com>
108 lines
2.7 KiB
Swift
108 lines
2.7 KiB
Swift
//
|
|
// PowerMetrics.swift
|
|
// Meshtastic
|
|
//
|
|
// Created by Matthew Davies on 1/24/25.
|
|
//
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
|
|
struct PowerMetrics: View {
|
|
private let gridItemLayout = Array(repeating: GridItem(.flexible(), spacing: 10), count: 2)
|
|
|
|
let metric: TelemetryEntity
|
|
|
|
var body: some View {
|
|
|
|
LazyVGrid(columns: gridItemLayout) {
|
|
|
|
if let powerCh1Voltage = metric.powerCh1Voltage {
|
|
PowerMetricCompactWidget(
|
|
type: .voltage,
|
|
value: powerCh1Voltage,
|
|
title: "Channel 1 Voltage"
|
|
)
|
|
}
|
|
|
|
if let powerCh1Current = metric.powerCh1Current {
|
|
PowerMetricCompactWidget(
|
|
type: .current,
|
|
value: powerCh1Current,
|
|
title: "Channel 1 Current"
|
|
)
|
|
}
|
|
|
|
if let powerCh2Voltage = metric.powerCh2Voltage {
|
|
PowerMetricCompactWidget(
|
|
type: .voltage,
|
|
value: powerCh2Voltage,
|
|
title: "Channel 2 Voltage"
|
|
)
|
|
}
|
|
|
|
if let powerCh2Current = metric.powerCh2Current {
|
|
PowerMetricCompactWidget(
|
|
type: .current,
|
|
value: powerCh2Current,
|
|
title: "Channel 2 Current"
|
|
)
|
|
}
|
|
|
|
if let powerCh3Voltage = metric.powerCh3Voltage {
|
|
PowerMetricCompactWidget(
|
|
type: .voltage,
|
|
value: powerCh3Voltage,
|
|
title: "Channel 3 Voltage"
|
|
)
|
|
}
|
|
|
|
if let powerCh3Current = metric.powerCh3Current {
|
|
PowerMetricCompactWidget(
|
|
type: .current,
|
|
value: powerCh3Current,
|
|
title: "Channel 3 Current"
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
enum PowerMetricType: String {
|
|
case current = "Current"
|
|
case voltage = "Voltage"
|
|
}
|
|
|
|
struct PowerMetricCompactWidget: View {
|
|
let type: PowerMetricType
|
|
let value: Float
|
|
let title: String
|
|
var body: some View {
|
|
VStack(alignment: .leading) {
|
|
HStack(spacing: 5.0) {
|
|
Image(systemName: type == .current ? "bolt.fill" : "powerplug.fill")
|
|
.foregroundColor(.accentColor)
|
|
.font(.callout)
|
|
Text(title)
|
|
.font(.caption)
|
|
}
|
|
Text("\(value, specifier: type == .current ? "%.1f" : "%.2f") \(type == .current ? "mA" : "V")")
|
|
.font(type == .current ? .system(size: 35) : .system(size: 30))
|
|
}
|
|
.frame(minWidth: 100, idealWidth: 125, maxWidth: 150, minHeight: 120, idealHeight: 130, maxHeight: 140)
|
|
.padding()
|
|
.background(.tertiary, in: RoundedRectangle(cornerRadius: 20, style: .continuous))
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
let gridItemLayout = Array(repeating: GridItem(.flexible(), spacing: 10), count: 2)
|
|
Form {
|
|
LazyVGrid(columns: gridItemLayout) {
|
|
PowerMetricCompactWidget(type: .voltage, value: 3.72, title: "Channel 1 Voltage")
|
|
PowerMetricCompactWidget(type: .current, value: 125.3, title: "Channel 1 Current")
|
|
PowerMetricCompactWidget(type: .voltage, value: 5.01, title: "Channel 2 Voltage")
|
|
PowerMetricCompactWidget(type: .current, value: 42.7, title: "Channel 2 Current")
|
|
}
|
|
}
|
|
}
|