From fbddbe341cd1938214eeb47bf766a6abf9b5d19a Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Mon, 13 Jun 2022 20:43:51 -0700 Subject: [PATCH] Live mockup of device config --- Meshtastic Apple.xcodeproj/project.pbxproj | 4 + .../Map/Custom/PositionAnnotationView.swift | 2 +- MeshtasticApple/Views/Nodes/NodeDetail.swift | 12 ++- .../Views/Settings/DeviceConfig.swift | 91 +++++++++++++++++++ .../Views/Settings/PositionConfig.swift | 4 +- .../Views/Settings/PowerConfig.swift | 2 +- MeshtasticApple/Views/Settings/Settings.swift | 8 ++ 7 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 MeshtasticApple/Views/Settings/DeviceConfig.swift diff --git a/Meshtastic Apple.xcodeproj/project.pbxproj b/Meshtastic Apple.xcodeproj/project.pbxproj index 9a440c6e..9f4cc380 100644 --- a/Meshtastic Apple.xcodeproj/project.pbxproj +++ b/Meshtastic Apple.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ DD2E65262767A01F00E45FC5 /* NodeDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E65252767A01F00E45FC5 /* NodeDetail.swift */; }; DD3501892852FC3B000FC853 /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3501882852FC3B000FC853 /* Settings.swift */; }; DD35018B2852FC79000FC853 /* UserSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD35018A2852FC79000FC853 /* UserSettings.swift */; }; + DD41582628582E9B009B0E59 /* DeviceConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD41582528582E9B009B0E59 /* DeviceConfig.swift */; }; DD47E3CE26F103C600029299 /* NodeList.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD47E3CD26F103C600029299 /* NodeList.swift */; }; DD47E3D626F17ED900029299 /* CircleText.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD47E3D526F17ED900029299 /* CircleText.swift */; }; DD47E3D926F3093800029299 /* MessageBubble.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD47E3D826F3093800029299 /* MessageBubble.swift */; }; @@ -103,6 +104,7 @@ DD2E65252767A01F00E45FC5 /* NodeDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeDetail.swift; sourceTree = ""; }; DD3501882852FC3B000FC853 /* Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Settings.swift; sourceTree = ""; }; DD35018A2852FC79000FC853 /* UserSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSettings.swift; sourceTree = ""; }; + DD41582528582E9B009B0E59 /* DeviceConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceConfig.swift; sourceTree = ""; }; DD45C77427BD4EF80011784F /* MeshtasticDataModel v2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MeshtasticDataModel v2.xcdatamodel"; sourceTree = ""; }; DD47E3CD26F103C600029299 /* NodeList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeList.swift; sourceTree = ""; }; DD47E3D526F17ED900029299 /* CircleText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircleText.swift; sourceTree = ""; }; @@ -230,6 +232,7 @@ DD3501882852FC3B000FC853 /* Settings.swift */, DD4A911D2708C65400501B7E /* AppSettings.swift */, DD6B85A728009258000ACD6B /* ShareChannel.swift */, + DD41582528582E9B009B0E59 /* DeviceConfig.swift */, DD8EBF42285058FA00426DCA /* DisplayConfig.swift */, DD2553562855B02500E55709 /* LoRaConfig.swift */, DD2553582855B52700E55709 /* PositionConfig.swift */, @@ -596,6 +599,7 @@ DDAF8C5D26ED09490058C060 /* portnums.pb.swift in Sources */, DD9D8F2F2764403B00080993 /* Meshtastic.xcdatamodeld in Sources */, DD25535D285666C700E55709 /* PowerConfig.swift in Sources */, + DD41582628582E9B009B0E59 /* DeviceConfig.swift in Sources */, DD1BF2F92776FE2E008C8D2F /* UserMessageList.swift in Sources */, DDB2CC6E27F3EB47009C5FCC /* telemetry.pb.swift in Sources */, DD23A50F26FD1B4400D9B90C /* PeripheralModel.swift in Sources */, diff --git a/MeshtasticApple/Views/Map/Custom/PositionAnnotationView.swift b/MeshtasticApple/Views/Map/Custom/PositionAnnotationView.swift index 4500052a..47c20197 100644 --- a/MeshtasticApple/Views/Map/Custom/PositionAnnotationView.swift +++ b/MeshtasticApple/Views/Map/Custom/PositionAnnotationView.swift @@ -25,7 +25,7 @@ class PositionAnnotation: NSObject, MKAnnotation { class PositionAnnotationView: MKAnnotationView { - private let annotationFrame = CGRect(x: 0, y: 0, width: 40, height: 40cen) + private let annotationFrame = CGRect(x: 0, y: 0, width: 40, height: 40) private let label: UILabel override init(annotation: MKAnnotation?, reuseIdentifier: String?) { diff --git a/MeshtasticApple/Views/Nodes/NodeDetail.swift b/MeshtasticApple/Views/Nodes/NodeDetail.swift index a1008e74..aa69dd53 100644 --- a/MeshtasticApple/Views/Nodes/NodeDetail.swift +++ b/MeshtasticApple/Views/Nodes/NodeDetail.swift @@ -219,11 +219,13 @@ struct NodeDetail: View { .foregroundColor(.gray) .fixedSize() } - - Text(String(format: "%.2f", mostRecent.voltage) + " V") - .font(.title3) - .foregroundColor(.gray) - .fixedSize() + if mostRecent.voltage > 0 { + + Text(String(format: "%.2f", mostRecent.voltage) + " V") + .font(.title3) + .foregroundColor(.gray) + .fixedSize() + } } .padding(5) } diff --git a/MeshtasticApple/Views/Settings/DeviceConfig.swift b/MeshtasticApple/Views/Settings/DeviceConfig.swift new file mode 100644 index 00000000..ae734c68 --- /dev/null +++ b/MeshtasticApple/Views/Settings/DeviceConfig.swift @@ -0,0 +1,91 @@ +// +// DeviceConfig.swift +// Meshtastic Apple +// +// Copyright (c) Garth Vander Houwen 6/13/22. +// +import SwiftUI + +// Default of 0 is One Minute +enum DeviceRoles: Int, CaseIterable, Identifiable { + + case client = 0 + case clientMute = 1 + case router = 2 + case routerClient = 3 + + var id: Int { self.rawValue } + var description: String { + get { + switch self { + + case .client: + return "Client (default)" + case .clientMute: + return "Client Mute - Packets will not hop over this node, does not contribute to routing packets for mesh." + case .router: + return "Router - Mesh packets will prefer to be routed over this node. This node will not be used by client apps. The wifi/ble radios and the oled screen will be put to sleep." + case .routerClient: + return "Router Client - Mesh packets will prefer to be routed over this node. The Router Client can be used as both a Router and an app connected Client." + } + } + } +} + +struct DeviceConfig: View { + + @Environment(\.managedObjectContext) var context + @EnvironmentObject var bleManager: BLEManager + + @State var deviceRole = 0 + @State var serialEnabled = true + @State var debugLogEnabled = false + + var body: some View { + + VStack { + + Form { + + Section(header: Text("Options")) { + + Picker("Device Role", selection: $deviceRole ) { + ForEach(DeviceRoles.allCases) { dr in + Text(dr.description) + } + } + .pickerStyle(InlinePickerStyle()) + .padding(.top, 10) + .padding(.bottom, 10) + } + + Section(header: Text("Debug")) { + + Toggle(isOn: $serialEnabled) { + + Label("Serial Console", systemImage: "terminal") + } + .toggleStyle(SwitchToggleStyle(tint: .accentColor)) + + Toggle(isOn: $debugLogEnabled) { + + Label("Debug Log", systemImage: "ant.fill") + } + .toggleStyle(SwitchToggleStyle(tint: .accentColor)) + } + } + .navigationTitle("Device Config") + .navigationBarItems(trailing: + + ZStack { + + ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.lastFourCode : "????") + }) + .onAppear { + + self.bleManager.context = context + } + .navigationViewStyle(StackNavigationViewStyle()) + } + } +} diff --git a/MeshtasticApple/Views/Settings/PositionConfig.swift b/MeshtasticApple/Views/Settings/PositionConfig.swift index e511c7b1..9b9d55a0 100644 --- a/MeshtasticApple/Views/Settings/PositionConfig.swift +++ b/MeshtasticApple/Views/Settings/PositionConfig.swift @@ -124,7 +124,7 @@ struct PositionConfig: View { Form { - Section(header: Text("Device GPS Options")) { + Section(header: Text("Device GPS")) { Toggle(isOn: $deviceGpsEnabled) { @@ -172,7 +172,7 @@ struct PositionConfig: View { } } - Section(header: Text("Position Packet Options")) { + Section(header: Text("Position Packet")) { Toggle(isOn: $smartPositionEnabled) { diff --git a/MeshtasticApple/Views/Settings/PowerConfig.swift b/MeshtasticApple/Views/Settings/PowerConfig.swift index 809eb091..ea4d909a 100644 --- a/MeshtasticApple/Views/Settings/PowerConfig.swift +++ b/MeshtasticApple/Views/Settings/PowerConfig.swift @@ -24,7 +24,7 @@ struct PowerConfig: View { Section(header: Text("Warning")) { - Text("These power settings are designed for and and are only useful in very specific mostly solar use cases and should not be enabled by the majority of users, expecially if you are using your device as a messaging handset paired with a phone.") + Text("These power settings are designed for and and are only useful mostly for solar use cases. Do not use these settings if you are planning on using your device for messaging paired with a phone.") .font(.callout) .listRowSeparator(.visible) } diff --git a/MeshtasticApple/Views/Settings/Settings.swift b/MeshtasticApple/Views/Settings/Settings.swift index cbedcebd..7d2d78cb 100644 --- a/MeshtasticApple/Views/Settings/Settings.swift +++ b/MeshtasticApple/Views/Settings/Settings.swift @@ -37,6 +37,14 @@ struct Settings: View { Section("Radio Configuration (Non-Functional Interaction Previews)") { + NavigationLink { + DeviceConfig() + } label: { + + Image(systemName: "flipphone") + .symbolRenderingMode(.hierarchical) + Text("Device") + } NavigationLink { DisplayConfig() } label: {