mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
After this change, a developer can now clone the project and run without the build failing due to lint errors! 😃
* I ran `swiftlint --fix` to resolve many auto-correctable issues (mostly whitespace)
* Excluded the `Meshtastic/Protobufs` directory from lint, since that code is automatically generated.
* Converted some single letter method parameters to lowercase.
* Converted several instances `force_cast` to instead use `guard` or `if let` to unwrap optional values. During this change, some of the SwiftUI views became "too complex to be solved in a reasonable time", so I broke up the views into distinct sub-expressions.
I was able to build and run the app on an iOS simulator.
68 lines
2.7 KiB
Swift
68 lines
2.7 KiB
Swift
//
|
|
// GPSStatus.swift
|
|
// Meshtastic
|
|
//
|
|
// Copyright(c) by Garth Vander Houwen 12/22/23.
|
|
//
|
|
|
|
import SwiftUI
|
|
import CoreLocation
|
|
|
|
@available(iOS 17.0, macOS 14.0, *)
|
|
struct GPSStatus: View {
|
|
|
|
var largeFont: Font = .footnote
|
|
var smallFont: Font = .caption2
|
|
|
|
@ObservedObject var locationsHandler: LocationsHandler = LocationsHandler.shared
|
|
var body: some View {
|
|
|
|
if let newLocation = locationsHandler.locationsArray.last {
|
|
let horizontalAccuracy = Measurement(value: newLocation.horizontalAccuracy, unit: UnitLength.meters)
|
|
let verticalAccuracy = Measurement(value: newLocation.verticalAccuracy, unit: UnitLength.meters)
|
|
let altitiude = Measurement(value: newLocation.altitude, unit: UnitLength.meters)
|
|
let speed = Measurement(value: newLocation.speed, unit: UnitSpeed.kilometersPerHour)
|
|
let speedAccuracy = Measurement(value: newLocation.speedAccuracy, unit: UnitSpeed.metersPerSecond)
|
|
let courseAccuracy = Measurement(value: newLocation.courseAccuracy, unit: UnitAngle.degrees)
|
|
|
|
Label("Coordinate \(String(format: "%.5f", newLocation.coordinate.latitude)), \(String(format: "%.5f", newLocation.coordinate.longitude))", systemImage: "mappin")
|
|
.font(largeFont)
|
|
.textSelection(.enabled)
|
|
HStack {
|
|
Label("Accuracy \(horizontalAccuracy.formatted())", systemImage: "scope")
|
|
.font(largeFont)
|
|
Label("Sats Estimate \(LocationsHandler.satsInView)", systemImage: "sparkles")
|
|
.font(largeFont)
|
|
|
|
}
|
|
HStack {
|
|
if newLocation.verticalAccuracy > 0 {
|
|
Label("Altitude \(altitiude.formatted())", systemImage: "mountain.2")
|
|
.font(largeFont)
|
|
}
|
|
Label("Accuracy \(verticalAccuracy.formatted())", systemImage: "lines.measurement.vertical")
|
|
.font(smallFont)
|
|
}
|
|
HStack {
|
|
let degrees = Angle.degrees(newLocation.course)
|
|
Label {
|
|
let heading = Measurement(value: degrees.degrees, unit: UnitAngle.degrees)
|
|
Text("Heading: \(heading.formatted(.measurement(width: .narrow, numberFormatStyle: .number.precision(.fractionLength(0)))))")
|
|
} icon: {
|
|
Image(systemName: "location.north")
|
|
.symbolRenderingMode(.hierarchical)
|
|
.rotationEffect(degrees)
|
|
}
|
|
.font(largeFont)
|
|
Label("Accuracy \(courseAccuracy.formatted(.measurement(width: .narrow, numberFormatStyle: .number.precision(.fractionLength(0)))))", systemImage: "safari")
|
|
.font(smallFont)
|
|
}
|
|
HStack {
|
|
Label("Speed \(speed.formatted(.measurement(width: .abbreviated, numberFormatStyle: .number.precision(.fractionLength(0)))))", systemImage: "speedometer")
|
|
.font(largeFont)
|
|
Label("Accuracy \(speedAccuracy.formatted(.measurement(width: .abbreviated, numberFormatStyle: .number.precision(.fractionLength(0)))))", systemImage: "gauge.with.dots.needle.bottom.50percent.badge.plus")
|
|
.font(smallFont)
|
|
}
|
|
}
|
|
}
|
|
}
|