Assorted app cleanup

This commit is contained in:
Garth Vander Houwen 2022-11-13 09:25:00 -08:00
parent 4e852d8d23
commit da382614dd
10 changed files with 45 additions and 97 deletions

View file

@ -959,6 +959,7 @@
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = Meshtastic/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Meshtastic;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
@ -991,6 +992,7 @@
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = Meshtastic/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Meshtastic;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",

View file

@ -505,9 +505,9 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
if myInfo != nil {
connectedPeripheral.num = myInfo!.myNodeNum
connectedPeripheral.firmwareVersion = myInfo!.firmwareVersion ?? "Unknown"
connectedPeripheral.name = myInfo!.bleName ?? "Unknown"
connectedPeripheral.longName = myInfo!.bleName ?? "Unknown"
connectedPeripheral.firmwareVersion = myInfo?.firmwareVersion ?? "Unknown"
connectedPeripheral.name = myInfo?.bleName ?? "Unknown"
connectedPeripheral.longName = myInfo?.bleName ?? "Unknown"
}
}
}
@ -759,51 +759,33 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
return success
}
public func sendLocation(destNum: Int64, wantAck: Bool) -> Bool {
public func sendWaypoint(destNum: Int64, name: String, wantAck: Bool) -> Bool {
var success = false
let fromNodeNum = connectedPeripheral.num
if fromNodeNum <= 0 || (LocationHelper.currentLocation.latitude == LocationHelper.DefaultLocation.latitude && LocationHelper.currentLocation.longitude == LocationHelper.DefaultLocation.longitude) {
return false
}
var positionPacket = Position()
positionPacket.latitudeI = Int32(LocationHelper.currentLocation.latitude * 1e7)
positionPacket.longitudeI = Int32(LocationHelper.currentLocation.longitude * 1e7)
positionPacket.satsInView = UInt32(LocationHelper.satsInView)
positionPacket.altitude = Int32(LocationHelper.currentAltitude)
positionPacket.timestamp = UInt32(LocationHelper.currentTimestamp.timeIntervalSince1970)
positionPacket.groundSpeed = UInt32(LocationHelper.currentSpeed)
if LocationHelper.currentHeading > 0 {
positionPacket.groundTrack = UInt32(LocationHelper.currentHeading)
}
//var waypointPacket = Waypoint()
//waypointPacket.latitudeI = Int32(LocationHelper.currentLocation.latitude * 1e7)
//waypointPacket.longitudeI = Int32(LocationHelper.currentLocation.longitude * 1e7)
//let oneWeekFromNow = Calendar.current.date(byAdding: .day, value: 7, to: Date())
//waypointPacket.expire = UInt32(oneWeekFromNow!.timeIntervalSince1970)
//waypointPacket.name = "Test Waypoint"
var waypointPacket = Waypoint()
waypointPacket.latitudeI = Int32(LocationHelper.currentLocation.latitude * 1e7)
waypointPacket.longitudeI = Int32(LocationHelper.currentLocation.longitude * 1e7)
let oneWeekFromNow = Calendar.current.date(byAdding: .day, value: 7, to: Date())
waypointPacket.expire = UInt32(oneWeekFromNow!.timeIntervalSince1970)
waypointPacket.name = name
var meshPacket = MeshPacket()
meshPacket.to = UInt32(destNum)
meshPacket.from = 0 // Send 0 as from from phone to device to avoid warning about client trying to set node num
meshPacket.wantAck = true//wantAck
var dataMessage = DataMessage()
dataMessage.payload = try! positionPacket.serializedData()
dataMessage.portnum = PortNum.positionApp
dataMessage.payload = try! waypointPacket.serializedData()
dataMessage.portnum = PortNum.waypointApp
meshPacket.decoded = dataMessage
var toRadio: ToRadio!
toRadio = ToRadio()
toRadio.packet = meshPacket
let binaryData: Data = try! toRadio.serializedData()
MeshLogger.log("📍 Sent a Location Packet from the Apple device GPS to node: \(fromNodeNum)")
MeshLogger.log("📍 Sent a Waypoint Packet from the Apple device GPS to node: \(fromNodeNum)")
if connectedPeripheral!.peripheral.state == CBPeripheralState.connected {
connectedPeripheral.peripheral.writeValue(binaryData, for: TORADIO_characteristic, type: .withResponse)
@ -815,14 +797,10 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
public func sendPosition(destNum: Int64, wantAck: Bool) -> Bool {
var success = false
let fromNodeNum = connectedPeripheral.num
if fromNodeNum <= 0 || (LocationHelper.currentLocation.latitude == LocationHelper.DefaultLocation.latitude && LocationHelper.currentLocation.longitude == LocationHelper.DefaultLocation.longitude) {
return false
}
var positionPacket = Position()
positionPacket.latitudeI = Int32(LocationHelper.currentLocation.latitude * 1e7)
positionPacket.longitudeI = Int32(LocationHelper.currentLocation.longitude * 1e7)
@ -830,23 +808,19 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
positionPacket.timestamp = UInt32(LocationHelper.currentTimestamp.timeIntervalSince1970)
positionPacket.altitude = Int32(LocationHelper.currentAltitude)
positionPacket.satsInView = UInt32(LocationHelper.satsInView)
// Get Errors without some speed
if LocationHelper.currentSpeed >= 5 {
positionPacket.groundSpeed = UInt32(LocationHelper.currentSpeed)
positionPacket.groundTrack = UInt32(LocationHelper.currentHeading)
}
var meshPacket = MeshPacket()
meshPacket.to = UInt32(destNum)
meshPacket.from = 0 // Send 0 as from from phone to device to avoid warning about client trying to set node num
meshPacket.wantAck = wantAck
var dataMessage = DataMessage()
dataMessage.payload = try! positionPacket.serializedData()
dataMessage.portnum = PortNum.positionApp
meshPacket.decoded = dataMessage
var toRadio: ToRadio!
@ -854,15 +828,11 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
toRadio.packet = meshPacket
let binaryData: Data = try! toRadio.serializedData()
if connectedPeripheral!.peripheral.state == CBPeripheralState.connected {
connectedPeripheral.peripheral.writeValue(binaryData, for: TORADIO_characteristic, type: .withResponse)
success = true
MeshLogger.log("📍 Sent a Share Location Position Packet from the Apple device GPS to node: \(fromNodeNum)")
MeshLogger.log("📍 Sent a Position Packet from the Apple device GPS to node: \(fromNodeNum)")
}
return success
}

View file

@ -224,51 +224,37 @@ func localConfig (config: Config, context:NSManagedObjectContext, nodeNum: Int64
if config.payloadVariant == Config.OneOf_PayloadVariant.network(config.network) {
MeshLogger.log("📶 Network config received \(String(nodeNum))")
print(try! config.network.jsonString())
let fetchNodeInfoRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest.init(entityName: "NodeInfoEntity")
fetchNodeInfoRequest.predicate = NSPredicate(format: "num == %lld", Int64(nodeNum))
do {
let fetchedNode = try context.fetch(fetchNodeInfoRequest) as! [NodeInfoEntity]
// Found a node, save WiFi Config
if !fetchedNode.isEmpty {
if fetchedNode[0].networkConfig == nil {
let newNetworkConfig = NetworkConfigEntity(context: context)
newNetworkConfig.wifiSsid = config.network.wifiSsid
newNetworkConfig.wifiPsk = config.network.wifiPsk
fetchedNode[0].networkConfig = newNetworkConfig
} else {
fetchedNode[0].networkConfig?.wifiSsid = config.network.wifiSsid
fetchedNode[0].networkConfig?.wifiPsk = config.network.wifiPsk
}
do {
try context.save()
MeshLogger.log("💾 Updated WiFi Config for node number: \(String(nodeNum))")
MeshLogger.log("💾 Updated Network Config for node number: \(String(nodeNum))")
} catch {
context.rollback()
let nsError = error as NSError
print("💥 Error Updating Core Data WiFiConfigEntity: \(nsError)")
}
} else {
print("💥 No Nodes found in local database matching node number \(nodeNum) unable to save WiFi Config")
print("💥 No Nodes found in local database matching node number \(nodeNum) unable to save Network Config")
}
} catch {
let nsError = error as NSError
print("💥 Fetching node for core data WiFiConfigEntity failed: \(nsError)")
}
@ -1047,7 +1033,18 @@ func nodeInfoAppPacket (packet: MeshPacket, context: NSManagedObjectContext) {
}
func adminAppPacket (packet: MeshPacket, context: NSManagedObjectContext) {
print(try! packet.decoded.jsonString())
//print(packet.payloadVariant.debugDescription)
if let messages = try? CannedMessageModuleConfig(serializedData: packet.decoded.payload) {
//let adminMessageId = bleManager.saveCannedMessageModuleMessages(messages: messages, fromUser: node!.user!, toUser: node!.user!, wantResponse: true)
//if adminMessageId > 0 {
//}
//print(messages)
} else {
//print(try! packet.decoded.jsonString())
}
}
@ -1103,20 +1100,15 @@ func positionPacket (packet: MeshPacket, context: NSManagedObjectContext) {
print("💥 Error Saving NodeInfoEntity from POSITION_APP \(nsError)")
}
}
} else {
print("💥 Empty POSITION_APP Packet")
print(try! packet.jsonString())
if let dataMessage = try? DataMessage(serializedData: packet.decoded.payload) {
print(dataMessage)
//print(dataMessage)
}
}
}
} catch {
print("💥 Error Fetching NodeInfoEntity for POSITION_APP")
}
}

View file

@ -75,6 +75,8 @@
<array>
<string>armv7</string>
</array>
<key>UIStatusBarStyle</key>
<string></string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>

View file

@ -78,8 +78,10 @@ extension NSManagedObjectContext {
/// - Throws: An error if anything went wrong executing the batch deletion.
public func executeAndMergeChanges(using batchDeleteRequest: NSBatchDeleteRequest) throws {
batchDeleteRequest.resultType = .resultTypeObjectIDs
let result = try execute(batchDeleteRequest) as? NSBatchDeleteResult
let changes: [AnyHashable: Any] = [NSDeletedObjectsKey: result?.result as? [NSManagedObjectID] ?? []]
NSManagedObjectContext.mergeChanges(fromRemoteContextSave: changes, into: [self])
}
}

View file

@ -6,9 +6,7 @@
//
import SwiftUI
#if canImport(Charts)
import Charts
#endif
struct BatteryGauge: View {
@ -19,8 +17,6 @@ struct BatteryGauge: View {
var body: some View {
VStack {
#if !targetEnvironment(macCatalyst)
if batteryLevel == 0.0 {
// Plugged in
Image(systemName: "powerplug")
@ -50,7 +46,6 @@ struct BatteryGauge: View {
.tint(gradient)
.gaugeStyle(.accessoryCircular)
}
#endif
}
}
}

View file

@ -297,7 +297,7 @@ struct ChannelMessageList: View {
focusedField = nil
replyMessageId = 0
if sendPositionWithMessage {
if bleManager.sendLocation(destNum: Int64(channel.index), wantAck: true) {
if bleManager.sendPosition(destNum: Int64(channel.index), wantAck: true) {
print("Location Sent")
}
}

View file

@ -300,7 +300,7 @@ struct UserMessageList: View {
focusedField = nil
replyMessageId = 0
if sendPositionWithMessage {
if bleManager.sendLocation(destNum: user.num, wantAck: true) {
if bleManager.sendPosition(destNum: user.num, wantAck: true) {
print("Location Sent")
}
}

View file

@ -56,7 +56,7 @@ struct NodeDetail: View {
)
}
.ignoresSafeArea(.all, edges: [.leading, .trailing])
.frame(idealWidth: bounds.size.width, minHeight: bounds.size.height / 1.70)
.frame(idealWidth: bounds.size.width, minHeight: bounds.size.height / 2)
}
Text(mostRecent.satsInView > 0 ? "Sats: \(mostRecent.satsInView)" : " ")
@ -84,12 +84,12 @@ struct NodeDetail: View {
Image(hwModelString)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 75, height: 75)
.frame(width: 100, height: 100)
.cornerRadius(5)
Text(String(hwModelString))
.foregroundColor(.gray)
.font(.title).fixedSize()
.font(.largeTitle).fixedSize()
}
}
@ -140,7 +140,9 @@ struct NodeDetail: View {
.symbolRenderingMode(.hierarchical)
Text("User Id:").font(.title)
}
Text(node.user?.userId ?? "??????").font(.title).foregroundColor(.gray)
//Text(node.user?.userId ?? "??????").font(.title).foregroundColor(.gray)
Text("!\(String(format:"%02x", node.num))")
.font(.title).foregroundColor(.gray)
}
Divider()
VStack {
@ -178,7 +180,7 @@ struct NodeDetail: View {
}
DateTimeText(dateTime: node.lastHeard)
.font(.title)
.font(.title3)
.foregroundColor(.gray)
}
}
@ -202,7 +204,7 @@ struct NodeDetail: View {
Image(node.user!.hwModel ?? "UNSET")
.resizable()
.frame(width: 50, height: 50)
.frame(width: 75, height: 75)
.cornerRadius(5)
Text(String(node.user!.hwModel ?? "UNSET"))

View file

@ -313,69 +313,52 @@ struct CannedMessagesConfig: View {
hasChanges = true
}
.onChange(of: enabled) { newEnabled in
if node != nil && node!.cannedMessageConfig != nil {
if newEnabled != node!.cannedMessageConfig!.enabled { hasChanges = true }
}
}
.onChange(of: sendBell) { newBell in
if node != nil && node!.cannedMessageConfig != nil {
if newBell != node!.cannedMessageConfig!.sendBell { hasChanges = true }
}
}
.onChange(of: rotary1Enabled) { newRot1 in
if node != nil && node!.cannedMessageConfig != nil {
if newRot1 != node!.cannedMessageConfig!.rotary1Enabled { hasChanges = true }
}
}
.onChange(of: updown1Enabled) { newUpDown in
if node != nil && node!.cannedMessageConfig != nil {
if newUpDown != node!.cannedMessageConfig!.updown1Enabled { hasChanges = true }
}
}
.onChange(of: inputbrokerPinA) { newPinA in
if node != nil && node!.cannedMessageConfig != nil {
if newPinA != node!.cannedMessageConfig!.inputbrokerPinA { hasChanges = true }
}
}
.onChange(of: inputbrokerPinB) { newPinB in
if node != nil && node!.cannedMessageConfig != nil {
if newPinB != node!.cannedMessageConfig!.inputbrokerPinB { hasChanges = true }
}
}
.onChange(of: inputbrokerPinPress) { newPinPress in
if node != nil && node!.cannedMessageConfig != nil {
if newPinPress != node!.cannedMessageConfig!.inputbrokerPinPress { hasChanges = true }
}
}
.onChange(of: inputbrokerEventCw) { newKeyA in
if node != nil && node!.cannedMessageConfig != nil {
if newKeyA != node!.cannedMessageConfig!.inputbrokerEventCw { hasChanges = true }
}
}
.onChange(of: inputbrokerEventCcw) { newKeyB in
if node != nil && node!.cannedMessageConfig != nil {
if newKeyB != node!.cannedMessageConfig!.inputbrokerEventCcw { hasChanges = true }
}
}
.onChange(of: inputbrokerEventPress) { newKeyPress in
if node != nil && node!.cannedMessageConfig != nil {
if newKeyPress != node!.cannedMessageConfig!.inputbrokerEventPress { hasChanges = true }
}
}