mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Add wind to environment metrics
This commit is contained in:
parent
cc47e866c3
commit
eb18b61f03
3 changed files with 39 additions and 6 deletions
|
|
@ -158,11 +158,13 @@ struct WindCompactWidget: View {
|
|||
VStack(alignment: .leading) {
|
||||
Label { Text("WIND") } icon: { Image(systemName: "wind").foregroundColor(.accentColor) }
|
||||
Text("\(direction)")
|
||||
.font(.caption)
|
||||
.font(gust.isEmpty ? .callout : .caption)
|
||||
.padding(.bottom, 10)
|
||||
Text(speed)
|
||||
.font(.system(size: 35))
|
||||
Text("Gusts \(gust)")
|
||||
.font(gust.isEmpty ? .system(size: 45) : .system(size: 35))
|
||||
if !gust.isEmpty {
|
||||
Text("Gusts \(gust)")
|
||||
}
|
||||
}
|
||||
.padding(10)
|
||||
.frame(maxWidth: .infinity)
|
||||
|
|
|
|||
|
|
@ -94,10 +94,12 @@ struct EnvironmentMetricsLog: View {
|
|||
}
|
||||
}
|
||||
TableColumn("Wind Speed") { em in
|
||||
Text("\(String(format: "%.1f", em.windSpeed)) hPa")
|
||||
let windSpeed = Measurement(value: Double(em.windSpeed), unit: UnitSpeed.kilometersPerHour)
|
||||
Text(windSpeed.formatted(.measurement(width: .abbreviated, numberFormatStyle: .number.precision(.fractionLength(0)))))
|
||||
}
|
||||
TableColumn("Wind Direction") { em in
|
||||
Text("\(String(format: "%.1f", em.windDirection)) hPa")
|
||||
let direction = cardinalValue(from: Double(em.windDirection))
|
||||
Text(direction)
|
||||
}
|
||||
TableColumn("timestamp") { em in
|
||||
Text(em.time?.formattedDate(format: dateFormatString) ?? "unknown.age".localized)
|
||||
|
|
|
|||
|
|
@ -194,7 +194,11 @@ struct NodeDetail: View {
|
|||
PressureCompactWidget(pressure: String(format: "%.2f", node.latestEnvironmentMetrics?.barometricPressure ?? 0.0), unit: "hPA", low: node.latestEnvironmentMetrics?.barometricPressure ?? 0.0 <= 1009.144)
|
||||
}
|
||||
if node.latestEnvironmentMetrics?.windSpeed ?? 0.0 > 0.0 {
|
||||
WindCompactWidget(speed: String(node.latestEnvironmentMetrics?.windSpeed ?? 0.0), gust: String(node.latestEnvironmentMetrics?.windGust ?? 0.0), direction: "")
|
||||
let windSpeed = Measurement(value: Double(node.latestEnvironmentMetrics?.windSpeed ?? 0.0), unit: UnitSpeed.metersPerSecond)
|
||||
let windGust = Measurement(value: Double(node.latestEnvironmentMetrics?.windGust ?? 0.0), unit: UnitSpeed.metersPerSecond)
|
||||
let direction = cardinalValue(from: Double(node.latestEnvironmentMetrics?.windDirection ?? 0))
|
||||
WindCompactWidget(speed: windSpeed.formatted(.measurement(width: .abbreviated, numberFormatStyle: .number.precision(.fractionLength(0)))),
|
||||
gust: node.latestEnvironmentMetrics?.windGust ?? 0.0 > 0.0 ? windGust.formatted(.measurement(width: .abbreviated, numberFormatStyle: .number.precision(.fractionLength(0)))) : "", direction: direction)
|
||||
}
|
||||
}
|
||||
.padding(node.latestEnvironmentMetrics?.iaq ?? -1 > 0 ? .bottom : .vertical)
|
||||
|
|
@ -411,3 +415,28 @@ struct NodeDetail: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func cardinalValue(from heading: Double) -> String {
|
||||
switch heading {
|
||||
case 0 ..< 22.5:
|
||||
return "North"
|
||||
case 22.5 ..< 67.5:
|
||||
return "North East"
|
||||
case 67.5 ..< 112.5:
|
||||
return "East"
|
||||
case 112.5 ..< 157.5:
|
||||
return "South East"
|
||||
case 157.5 ..< 202.5:
|
||||
return "South"
|
||||
case 202.5 ..< 247.5:
|
||||
return "South West"
|
||||
case 247.5 ..< 292.5:
|
||||
return "West"
|
||||
case 292.5 ..< 337.5:
|
||||
return "North West"
|
||||
case 337.5 ... 360.0:
|
||||
return "North"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue