Battery gauge

This commit is contained in:
Garth Vander Houwen 2022-09-28 15:44:42 -07:00
parent 401423f606
commit ef6d28bfad
5 changed files with 70 additions and 33 deletions

View file

@ -27,6 +27,7 @@
DD35018B2852FC79000FC853 /* UserSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD35018A2852FC79000FC853 /* UserSettings.swift */; };
DD3CC6B528E33FD100FA9159 /* ShareChannels.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3CC6B428E33FD100FA9159 /* ShareChannels.swift */; };
DD3CC6BC28E366DF00FA9159 /* Meshtastic.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = DD3CC6BA28E366DF00FA9159 /* Meshtastic.xcdatamodeld */; };
DD3CC6BE28E4CD9800FA9159 /* BatteryGauge.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3CC6BD28E4CD9800FA9159 /* BatteryGauge.swift */; };
DD4033C228B286B70096A444 /* Onboarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD4033C128B286B70096A444 /* Onboarding.swift */; };
DD41582628582E9B009B0E59 /* DeviceConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD41582528582E9B009B0E59 /* DeviceConfig.swift */; };
DD415828285859C4009B0E59 /* TelemetryConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD415827285859C4009B0E59 /* TelemetryConfig.swift */; };
@ -137,6 +138,7 @@
DD35018A2852FC79000FC853 /* UserSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSettings.swift; sourceTree = "<group>"; };
DD3CC6B428E33FD100FA9159 /* ShareChannels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareChannels.swift; sourceTree = "<group>"; };
DD3CC6BB28E366DF00FA9159 /* MeshtasticDataModel.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = MeshtasticDataModel.xcdatamodel; sourceTree = "<group>"; };
DD3CC6BD28E4CD9800FA9159 /* BatteryGauge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryGauge.swift; sourceTree = "<group>"; };
DD4033C128B286B70096A444 /* Onboarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Onboarding.swift; sourceTree = "<group>"; };
DD41582528582E9B009B0E59 /* DeviceConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceConfig.swift; sourceTree = "<group>"; };
DD415827285859C4009B0E59 /* TelemetryConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TelemetryConfig.swift; sourceTree = "<group>"; };
@ -503,6 +505,7 @@
DDA6B2EA28420A7B003E8C16 /* NodeAnnotation.swift */,
DDD94A4F2845C8F5004A87A0 /* DateTimeText.swift */,
DDB6ABDA28B0AC6000384BA1 /* DistanceText.swift */,
DD3CC6BD28E4CD9800FA9159 /* BatteryGauge.swift */,
);
path = Helpers;
sourceTree = "<group>";
@ -716,6 +719,7 @@
DDAF8C6226ED0A230058C060 /* mqtt.pb.swift in Sources */,
DDF924CA26FBB953009FE055 /* ConnectedDevice.swift in Sources */,
DDAF8C5D26ED09490058C060 /* portnums.pb.swift in Sources */,
DD3CC6BE28E4CD9800FA9159 /* BatteryGauge.swift in Sources */,
DD6193772862F90F00E59241 /* CannedMessagesConfig.swift in Sources */,
DD41582628582E9B009B0E59 /* DeviceConfig.swift in Sources */,
DD3CC6B528E33FD100FA9159 /* ShareChannels.swift in Sources */,

View file

@ -184,7 +184,7 @@ struct Connect: View {
}
}
HStack(alignment: .center) {
HStack(alignment: .center) {
Spacer()

View file

@ -0,0 +1,33 @@
//
// BatteryGauge.swift
// Meshtastic
//
// Created by Garth Vander Houwen on 9/28/22.
//
import SwiftUI
import Charts
struct BatteryGauge: View {
@State var batteryLevel = 64.0
private let minValue = 1.0
private let maxValue = 100.00
let gradient = Gradient(colors: [.red, .yellow, .green])
var body: some View {
VStack {
Gauge(value: batteryLevel, in: minValue...maxValue) {
Label("Battery Level %", systemImage: "battery.0")
} currentValueLabel: {
Text(Int(batteryLevel), format: .percent)
}
.tint(gradient)
}
.gaugeStyle(.accessoryCircular)
.padding()
}
}

View file

@ -191,7 +191,11 @@ struct NodeDetail: View {
.font(.largeTitle)
.foregroundColor(.gray)
.fixedSize()
}
}
if node.telemetries?.count ?? 0 >= 1 {
@ -199,23 +203,15 @@ struct NodeDetail: View {
let mostRecent = node.telemetries?.lastObject as! TelemetryEntity
Divider()
VStack(alignment: .center) {
BatteryIcon(batteryLevel: mostRecent.batteryLevel, font: .largeTitle, color: .accentColor)
.padding(.bottom, 10)
if mostRecent.batteryLevel > 0 {
Text(String(mostRecent.batteryLevel) + "%")
.font(.largeTitle)
.frame(width: 100)
.foregroundColor(.gray)
.fixedSize()
}
BatteryGauge(batteryLevel: Double(mostRecent.batteryLevel))
if mostRecent.voltage > 0 {
Text(String(format: "%.2f", mostRecent.voltage) + " V")
.font(.largeTitle)
.font(.title)
.foregroundColor(.gray)
.fixedSize()
}
@ -225,10 +221,6 @@ struct NodeDetail: View {
}
.padding()
.onLongPressGesture(minimumDuration: 2) {
print("Long pressed!")
}
Divider()
HStack(alignment: .center) {
@ -291,11 +283,9 @@ struct NodeDetail: View {
HStack {
VStack(alignment: .center) {
Text("AKA").font(.title2).fixedSize()
CircleText(text: node.user?.shortName ?? "???", color: .accentColor)
.offset(y: 10)
}
.padding(5)
Divider()
@ -340,29 +330,24 @@ struct NodeDetail: View {
VStack(alignment: .center) {
BatteryIcon(batteryLevel: mostRecent.batteryLevel, font: .title, color: .accentColor)
.padding(.bottom)
BatteryGauge(batteryLevel: Double(mostRecent.batteryLevel))
if mostRecent.batteryLevel > 0 {
Text(String(mostRecent.batteryLevel) + "%")
.font(.title3)
.foregroundColor(.gray)
.fixedSize()
}
if mostRecent.voltage > 0 {
Text(String(format: "%.2f", mostRecent.voltage) + " V")
.font(.title3)
.font(.callout)
.foregroundColor(.gray)
.fixedSize()
.offset(y: -25)
}
}
.padding(5)
}
}
.padding(4)
Divider()
HStack(alignment: .center) {
VStack {
HStack {
Image(systemName: "person")
@ -396,12 +381,15 @@ struct NodeDetail: View {
Text(String(node.user?.macaddr?.macAddressString ?? "not a valid mac address")).foregroundColor(.gray)
}
.padding([.bottom], 0)
Divider()
}
VStack {
if (node.positions?.count ?? 0) > 0 {
NavigationLink {
PositionLog(node: node)
} label: {

View file

@ -67,6 +67,18 @@ struct ShareChannels: View {
alignment: .center
)
VStack {
ShareLink(
item: text,
preview: SharePreview(
"Meshtastic Channel Settings From Node \(node?.user?.shortName ?? "????")",
image: Image(systemName: "qrcode")
)
)
.presentationDetents([.large, .large])
.font(.title3)
}
if node != nil && node!.loRaConfig != nil {
HStack {