Speed 🏎️

This commit is contained in:
Garth Vander Houwen 2023-02-05 18:36:35 -08:00
parent a0b024874d
commit 8970464fec
3 changed files with 17 additions and 11 deletions

View file

@ -796,15 +796,15 @@ class BLEManager: NSObject, CBPeripheralDelegate, ObservableObject {
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 {
if LocationHelper.currentSpeed >= 0 {
positionPacket.groundSpeed = UInt32(LocationHelper.currentSpeed)
}
if LocationHelper.currentHeading >= 0 {
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.from = UInt32(fromNodeNum)
var dataMessage = DataMessage()
dataMessage.payload = try! positionPacket.serializedData()

View file

@ -36,10 +36,10 @@ class LocationHelper: NSObject, ObservableObject {
static var currentHeading: CLLocationDirection {
guard let speed = shared.locationManager.location?.course else {
guard let heading = shared.locationManager.location?.course else {
return DefaultHeading
}
return speed
return heading
}
static var currentTimestamp: Date {

View file

@ -134,21 +134,27 @@ struct MapViewSwiftUI: UIViewRepresentable {
subtitle.text! += "Altitude: \(distanceFormatter.string(fromDistance: Double(positionAnnotation.altitude))) \n"
if positionAnnotation.nodePosition?.metadata != nil {
let pf = PositionFlags(rawValue: Int(positionAnnotation.nodePosition?.metadata?.positionFlags ?? 3))
if pf.contains(.Satsinview) {
subtitle.text! += "Sats in view: \(String(positionAnnotation.satsInView)) \n"
} else if pf.contains(.Speed) {
}
if pf.contains(.SeqNo) {
subtitle.text! += "Sequence: \(String(positionAnnotation.seqNo)) \n"
}
if pf.contains(.Speed) {
let formatter = MeasurementFormatter()
formatter.locale = Locale.current
subtitle.text! += "Speed: \(formatter.string(from: Measurement(value: Double(positionAnnotation.speed), unit: UnitSpeed.kilometersPerHour))) \n"
}
if pf.contains(.Heading) {
subtitle.text! += "Heading: \(String(positionAnnotation.heading)) \n"
}
}
subtitle.text! += positionAnnotation.time?.formatted() ?? "Unknown \n"
subtitle.numberOfLines = 0
annotationView.detailCalloutAccessoryView = subtitle
//let detailsIcon = UIButton(type: .detailDisclosure)
//detailsIcon.setImage(UIImage(systemName: "info.square"), for: .normal)
//annotationView.rightCalloutAccessoryView = detailsIcon
let detailsIcon = UIButton(type: .detailDisclosure)
detailsIcon.setImage(UIImage(systemName: "info.square"), for: .normal)
annotationView.rightCalloutAccessoryView = detailsIcon
return annotationView
case let waypointAnnotation as WaypointEntity:
let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "waypoint") as? MKMarkerAnnotationView ?? MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "Waypoint")