From ef6d28bfadaa49cecc797e59c004b23201111f27 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Wed, 28 Sep 2022 15:44:42 -0700 Subject: [PATCH] Battery gauge --- Meshtastic.xcodeproj/project.pbxproj | 4 ++ Meshtastic/Views/Bluetooth/Connect.swift | 2 +- Meshtastic/Views/Helpers/BatteryGauge.swift | 33 ++++++++++++ Meshtastic/Views/Nodes/NodeDetail.swift | 52 +++++++------------ Meshtastic/Views/Settings/ShareChannels.swift | 12 +++++ 5 files changed, 70 insertions(+), 33 deletions(-) create mode 100644 Meshtastic/Views/Helpers/BatteryGauge.swift diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index f6e0d27e..797531e1 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -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 = ""; }; DD3CC6B428E33FD100FA9159 /* ShareChannels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareChannels.swift; sourceTree = ""; }; DD3CC6BB28E366DF00FA9159 /* MeshtasticDataModel.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = MeshtasticDataModel.xcdatamodel; sourceTree = ""; }; + DD3CC6BD28E4CD9800FA9159 /* BatteryGauge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryGauge.swift; sourceTree = ""; }; DD4033C128B286B70096A444 /* Onboarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Onboarding.swift; sourceTree = ""; }; DD41582528582E9B009B0E59 /* DeviceConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceConfig.swift; sourceTree = ""; }; DD415827285859C4009B0E59 /* TelemetryConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TelemetryConfig.swift; sourceTree = ""; }; @@ -503,6 +505,7 @@ DDA6B2EA28420A7B003E8C16 /* NodeAnnotation.swift */, DDD94A4F2845C8F5004A87A0 /* DateTimeText.swift */, DDB6ABDA28B0AC6000384BA1 /* DistanceText.swift */, + DD3CC6BD28E4CD9800FA9159 /* BatteryGauge.swift */, ); path = Helpers; sourceTree = ""; @@ -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 */, diff --git a/Meshtastic/Views/Bluetooth/Connect.swift b/Meshtastic/Views/Bluetooth/Connect.swift index d5eb57c1..4cf30148 100644 --- a/Meshtastic/Views/Bluetooth/Connect.swift +++ b/Meshtastic/Views/Bluetooth/Connect.swift @@ -184,7 +184,7 @@ struct Connect: View { } } - HStack(alignment: .center) { + HStack(alignment: .center) { Spacer() diff --git a/Meshtastic/Views/Helpers/BatteryGauge.swift b/Meshtastic/Views/Helpers/BatteryGauge.swift new file mode 100644 index 00000000..c6a52762 --- /dev/null +++ b/Meshtastic/Views/Helpers/BatteryGauge.swift @@ -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() + } +} diff --git a/Meshtastic/Views/Nodes/NodeDetail.swift b/Meshtastic/Views/Nodes/NodeDetail.swift index 405a8777..b773824c 100644 --- a/Meshtastic/Views/Nodes/NodeDetail.swift +++ b/Meshtastic/Views/Nodes/NodeDetail.swift @@ -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: { diff --git a/Meshtastic/Views/Settings/ShareChannels.swift b/Meshtastic/Views/Settings/ShareChannels.swift index 82dbb747..3fda36af 100644 --- a/Meshtastic/Views/Settings/ShareChannels.swift +++ b/Meshtastic/Views/Settings/ShareChannels.swift @@ -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 {