mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Waypoint fixes
This commit is contained in:
parent
c5f43acec6
commit
55edc42321
8 changed files with 47 additions and 19 deletions
|
|
@ -730,6 +730,10 @@ class BLEManager: NSObject, CBPeripheralDelegate, ObservableObject {
|
|||
|
||||
public func sendWaypoint(waypoint: Waypoint) -> Bool {
|
||||
|
||||
if waypoint.latitudeI == 373346000 && waypoint.longitudeI == -1220090000 {
|
||||
return false
|
||||
}
|
||||
|
||||
var success = false
|
||||
let fromNodeNum = UInt32(connectedPeripheral.num)
|
||||
var waypointPacket = waypoint
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import Foundation
|
||||
import SwiftUI
|
||||
import MapKit
|
||||
|
||||
extension Character {
|
||||
var isEmoji: Bool {
|
||||
|
|
@ -8,6 +9,17 @@ extension Character {
|
|||
}
|
||||
}
|
||||
|
||||
extension CLLocationCoordinate2D {
|
||||
/// Returns distance from coordianate in meters.
|
||||
/// - Parameter from: coordinate which will be used as end point.
|
||||
/// - Returns: Returns distance in meters.
|
||||
func distance(from: CLLocationCoordinate2D) -> CLLocationDistance {
|
||||
let from = CLLocation(latitude: from.latitude, longitude: from.longitude)
|
||||
let to = CLLocation(latitude: self.latitude, longitude: self.longitude)
|
||||
return from.distance(from: to)
|
||||
}
|
||||
}
|
||||
|
||||
extension Data {
|
||||
var macAddressString: String {
|
||||
let mac: String = reduce("") {$0 + String(format: "%02x:", $1)}
|
||||
|
|
|
|||
|
|
@ -734,9 +734,8 @@ func channelPacket (channel: Channel, fromNum: Int64, context: NSManagedObjectCo
|
|||
func deviceMetadataPacket (metadata: DeviceMetadata, fromNum: Int64, context: NSManagedObjectContext) {
|
||||
|
||||
if metadata.isInitialized {
|
||||
|
||||
let logString = String.localizedStringWithFormat(NSLocalizedString("mesh.log.device.metadata.received %@", comment: "Device Metadata received from: %@"), String(fromNum))
|
||||
MeshLogger.log("🎛️ \(logString)")
|
||||
let logString = String.localizedStringWithFormat(NSLocalizedString("mesh.log.device.metadata.received %@", comment: "Device Metadata admin message received from: %@"), String(fromNum))
|
||||
MeshLogger.log("🏷️ \(logString)")
|
||||
|
||||
let fetchedNodeRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest.init(entityName: "NodeInfoEntity")
|
||||
fetchedNodeRequest.predicate = NSPredicate(format: "num == %lld", fromNum)
|
||||
|
|
@ -977,12 +976,8 @@ func nodeInfoAppPacket (packet: MeshPacket, context: NSManagedObjectContext) {
|
|||
|
||||
func adminAppPacket (packet: MeshPacket, context: NSManagedObjectContext) {
|
||||
|
||||
MeshLogger.log("🕸️ MESH PACKET received for Admin App \(try! packet.decoded.jsonString())")
|
||||
|
||||
if let adminMessage = try? AdminMessage(serializedData: packet.decoded.payload) {
|
||||
|
||||
MeshLogger.log("🕸️ MESH PACKET received for Admin App \(adminMessage.getDeviceMetadataResponse)")
|
||||
|
||||
if adminMessage.payloadVariant == AdminMessage.OneOf_PayloadVariant.getCannedMessageModuleMessagesResponse(adminMessage.getCannedMessageModuleMessagesResponse) {
|
||||
|
||||
if let cmmc = try? CannedMessageModuleConfig(serializedData: packet.decoded.payload) {
|
||||
|
|
@ -1019,16 +1014,20 @@ func adminAppPacket (packet: MeshPacket, context: NSManagedObjectContext) {
|
|||
}
|
||||
} else if adminMessage.payloadVariant == AdminMessage.OneOf_PayloadVariant.getChannelResponse(adminMessage.getChannelResponse) {
|
||||
channelPacket(channel: adminMessage.getChannelResponse, fromNum: Int64(packet.from), context: context)
|
||||
|
||||
} else if adminMessage.payloadVariant == AdminMessage.OneOf_PayloadVariant.getDeviceMetadataResponse(adminMessage.getDeviceMetadataResponse) {
|
||||
deviceMetadataPacket(metadata: adminMessage.getDeviceMetadataResponse, fromNum: Int64(packet.from), context: context)
|
||||
} else if adminMessage.payloadVariant == AdminMessage.OneOf_PayloadVariant.getConfigResponse(adminMessage.getConfigResponse) {
|
||||
|
||||
} else if adminMessage.payloadVariant == AdminMessage.OneOf_PayloadVariant.getConfigResponse(adminMessage.getConfigResponse) {
|
||||
if let config = try? Config(serializedData: packet.decoded.payload) {
|
||||
|
||||
if config.payloadVariant == Config.OneOf_PayloadVariant.lora(config.lora) {
|
||||
if config.payloadVariant == Config.OneOf_PayloadVariant.bluetooth(config.bluetooth) {
|
||||
//upsertLoraConfigPacket(config: config, nodeNum: Int64(packet.from), context: context)
|
||||
} else if config.payloadVariant == Config.OneOf_PayloadVariant.lora(config.lora) {
|
||||
upsertLoraConfigPacket(config: config, nodeNum: Int64(packet.from), context: context)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MeshLogger.log("🕸️ MESH PACKET received for Admin App \(try! packet.decoded.jsonString())")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,7 +143,6 @@ func upsertLoraConfigPacket(config: Config, nodeNum: Int64, context: NSManagedOb
|
|||
}
|
||||
do {
|
||||
try context.save()
|
||||
context.refreshAllObjects()
|
||||
print("💾 Updated LoRa Config for node number: \(String(nodeNum))")
|
||||
} catch {
|
||||
context.rollback()
|
||||
|
|
|
|||
|
|
@ -98,9 +98,9 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
self.parent = parent
|
||||
super.init()
|
||||
self.longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressHandler))
|
||||
self.longPressRecognizer.minimumPressDuration = 0.4
|
||||
self.longPressRecognizer.minimumPressDuration = 0.5
|
||||
//self.longPressRecognizer.numberOfTouchesRequired = 1
|
||||
//self.longPressRecognizer.cancelsTouchesInView = true
|
||||
self.longPressRecognizer.cancelsTouchesInView = true
|
||||
self.longPressRecognizer.delegate = self
|
||||
self.parent.mapView.addGestureRecognizer(longPressRecognizer)
|
||||
self.overlays = []
|
||||
|
|
@ -113,6 +113,7 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
case _ as MKClusterAnnotation:
|
||||
let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "nodeGroup") as? MKMarkerAnnotationView ?? MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "nodeGroup")
|
||||
annotationView.markerTintColor = .brown//.systemRed
|
||||
annotationView.displayPriority = .defaultLow
|
||||
annotationView.tag = -1
|
||||
return annotationView
|
||||
case _ as PositionEntity:
|
||||
|
|
@ -122,7 +123,7 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
annotationView.glyphText = "📟"
|
||||
annotationView.clusteringIdentifier = "nodeGroup"
|
||||
annotationView.markerTintColor = UIColor(.indigo)
|
||||
annotationView.titleVisibility = .visible
|
||||
annotationView.titleVisibility = .adaptive
|
||||
return annotationView
|
||||
case let waypointAnnotation as WaypointEntity:
|
||||
let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "waypoint") as? MKMarkerAnnotationView ?? MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "Waypoint")
|
||||
|
|
@ -137,7 +138,7 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
annotationView.clusteringIdentifier = "waypointGroup"
|
||||
annotationView.markerTintColor = UIColor(.accentColor)
|
||||
annotationView.displayPriority = .required
|
||||
annotationView.titleVisibility = .visible
|
||||
annotationView.titleVisibility = .adaptive
|
||||
let leftIcon = UIImageView(image: annotationView.glyphText?.image())
|
||||
leftIcon.backgroundColor = UIColor(.accentColor)
|
||||
annotationView.leftCalloutAccessoryView = leftIcon
|
||||
|
|
|
|||
|
|
@ -152,6 +152,8 @@ struct WaypointFormView: View {
|
|||
waypointId = 0
|
||||
dismiss()
|
||||
} else {
|
||||
waypointId = 0
|
||||
dismiss()
|
||||
print("Send waypoint failed")
|
||||
}
|
||||
} label: {
|
||||
|
|
@ -221,6 +223,13 @@ struct WaypointFormView: View {
|
|||
latitude = coordinate.latitude
|
||||
longitude = coordinate.longitude
|
||||
}
|
||||
|
||||
if coordinate.distance(from: LocationHelper.DefaultLocation) == 0.0 {
|
||||
// Too close to apple park, bail out
|
||||
waypointId = 0
|
||||
//dismiss()
|
||||
//print(coordinate.distance(from: LocationHelper.DefaultLocation))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ struct NodeMap: View {
|
|||
private var waypoints: FetchedResults<WaypointEntity>
|
||||
|
||||
@State private var mapType: MKMapType = .standard
|
||||
@State var waypointCoordinate: CLLocationCoordinate2D?
|
||||
@State var waypointCoordinate: CLLocationCoordinate2D = LocationHelper.DefaultLocation
|
||||
@State var editingWaypoint: Int = 0
|
||||
@State private var presentingWaypointForm = false
|
||||
@State private var customMapOverlay: MapViewSwiftUI.CustomMapOverlay? = MapViewSwiftUI.CustomMapOverlay(
|
||||
|
|
@ -58,7 +58,11 @@ struct NodeMap: View {
|
|||
MapViewSwiftUI(onLongPress: { coord in
|
||||
waypointCoordinate = coord
|
||||
editingWaypoint = 0
|
||||
presentingWaypointForm = true
|
||||
if waypointCoordinate.distance(from: LocationHelper.DefaultLocation) == 0.0 {
|
||||
print("Apple Park")
|
||||
} else {
|
||||
presentingWaypointForm = true
|
||||
}
|
||||
}, onWaypointEdit: { wpId in
|
||||
if wpId > 0 {
|
||||
editingWaypoint = wpId
|
||||
|
|
@ -82,7 +86,7 @@ struct NodeMap: View {
|
|||
.ignoresSafeArea(.all, edges: [.top, .leading, .trailing])
|
||||
.frame(maxHeight: .infinity)
|
||||
.sheet(isPresented: $presentingWaypointForm ) {//, onDismiss: didDismissSheet) {
|
||||
WaypointFormView(coordinate: waypointCoordinate ?? LocationHelper.DefaultLocation, waypointId: editingWaypoint)
|
||||
WaypointFormView(coordinate: waypointCoordinate, waypointId: editingWaypoint)
|
||||
.presentationDetents([.medium, .large])
|
||||
.presentationDragIndicator(.automatic)
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
"battery.level.trend"="Battery Level Trend";
|
||||
"ble.name"="BLE Name";
|
||||
"ble.connection.timeout %d %@"="Connection failed after %d attempts to connect to %@. You may need to forget your device under Settings > Bluetooth.";
|
||||
"ble.errorcode.6 %@"="%@ The app will automatically reconnect to the preferred radio if it come back in range.";
|
||||
"ble.errorcode.6 %@"="%@ The app will automatically reconnect to the preferred radio if it comes back in range.";
|
||||
"ble.errorcode.14 %@"="%@ This error usually cannot be fixed without forgetting the device unders Settings > Bluetooth and re-connecting to the radio.";
|
||||
"ble.errorcode.pin %@"="%@ Please try connecting again and check the PIN carefully.";
|
||||
"bluetooth"="Bluetooth";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue