From 93cfda20ed437b2b61319abd0b7c39d3c87323a3 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Thu, 23 Sep 2021 22:11:24 -0700 Subject: [PATCH] Fix assorted paper cuts --- Meshtastic Client.xcodeproj/project.pbxproj | 8 +- MeshtasticClient/Helpers/BLEManager.swift | 6 +- MeshtasticClient/Model/Color.swift | 82 ------------------- MeshtasticClient/Model/MyInfoModel.swift | 2 - MeshtasticClient/Model/PacketModel.swift | 28 +++++-- .../Views/Bluetooth/Connect.swift | 4 +- .../Views/Messages/MessageList.swift | 2 +- MeshtasticClient/Views/Nodes/NodeList.swift | 8 -- 8 files changed, 27 insertions(+), 113 deletions(-) delete mode 100644 MeshtasticClient/Model/Color.swift diff --git a/Meshtastic Client.xcodeproj/project.pbxproj b/Meshtastic Client.xcodeproj/project.pbxproj index a1b15b8f..8eaa78fb 100644 --- a/Meshtastic Client.xcodeproj/project.pbxproj +++ b/Meshtastic Client.xcodeproj/project.pbxproj @@ -20,7 +20,6 @@ DD836AE726F6B38600ABCC23 /* Connect.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD836AE626F6B38600ABCC23 /* Connect.swift */; }; DD836AED26F858F900ABCC23 /* MeshData.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD836AEC26F858F900ABCC23 /* MeshData.swift */; }; DD836AEF26F85D8D00ABCC23 /* NodeInfoModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD836AEE26F85D8D00ABCC23 /* NodeInfoModel.swift */; }; - DD836AF126F8613500ABCC23 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD836AF026F8613500ABCC23 /* Color.swift */; }; DD8EDE9426F97A2B00A5A10B /* SwiftProtobuf in Frameworks */ = {isa = PBXBuildFile; productRef = DD8EDE9326F97A2B00A5A10B /* SwiftProtobuf */; }; DD90860C26F684AF00DC5189 /* BatteryIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD90860B26F684AF00DC5189 /* BatteryIcon.swift */; }; DD90860E26F69BAE00DC5189 /* NodeMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD90860D26F69BAE00DC5189 /* NodeMap.swift */; }; @@ -79,7 +78,6 @@ DD836AE626F6B38600ABCC23 /* Connect.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Connect.swift; sourceTree = ""; }; DD836AEC26F858F900ABCC23 /* MeshData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeshData.swift; sourceTree = ""; }; DD836AEE26F85D8D00ABCC23 /* NodeInfoModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeInfoModel.swift; sourceTree = ""; }; - DD836AF026F8613500ABCC23 /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = ""; }; DD90860A26F645B700DC5189 /* MeshtasticClient.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MeshtasticClient.entitlements; sourceTree = ""; }; DD90860B26F684AF00DC5189 /* BatteryIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryIcon.swift; sourceTree = ""; }; DD90860D26F69BAE00DC5189 /* NodeMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeMap.swift; sourceTree = ""; }; @@ -265,7 +263,6 @@ DDF924C526FA2375009FE055 /* MessageModel.swift */, DD836AEC26F858F900ABCC23 /* MeshData.swift */, DD836AEE26F85D8D00ABCC23 /* NodeInfoModel.swift */, - DD836AF026F8613500ABCC23 /* Color.swift */, DDF924CC26FCC97E009FE055 /* PacketModel.swift */, DD23A50E26FD1B4400D9B90C /* PeripheralModel.swift */, ); @@ -452,7 +449,6 @@ DD47E3CC26F0E51D00029299 /* NodeDetail.swift in Sources */, DD836AEF26F85D8D00ABCC23 /* NodeInfoModel.swift in Sources */, DDC2E1A726CEB3400042C5E4 /* LocationHelper.swift in Sources */, - DD836AF126F8613500ABCC23 /* Color.swift in Sources */, DD47E3D226F1210600029299 /* HelperFunctions.swift in Sources */, DDAF8C5F26ED09B50058C060 /* radioconfig.pb.swift in Sources */, DDAF8C5326EB1DF10058C060 /* BLEManager.swift in Sources */, @@ -649,7 +645,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.11; + MARKETING_VERSION = 1.12; PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTS_MACCATALYST = NO; @@ -675,7 +671,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.11; + MARKETING_VERSION = 1.12; PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTS_MACCATALYST = NO; diff --git a/MeshtasticClient/Helpers/BLEManager.swift b/MeshtasticClient/Helpers/BLEManager.swift index 249ec849..8142a003 100644 --- a/MeshtasticClient/Helpers/BLEManager.swift +++ b/MeshtasticClient/Helpers/BLEManager.swift @@ -97,7 +97,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph { var toRadio: ToRadio! toRadio = ToRadio() -//toRadio.setOwner = myUser + //toRadio.setOwner = myUser let binaryData: Data = try! toRadio.serializedData() if (self.connectedPeripheral.state == CBPeripheralState.connected) @@ -156,7 +156,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph //--------------------------------------------------------------------------------------- func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) { - meshData.load() if(peripheral.identifier == connectedPeripheral.identifier){ connectedPeripheral = nil } @@ -268,9 +267,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph connectedNode = meshData.nodes.first(where: {$0.id == decodedInfo.myInfo.myNodeNum}) if connectedNode != nil { connectedNode.myInfo = myInfoModel - let nodeIndex = meshData.nodes.firstIndex(where: { $0.id == decodedInfo.myInfo.myNodeNum }) - meshData.nodes.remove(at: nodeIndex!) - meshData.nodes.append(connectedNode) } meshData.save() diff --git a/MeshtasticClient/Model/Color.swift b/MeshtasticClient/Model/Color.swift deleted file mode 100644 index ef8f131a..00000000 --- a/MeshtasticClient/Model/Color.swift +++ /dev/null @@ -1,82 +0,0 @@ -/* -See LICENSE folder for this sample’s licensing information. -*/ - -import SwiftUI - -extension Color: Codable { - private struct Components { - let red: Double - let green: Double - let blue: Double - let alpha: Double - } - - private enum CodingKeys: String, CodingKey { - case red - case green - case blue - case alpha - } - - /// A new random color. - static var random: Color { - let red = Double.random(in: 0...1) - let green = Double.random(in: 0...1) - let blue = Double.random(in: 0...1) - return Color(.sRGB, red: red, green: green, blue: blue, opacity: 1) - } - - private var components: Components { - var red: CGFloat = 0 - var green: CGFloat = 0 - var blue: CGFloat = 0 - var alpha: CGFloat = 0 - UIColor(self).getRed(&red, green: &green, blue: &blue, alpha: &alpha) - return Components(red: Double(red), - green: Double(green), - blue: Double(blue), - alpha: Double(alpha)) - } - - public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - let red = try container.decode(Double.self, forKey: .red) - let green = try container.decode(Double.self, forKey: .green) - let blue = try container.decode(Double.self, forKey: .blue) - let alpha = try container.decode(Double.self, forKey: .alpha) - self.init(Components(red: red, green: green, blue: blue, alpha: alpha)) - } - - private init(_ components: Components) { - self.init(.sRGB, red: components.red, green: components.green, blue: components.blue, opacity: components.alpha) - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - let components = self.components - try container.encode(components.red, forKey: .red) - try container.encode(components.green, forKey: .green) - try container.encode(components.blue, forKey: .blue) - try container.encode(components.alpha, forKey: .alpha) - } - - // MARK: - font colors - /// This color is either black or white, whichever is more accessible when viewed against the scrum color. - var accessibleFontColor: Color { - var red: CGFloat = 0 - var green: CGFloat = 0 - var blue: CGFloat = 0 - UIColor(self).getRed(&red, green: &green, blue: &blue, alpha: nil) - return isLightColor(red: red, green: green, blue: blue) ? .black : .white - } - - private func isLightColor(red: CGFloat, green: CGFloat, blue: CGFloat) -> Bool { - let lightRed = red > 0.65 - let lightGreen = green > 0.65 - let lightBlue = blue > 0.65 - - let lightness = [lightRed, lightGreen, lightBlue].reduce(0) { $1 ? $0 + 1 : $0 } - return lightness >= 2 - } -} diff --git a/MeshtasticClient/Model/MyInfoModel.swift b/MeshtasticClient/Model/MyInfoModel.swift index 52d83f5a..79942b9d 100644 --- a/MeshtasticClient/Model/MyInfoModel.swift +++ b/MeshtasticClient/Model/MyInfoModel.swift @@ -30,7 +30,5 @@ struct MyInfoModel: Identifiable, Codable { self.rebootCount = rebootCount self.messageTimeoutMsec = messageTimeoutMsec self.minAppVersion = minAppVersion - } - } diff --git a/MeshtasticClient/Model/PacketModel.swift b/MeshtasticClient/Model/PacketModel.swift index 55bff11a..9b19a656 100644 --- a/MeshtasticClient/Model/PacketModel.swift +++ b/MeshtasticClient/Model/PacketModel.swift @@ -1,8 +1,22 @@ -// -// PacketModel.swift -// MeshtasticClient -// -// Created by Garth Vander Houwen on 9/23/21. -// +struct PacketModel: Identifiable { + + var id: UInt32 + var from: UInt32 + var to: UInt32 + var channel: UInt32 + var rxTime: UInt32 + var hopLimit: UInt32 + var wantAck: Bool -import Foundation + + init(id: UInt32, from: UInt32, to: UInt32, channel: UInt32, rxTime: UInt32, hopLimit: UInt32, wantAck: Bool) { + + self.id = id + self.from = from + self.to = to + self.channel = channel + self.rxTime = rxTime + self.hopLimit = hopLimit + self.wantAck = wantAck + } +} diff --git a/MeshtasticClient/Views/Bluetooth/Connect.swift b/MeshtasticClient/Views/Bluetooth/Connect.swift index 309bf35e..8bb6a223 100644 --- a/MeshtasticClient/Views/Bluetooth/Connect.swift +++ b/MeshtasticClient/Views/Bluetooth/Connect.swift @@ -136,8 +136,8 @@ struct Connect: View { ZStack { - ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.name : "Unknown") - + ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedNode != nil) ? bleManager.connectedNode.user.longName : ((bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.name : "Unknown") ?? "Unknown") + } ) }.navigationViewStyle(StackNavigationViewStyle()) diff --git a/MeshtasticClient/Views/Messages/MessageList.swift b/MeshtasticClient/Views/Messages/MessageList.swift index 43f41155..14d1c321 100644 --- a/MeshtasticClient/Views/Messages/MessageList.swift +++ b/MeshtasticClient/Views/Messages/MessageList.swift @@ -26,7 +26,7 @@ struct MessageList: View { ZStack { - ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.name : "Unknown") + ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedNode != nil) ? bleManager.connectedNode.user.longName : ((bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.name : "Unknown") ?? "Unknown") } ) .navigationBarTitleDisplayMode(.inline) diff --git a/MeshtasticClient/Views/Nodes/NodeList.swift b/MeshtasticClient/Views/Nodes/NodeList.swift index 5ff77027..5a708067 100644 --- a/MeshtasticClient/Views/Nodes/NodeList.swift +++ b/MeshtasticClient/Views/Nodes/NodeList.swift @@ -38,14 +38,6 @@ struct NodeList: View { Text("Views with bluetooth functionality will show an indicator in the upper right hand corner show if bluetooth is on, and if a device is connected.") .listRowSeparator(.hidden) Spacer().listRowSeparator(.hidden) - //Button(action: {}) { - // Text("Get Started") - // .font(.title) - // .frame(maxWidth: 300) - //} - //.buttonStyle(.borderedProminent) - //.buttonBorderShape(.automatic) - //.controlSize(.large) } else { Toggle(isOn: $showLocationOnly) {