From dceb20b42f13ea4d47a79b5500be01ce3851c41c Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Fri, 16 Sep 2022 05:35:42 -0700 Subject: [PATCH] Clean up node details view, use timer to get back channels --- Meshtastic/Helpers/BLEManager.swift | 35 +++++++++---------------- Meshtastic/Helpers/MeshPackets.swift | 5 ++++ Meshtastic/Views/Nodes/NodeDetail.swift | 15 ++++------- 3 files changed, 22 insertions(+), 33 deletions(-) diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 65c05f49..9c3dd9eb 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -643,20 +643,20 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph // Config conplete returns so we don't read the characteristic again // Get all the channels - var i: UInt32 = 0; - while i < 8 { - // this should actually loop over MyNodeInfo.maxChannels to get all channels - //let timer = Timer.scheduledTimer(withTimeInterval: 2.0, repeats: false) { (timer) in - print("requesting channel",i) + var i: UInt32 = 1; + + let timer = Timer.scheduledTimer(withTimeInterval: 2.0, + repeats: true) { timer in + if i == 9 { + timer.invalidate() // invalidate the timer + } else { + + print("requesting channel", i) let resp = self.getChannel(channelIndex: i, wantResponse: true) + i+=1; - DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + .seconds(3)) {} - //} - + } } - - - return } @@ -1345,22 +1345,11 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph if connectedPeripheral!.peripheral.state == CBPeripheralState.connected { - do { - - try context!.save() - if meshLoggingEnabled { MeshLogger.log("💾 Saved a Get Channel Request Admin Message for node: \(String(connectedPeripheral.num))") } + if meshLoggingEnabled { MeshLogger.log("đŸ›Žī¸ Send Get Channel Request Admin Message for node: \(String(connectedPeripheral.num))") } connectedPeripheral.peripheral.writeValue(binaryData, for: TORADIO_characteristic, type: .withResponse) return true - - } catch { - - context!.rollback() - - let nsError = error as NSError - print("đŸ’Ĩ Error Inserting New Core Data MessageEntity: \(nsError)") - } } return false diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index 6c84a589..17835d31 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -1075,13 +1075,18 @@ func adminAppPacket (packet: MeshPacket, meshLogging: Bool, context: NSManagedOb print(try! powerConfig.jsonUTF8Data()) } else if let channel = try? Channel(serializedData: packet.decoded.payload) { + print(try! channel.jsonUTF8Data()) print("channel settings:", channel.settings) + } else if let channel = try? ChannelSettings(serializedData: packet.decoded.payload) { print(try! channel.jsonUTF8Data()) print("channel settings:", channel) } + print(try! packet.decoded.jsonUTF8Data()) + + if meshLogging { MeshLogger.log("â„šī¸ MESH PACKET received for Admin App UNHANDLED \(try! packet.jsonString())") } } diff --git a/Meshtastic/Views/Nodes/NodeDetail.swift b/Meshtastic/Views/Nodes/NodeDetail.swift index 41d5164f..292de1a8 100644 --- a/Meshtastic/Views/Nodes/NodeDetail.swift +++ b/Meshtastic/Views/Nodes/NodeDetail.swift @@ -71,14 +71,9 @@ struct NodeDetail: View { } else { HStack { - Image(node.user?.hwModel ?? "UNSET") - .resizable() - .aspectRatio(contentMode: .fit) - .cornerRadius(10) - .frame(width: bounds.size.width, height: bounds.size.height / 2.3) - .padding([.top], 40) + } - .offset( y:-40) + .padding([.top], 40) } ScrollView { @@ -159,7 +154,7 @@ struct NodeDetail: View { Text("AKA").font(.largeTitle) .foregroundColor(.gray).fixedSize() - .offset(y:20) + .offset(y:15) CircleText(text: node.user?.shortName ?? "???", color: .accentColor, circleSize: 75, fontSize: 26) } .padding() @@ -172,8 +167,8 @@ struct NodeDetail: View { Image(hwModelString) .resizable() - .aspectRatio(contentMode: .fit) - .frame(width: 90, height: 90) + .aspectRatio(contentMode: .fill) + .frame(width: 200, height: 200) .cornerRadius(5) Text(String(hwModelString))